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
14b0a125
Commit
14b0a125
authored
Jan 22, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some test cases and formatted code
parent
bf567f5b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
6 deletions
+72
-6
assignment1/README.md
assignment1/README.md
+2
-0
assignment1/server.go
assignment1/server.go
+6
-6
assignment1/server_test.go
assignment1/server_test.go
+64
-0
No files found.
assignment1/README.md
View file @
14b0a125
...
...
@@ -10,3 +10,5 @@ completed:
yet to complete:
-when sending commands from test case, read/write sync breaks
-test cases need to be made
Note: inorder to run test cases you need to move the client.go file somewhere else
assignment1/server.go
View file @
14b0a125
...
...
@@ -24,9 +24,9 @@ const (
NOREPLY
=
"noreply"
//
// //response
OK
=
"OK"
CRLF
=
"
\r\n
"
VALUE
=
"VALUE"
OK
=
"OK"
CRLF
=
"
\r\n
"
VALUE
=
"VALUE"
DELETED
=
"DELETED"
//errors
...
...
@@ -106,7 +106,7 @@ func handleClient(conn net.Conn, table *KeyValueStore) {
defer
conn
.
Close
()
for
{
if
msg
,
ok
:=
read
(
conn
,
1024
);
ok
{
if
len
(
msg
)
==
0
{
if
len
(
msg
)
==
0
{
continue
}
parseInput
(
conn
,
string
(
msg
),
table
)
...
...
@@ -404,7 +404,7 @@ func performCas(conn net.Conn, tokens []string, table *KeyValueStore) (uint64, i
e
,
_
:=
strconv
.
ParseUint
(
tokens
[
1
],
10
,
64
)
ve
,
_
:=
strconv
.
ParseUint
(
tokens
[
2
],
10
,
64
)
n
,
_
:=
strconv
.
ParseUint
(
tokens
[
3
],
10
,
64
)
r
:=
true
r
:=
true
logger
.
Println
(
k
,
e
,
ve
,
n
,
r
)
if
len
(
tokens
)
==
5
&&
tokens
[
4
]
==
NOREPLY
{
...
...
@@ -438,7 +438,7 @@ func performCas(conn net.Conn, tokens []string, table *KeyValueStore) (uint64, i
return
0
,
3
,
r
//key not found
}
func
performDelete
(
conn
net
.
Conn
,
tokens
[]
string
,
table
*
KeyValueStore
)
(
bool
)
{
func
performDelete
(
conn
net
.
Conn
,
tokens
[]
string
,
table
*
KeyValueStore
)
bool
{
k
:=
tokens
[
0
]
defer
table
.
Unlock
()
...
...
assignment1/server_test.go
0 → 100644
View file @
14b0a125
package
main
import
(
"bytes"
"net"
"testing"
"time"
)
func
TestSet
(
t
*
testing
.
T
)
{
go
main
()
conn
,
err
:=
net
.
Dial
(
"tcp"
,
"localhost:5000"
)
if
err
!=
nil
{
t
.
Errorf
(
"Error connecting to server"
)
}
else
{
time
.
Sleep
(
time
.
Second
*
2
)
conn
.
Write
([]
byte
(
"set xyz 200 10
\r\n
"
))
time
.
Sleep
(
time
.
Millisecond
)
conn
.
Write
([]
byte
(
"abcd
\r\n
"
))
buffer
:=
make
([]
byte
,
1024
)
conn
.
Read
(
buffer
)
msg
:=
string
(
buffer
)
if
msg
==
ERR_CMD_ERR
+
"
\r\n
"
{
t
.
Errorf
(
"Expected OK <version>"
)
}
}
}
func
TestGet
(
t
*
testing
.
T
)
{
//go main()
conn
,
err
:=
net
.
Dial
(
"tcp"
,
"localhost:5000"
)
if
err
!=
nil
{
t
.
Errorf
(
"Error connecting to server"
)
}
else
{
time
.
Sleep
(
time
.
Second
)
conn
.
Write
([]
byte
(
"set xyz 200 10
\r\n
"
))
time
.
Sleep
(
time
.
Millisecond
)
conn
.
Write
([]
byte
(
"abcdefg
\r\n
"
))
buffer
:=
make
([]
byte
,
1024
)
conn
.
Read
(
buffer
)
msg
:=
string
(
buffer
)
if
msg
==
ERR_CMD_ERR
+
"
\r\n
"
{
t
.
Errorf
(
"Expected OK <version>"
)
}
conn
.
Write
([]
byte
(
"get xyz
\r\n
"
))
time
.
Sleep
(
time
.
Millisecond
)
conn
.
Read
(
buffer
)
msg
=
string
(
buffer
)
if
msg
==
ERR_CMD_ERR
+
"
\r\n
"
{
t
.
Errorf
(
"Expected key value"
)
}
conn
.
Write
([]
byte
(
"get tuv
\r\n
"
))
time
.
Sleep
(
time
.
Millisecond
)
buffer
=
make
([]
byte
,
1024
)
conn
.
Read
(
buffer
)
n
:=
bytes
.
Index
(
buffer
,
[]
byte
{
0
})
msg
=
string
(
buffer
[
:
n
])
if
msg
!=
ERR_NOT_FOUND
+
"
\r\n
"
{
t
.
Errorf
(
"Expected key value"
)
}
}
}
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