Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs733
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sushant Mahajan
cs733
Commits
d233a3c1
Commit
d233a3c1
authored
Jan 25, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test for getm, fixed bug in CustomSplitter - in case of newlines
parent
38f4efe2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
12 deletions
+27
-12
assignment1/README.md
assignment1/README.md
+4
-1
assignment1/server.go
assignment1/server.go
+5
-4
assignment1/server_test.go
assignment1/server_test.go
+18
-7
No files found.
assignment1/README.md
View file @
d233a3c1
assignment1 files for cs733 course
Assignment1 files for cs733 course
Comprizes the memcache implementation (key value store)
completed:
-validations for various commands
-set, get, getm, cas, delete functionality working when user gives input
...
...
@@ -17,4 +19,5 @@ completed:
-user allowed to send CR, LF as value bytes
yet to complete:
-test cases for parallel connections
assignment1/server.go
View file @
d233a3c1
...
...
@@ -380,7 +380,7 @@ func parseInput(conn net.Conn, msg string, table *KeyValueStore, ch chan []byte)
}
/*
*Helper function to read value or cause timeout after
5
seconds
*Helper function to read value or cause timeout after
READ_TIMEOUT
seconds
*parameters: channel to read data from, threshold number of bytes to read
*returns: the value string and error state
*/
...
...
@@ -518,6 +518,7 @@ func performGetm(conn net.Conn, tokens []string, table *KeyValueStore) (*Data, b
data
.
expTime
=
v
.
expTime
data
.
numBytes
=
v
.
numBytes
data
.
value
=
v
.
value
[
:
]
data
.
isPerpetual
=
v
.
isPerpetual
return
data
,
true
}
else
{
...
...
@@ -626,14 +627,14 @@ func CustomSplitter(data []byte, atEOF bool) (advance int, token []byte, err err
return
0
,
nil
,
nil
}
for
{
if
i
:=
bytes
.
IndexByte
(
data
[
omega
:
],
'\n'
);
i
>
0
{
if
i
:=
bytes
.
IndexByte
(
data
[
omega
:
],
'\n'
);
i
>
=
0
{
//here we add omega as we are using the complete data array instead of the slice where we found '\n'
if
data
[
omega
+
i
-
1
]
==
'\r'
{
if
i
>
0
&&
data
[
omega
+
i
-
1
]
==
'\r'
{
//next byte begins at i+1 and data[0:i+1] returned
return
omega
+
i
+
1
,
data
[
:
omega
+
i
+
1
],
nil
}
else
{
//move the omega index to the byte after \n
omega
=
i
+
1
omega
+
=
i
+
1
}
}
else
{
//need to break free the chains
...
...
assignment1/server_test.go
View file @
d233a3c1
...
...
@@ -43,9 +43,11 @@ func testIndividualCommands(t *testing.T) {
{[]
byte
(
"set e 200 10"
+
CRLF
+
"1234
\r
6789"
+
CRLF
),
[]
byte
(
"ERR_CMD_ERR"
+
CRLF
)},
//value length less (error)
//key length high (250 bytes)
{[]
byte
(
"set 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 200 10"
+
CRLF
+
"1234
\r
67890"
+
CRLF
),
[]
byte
(
"OK 9"
+
CRLF
)},
{[]
byte
(
"set cn 100 10"
+
CRLF
+
"1234
\n\n
7890"
+
CRLF
),
[]
byte
(
"OK 10"
+
CRLF
)},
//contiguous newlines in value
{[]
byte
(
"set cn 100 10"
+
CRLF
+
"12
\n
4
\n\n
78
\r
0"
+
CRLF
),
[]
byte
(
"OK 11"
+
CRLF
)},
//contiguous newlines in value
//version update
{[]
byte
(
"set changing 200 2"
+
CRLF
+
"12"
+
CRLF
+
"set changing 200 2"
+
CRLF
+
"12"
+
CRLF
+
"set changing 200 2"
+
CRLF
+
"12"
+
CRLF
),
[]
byte
(
"OK 1
0"
+
CRLF
+
"OK 11"
+
CRLF
+
"OK 12
"
+
CRLF
)},
{[]
byte
(
"set changing 200 2"
+
CRLF
+
"12"
+
CRLF
+
"set changing 200 2"
+
CRLF
+
"12"
+
CRLF
+
"set changing 200 2"
+
CRLF
+
"12"
+
CRLF
),
[]
byte
(
"OK 1
2"
+
CRLF
+
"OK 13"
+
CRLF
+
"OK 14
"
+
CRLF
)},
//key length high (251 bytes), error
{[]
byte
(
"set 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 200 10"
+
CRLF
+
"1234
\r
67890"
+
CRLF
),
[]
byte
(
"ERR_CMD_ERR"
+
CRLF
+
"ERR_CMD_ERR"
+
CRLF
)},
...
...
@@ -70,8 +72,8 @@ func testIndividualCommands(t *testing.T) {
/*test delete command*/
//set some keys first
{[]
byte
(
"set d1 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
3
"
+
CRLF
)},
//some key will be deleted
{[]
byte
(
"set d2 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
4
"
+
CRLF
)},
//some key will be deleted
{[]
byte
(
"set d1 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
5
"
+
CRLF
)},
//some key will be deleted
{[]
byte
(
"set d2 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
6
"
+
CRLF
)},
//some key will be deleted
//deletion begins
{[]
byte
(
"delete a"
+
CRLF
),
[]
byte
(
DELETED
+
CRLF
)},
//delete normal key
{[]
byte
(
"delete l"
+
CRLF
),
[]
byte
(
ERR_NOT_FOUND
+
CRLF
)},
//delete expired key
...
...
@@ -81,10 +83,10 @@ func testIndividualCommands(t *testing.T) {
/*test cas command*/
//set some keys first
{[]
byte
(
"set c1 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
5
"
+
CRLF
)},
//some key will be deleted
{[]
byte
(
"set c2 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
6
"
+
CRLF
)},
//some key will be deleted
{[]
byte
(
"set c1 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
7
"
+
CRLF
)},
//some key will be deleted
{[]
byte
(
"set c2 200 10"
+
CRLF
+
"1234567890"
+
CRLF
),
[]
byte
(
"OK 1
8
"
+
CRLF
)},
//some key will be deleted
//set new value of version 15 key c1 and retrieve the result
{[]
byte
(
"cas c1 300 1
5 9"
+
CRLF
+
"123456789"
+
CRLF
),
[]
byte
(
"OK 17
"
+
CRLF
)},
//cas key set earlier
{[]
byte
(
"cas c1 300 1
7 9"
+
CRLF
+
"123456789"
+
CRLF
),
[]
byte
(
"OK 19
"
+
CRLF
)},
//cas key set earlier
{[]
byte
(
"get c1"
+
CRLF
),
[]
byte
(
"VALUE 9"
+
CRLF
+
"123456789"
+
CRLF
)},
//verify cas'ed key
{[]
byte
(
"cas m 2 4 5"
+
CRLF
+
"12345"
+
CRLF
),
[]
byte
(
"ERR_NOT_FOUND"
+
CRLF
)},
//cas expired key
{[]
byte
(
"cas non_existant 2 4 5"
+
CRLF
+
"12345"
+
CRLF
),
[]
byte
(
"ERR_NOT_FOUND"
+
CRLF
)},
//cas non-existant key
...
...
@@ -99,6 +101,15 @@ func testIndividualCommands(t *testing.T) {
{[]
byte
(
"cas c2 100 5 5 6"
+
CRLF
+
"12345"
+
CRLF
),
[]
byte
(
"ERR_CMD_ERR"
+
CRLF
+
"ERR_CMD_ERR"
+
CRLF
)},
//invalid arg num >
{[]
byte
(
"cas c2 100 5"
+
CRLF
+
"12345"
+
CRLF
),
[]
byte
(
"ERR_CMD_ERR"
+
CRLF
+
"ERR_CMD_ERR"
+
CRLF
)},
//invalid arg num <
/*test getm commands*/
{[]
byte
(
"getm c"
+
CRLF
),
[]
byte
(
"VALUE 8 0 10"
+
CRLF
+
"12345"
+
CRLF
+
"890"
+
CRLF
)},
//perpetual key
{[]
byte
(
"getm non_existant"
+
CRLF
),
[]
byte
(
"ERR_NOT_FOUND"
+
CRLF
)},
//non-existant key
{[]
byte
(
"getm a"
+
CRLF
),
[]
byte
(
"ERR_NOT_FOUND"
+
CRLF
)},
//deleted key
{[]
byte
(
"getm c x"
+
CRLF
),
[]
byte
(
"ERR_CMD_ERR"
+
CRLF
)},
//invalid args >
{[]
byte
(
"getm"
+
CRLF
),
[]
byte
(
"ERR_CMD_ERR"
+
CRLF
)},
//invalid args <
//invalid key size
{[]
byte
(
"get 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
+
CRLF
),
[]
byte
(
ERR_CMD_ERR
+
CRLF
)},
}
for
i
,
e
:=
range
cases
{
...
...
@@ -106,7 +117,7 @@ func testIndividualCommands(t *testing.T) {
conn
.
Write
(
e
.
command
)
n
,
_
:=
conn
.
Read
(
buf
)
if
!
bytes
.
Equal
(
buf
[
:
n
],
e
.
expected
)
{
fmt
.
Println
(
buf
[
:
n
],
e
.
expected
,
"S:"
+
string
(
buf
[
:
n
]),
"E:"
+
string
(
e
.
expected
))
fmt
.
Println
(
buf
[
:
n
],
e
.
expected
,
"S:"
+
string
(
buf
[
:
n
]),
"E:"
+
string
(
e
.
expected
)
,
"C:"
+
string
(
e
.
command
)
)
t
.
Errorf
(
"Error occured for case:"
+
strconv
.
Itoa
(
i
))
}
}
...
...
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