Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
K
key_value-server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
amir.yosef
key_value-server
Commits
cddb4a54
Commit
cddb4a54
authored
Aug 20, 2024
by
amir.yosef
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding some tests ( first stage )
parent
b7615176
Changes
15
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
357 additions
and
15 deletions
+357
-15
io_quarkus_junit5_mockito.xml
.idea/libraries/io_quarkus_junit5_mockito.xml
+157
-0
junit.xml
.idea/libraries/junit.xml
+11
-0
Redis.iml
Redis.iml
+19
-0
Main.java
src/Main.java
+8
-8
EchoCommand.java
src/command/EchoCommand.java
+1
-1
FullRsyncCommand.java
src/command/FullRsyncCommand.java
+0
-1
ReplicaReplConfCommand.java
src/command/replica/ReplicaReplConfCommand.java
+0
-1
Director.java
src/director/Director.java
+1
-1
ConnectionHandler.java
src/handlers/replica/ConnectionHandler.java
+3
-3
Storage.java
src/storage/Storage.java
+2
-0
EchoCommandTest.java
test/command/EchoCommandTest.java
+44
-0
PingCommandSenderTest.java
test/command/PingCommandSenderTest.java
+33
-0
PingCommandTest.java
test/command/PingCommandTest.java
+25
-0
ReplConfCommandTest.java
test/command/ReplConfCommandTest.java
+29
-0
UnknownCommandTest.java
test/command/UnknownCommandTest.java
+24
-0
No files found.
.idea/libraries/io_quarkus_junit5_mockito.xml
0 → 100644
View file @
cddb4a54
This diff is collapsed.
Click to expand it.
.idea/libraries/junit.xml
0 → 100644
View file @
cddb4a54
<component
name=
"libraryTable"
>
<library
name=
"junit"
type=
"repository"
>
<properties
maven-id=
"junit:junit:4.13.2"
/>
<CLASSES>
<root
url=
"jar://$MAVEN_REPOSITORY$/junit/junit/4.13.2/junit-4.13.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/"
/>
</CLASSES>
<JAVADOC
/>
<SOURCES
/>
</library>
</component>
\ No newline at end of file
Redis.iml
View file @
cddb4a54
...
...
@@ -4,9 +4,28 @@
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/test"
isTestSource=
"true"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"library"
name=
"lib"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"junit"
level=
"project"
/>
<orderEntry
type=
"module-library"
scope=
"TEST"
>
<library
name=
"JUnit5.8.1"
>
<CLASSES>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/"
/>
</CLASSES>
<JAVADOC
/>
<SOURCES
/>
</library>
</orderEntry>
<orderEntry
type=
"library"
name=
"io.quarkus.junit5.mockito"
level=
"project"
/>
</component>
</module>
\ No newline at end of file
src/Main.java
View file @
cddb4a54
...
...
@@ -18,14 +18,14 @@ public class Main {
// server.start();
// }
// builder.setPort(16379);
executor
.
submit
(()
->
{
ReplicaConnectionService
service
=
null
;
try
{
director
.
buildReplica
(
builder
,
service
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
});
//
executor.submit(() -> {
//
ReplicaConnectionService service = null;
//
try {
//
director.buildReplica(builder, service);
//
} catch (IOException e) {
//
throw new RuntimeException(e);
//
}
//
});
executor
.
submit
(()
->
{
try
(
Server
server
=
builder
.
build
())
{
server
.
start
();
...
...
src/command/EchoCommand.java
View file @
cddb4a54
...
...
@@ -13,7 +13,7 @@ public class EchoCommand implements CommandExecutable<byte[]> {
@Override
public
byte
[]
execute
()
{
if
(!
args
.
isEmpty
())
{
if
(!
args
.
isEmpty
()
&&
args
.
getFirst
()
!=
null
)
{
return
(
Response
.
getResponse
(
args
.
getFirst
()));
}
else
{
return
""
.
getBytes
();
...
...
src/command/FullRsyncCommand.java
View file @
cddb4a54
...
...
@@ -27,7 +27,6 @@ public class FullRsyncCommand implements CommandExecutable<byte[]> {
public
byte
[]
execute
()
{
synchronized
(
this
)
{
replicaSender
.
addConnection
(
outputStream
);
System
.
out
.
println
(
"hi"
);
byte
[]
decode
=
rdbFileInfo
.
getContent
();
try
{
return
createCommandBytes
(
Command
.
FULLRESYNC
,
decode
,
serverInfo
);
...
...
src/command/replica/ReplicaReplConfCommand.java
View file @
cddb4a54
...
...
@@ -19,7 +19,6 @@ public class ReplicaReplConfCommand implements CommandExecutable<byte[]> {
@Override
public
byte
[]
execute
()
{
System
.
out
.
println
(
"ReplicaReplConfCommand processed command: "
);
return
commandParser
.
getResponseFromCommandArray
(
List
.
of
(
Command
.
REPLCONF
.
getValue
(),
"ACK"
,
commandByteCounter
.
getBytes
().
toString
())).
getBytes
();
}
...
...
src/director/Director.java
View file @
cddb4a54
...
...
@@ -12,7 +12,7 @@ public class Director {
}
public
void
buildReplica
(
ServerBuilder
builder
,
ReplicaConnectionService
replicaConnectionService
)
throws
IOException
{
replicaConnectionService
=
new
ReplicaConnectionService
(
builder
.
getMasterPortAndHost
(),
163
78
);
replicaConnectionService
=
new
ReplicaConnectionService
(
builder
.
getMasterPortAndHost
(),
163
80
);
replicaConnectionService
.
checkConnection
();
}
}
src/handlers/replica/ConnectionHandler.java
View file @
cddb4a54
...
...
@@ -33,10 +33,10 @@ public class ConnectionHandler {
}
public
BufferedReader
handleConnection
()
{
try
(
OutputStream
outputStream
=
socket
.
getOutputStream
();
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
socket
.
getInputStream
())))
{
try
{
OutputStream
outputStream
=
socket
.
getOutputStream
();
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
socket
.
getInputStream
()));
commandSender
.
sendCommand
(
bufferedReader
,
outputStream
);
String
line
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
if
(
line
.
isEmpty
())
{
...
...
src/storage/Storage.java
View file @
cddb4a54
package
storage
;
import
model.RdbFile
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
test/command/EchoCommandTest.java
0 → 100644
View file @
cddb4a54
package
command
;
import
org.junit.Test
;
import
util.Response
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
public
class
EchoCommandTest
{
@Test
public
void
test_execute_with_non_empty_args
()
{
List
<
String
>
args
=
List
.
of
(
"hello"
);
EchoCommand
command
=
new
EchoCommand
(
args
);
byte
[]
result
=
command
.
execute
();
byte
[]
expected
=
Response
.
getResponse
(
"hello"
);
assertArrayEquals
(
expected
,
result
);
}
@Test
public
void
test_execute_with_null_args
()
{
List
<
String
>
args
=
Collections
.
singletonList
((
String
)
null
);
EchoCommand
command
=
new
EchoCommand
(
args
);
byte
[]
result
=
command
.
execute
();
byte
[]
expected
=
""
.
getBytes
();
assertArrayEquals
(
expected
,
result
);
}
@Test
public
void
test_execute_with_long_strings
()
{
List
<
String
>
longArgs
=
new
ArrayList
<>();
StringBuilder
longString
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
longString
.
append
(
"a"
);
}
longArgs
.
add
(
longString
.
toString
());
EchoCommand
command
=
new
EchoCommand
(
longArgs
);
byte
[]
result
=
command
.
execute
();
byte
[]
expected
=
Response
.
getResponse
(
longString
.
toString
());
assertArrayEquals
(
expected
,
result
);
}
}
\ No newline at end of file
test/command/PingCommandSenderTest.java
0 → 100644
View file @
cddb4a54
package
command
;
// Generated by CodiumAI
import
command.handshake.PingCommandSender
;
import
org.junit.Test
;
import
parser.CommandParser
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
import
static
org
.
mockito
.
Mockito
.*;
public
class
PingCommandSenderTest
{
@Test
public
void
test_send_command_success
()
throws
IOException
{
CommandParser
commandParser
=
mock
(
CommandParser
.
class
);
PingCommandSender
pingCommandSender
=
new
PingCommandSender
(
commandParser
);
BufferedReader
bufferedReader
=
mock
(
BufferedReader
.
class
);
OutputStream
outputStream
=
mock
(
OutputStream
.
class
);
when
(
commandParser
.
getResponseFromCommandArray
(
List
.
of
(
"ping"
))).
thenReturn
(
"*1\r\n$4\r\nping\r\n"
);
pingCommandSender
.
sendCommand
(
bufferedReader
,
outputStream
);
verify
(
outputStream
).
write
(
"*1\r\n$4\r\nping\r\n"
.
getBytes
());
verify
(
outputStream
).
flush
();
}
}
\ No newline at end of file
test/command/PingCommandTest.java
0 → 100644
View file @
cddb4a54
package
command
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
public
class
PingCommandTest
{
@Test
public
void
test_execute_returns_correct_pong_response
()
{
PingCommand
pingCommand
=
new
PingCommand
();
byte
[]
expectedResponse
=
"+PONG\r\n"
.
getBytes
();
byte
[]
actualResponse
=
pingCommand
.
execute
();
assertArrayEquals
(
expectedResponse
,
actualResponse
);
}
@Test
public
void
test_execute_handles_null_values_gracefully
()
{
PingCommand
pingCommand
=
new
PingCommand
();
byte
[]
response
=
pingCommand
.
execute
();
assertNotNull
(
response
);
}
}
\ No newline at end of file
test/command/ReplConfCommandTest.java
0 → 100644
View file @
cddb4a54
package
command
;
import
org.junit.Test
;
import
java.util.List
;
import
java.util.NoSuchElementException
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
public
class
ReplConfCommandTest
{
@Test
public
void
test_execute_returns_null_for_ack
()
{
List
<
String
>
args
=
List
.
of
(
"ACK"
);
ReplConfCommand
command
=
new
ReplConfCommand
(
args
);
byte
[]
result
=
command
.
execute
();
assertNull
(
result
);
}
@Test
public
void
test_execute_with_empty_args_list
()
{
List
<
String
>
args
=
List
.
of
();
ReplConfCommand
command
=
new
ReplConfCommand
(
args
);
assertThrows
(
NoSuchElementException
.
class
,
command:
:
execute
);
}
}
\ No newline at end of file
test/command/UnknownCommandTest.java
0 → 100644
View file @
cddb4a54
package
command
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
public
class
UnknownCommandTest
{
@Test
public
void
test_execute_with_message
()
{
String
testMessage
=
"Test Message"
;
UnknownCommand
command
=
new
UnknownCommand
(
testMessage
);
byte
[]
result
=
command
.
execute
();
assertArrayEquals
(
testMessage
.
getBytes
(),
result
);
}
@Test
public
void
test_execute_with_null_message
()
{
UnknownCommand
command
=
new
UnknownCommand
();
byte
[]
result
=
command
.
execute
();
assertArrayEquals
(
"-Unknown Command\r\n"
.
getBytes
(),
result
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment