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
c8890231
Commit
c8890231
authored
Feb 09, 2015
by
Harshit Pande
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test cases for ERR_REDIRECT
parent
5e03357b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
+95
-0
assignment2/src/server_test.go
assignment2/src/server_test.go
+95
-0
No files found.
assignment2/src/server_test.go
0 → 100644
View file @
c8890231
//testing
package
main
import
(
"bytes"
"net"
"os"
"os/exec"
"raft"
"strconv"
"testing"
"time"
)
//constant values used
const
(
NUM_SERVERS
int
=
5
)
type
Testpair
struct
{
to_server
[]
byte
from_server
[]
byte
}
//
func
TestAll
(
t
*
testing
.
T
)
{
//start the servers
for
i
:=
0
;
i
<
NUM_SERVERS
;
i
++
{
go
testServersCommunic
(
i
,
t
)
}
//wait for some time so that servers are ready
time
.
Sleep
(
4
*
time
.
Second
)
//run client that tries connecting to the followers
testConnectFollower
(
t
)
}
//run servers
func
testServersCommunic
(
i
int
,
t
*
testing
.
T
)
{
cmd
:=
exec
.
Command
(
"go"
,
"run"
,
"server.go"
,
strconv
.
Itoa
(
i
+
1
),
strconv
.
Itoa
(
NUM_SERVERS
))
f
,
err
:=
os
.
OpenFile
(
strconv
.
Itoa
(
i
),
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_TRUNC
,
0666
)
if
err
!=
nil
{
t
.
Errorf
(
"error opening file: %v"
,
err
)
}
defer
f
.
Close
()
cmd
.
Stdout
=
f
cmd
.
Stderr
=
f
cmd
.
Run
()
}
//on trying to connect with the followers the client should get redirect err from the followers
func
testConnectFollower
(
t
*
testing
.
T
)
{
for
i
:=
2
;
i
<
NUM_SERVERS
;
i
++
{
//the followers start at second position
server_port
:=
raft
.
CLIENT_PORT
+
i
conn
,
err
:=
net
.
Dial
(
"tcp"
,
":"
+
strconv
.
Itoa
(
server_port
))
if
err
!=
nil
{
t
.
Error
(
"Error in connecting the server at port: "
+
strconv
.
Itoa
(
server_port
))
}
else
{
time
.
Sleep
(
time
.
Millisecond
)
sending
:=
[]
byte
(
"set mykey1 100 3
\r\n
lul
\r\n
"
)
expecting
:=
[]
byte
(
"ERR_REDIRECT 127.0.0.1 "
+
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
)
+
"
\r\n
"
+
"ERR_REDIRECT 127.0.0.1 "
+
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
)
+
"
\r\n
"
)
conn
.
Write
(
sending
)
buffer
:=
make
([]
byte
,
1024
)
conn
.
Read
(
buffer
)
n
:=
bytes
.
Index
(
buffer
,
[]
byte
{
0
})
if
!
bytes
.
Equal
(
buffer
[
:
n
],
expecting
)
{
t
.
Error
(
"For"
,
sending
,
string
(
sending
),
"expected"
,
expecting
,
string
(
expecting
),
"got"
,
buffer
[
:
n
],
string
(
buffer
[
:
n
]),
)
}
conn
.
Close
()
time
.
Sleep
(
time
.
Millisecond
)
}
}
}
//noreply option is not more valid with set and cas
//client should get command error from the server if it sends 'no reply' option
func
testNoReply
(
t
*
testing
.
T
)
{
var
noreply_cases
=
[]
testpair
{
{[]
byte
(
"set mykey1 100 3 noreply
\r\n
"
),
[]
byte
(
"ERRCMDERR
\r\n
"
)},
{[]
byte
(
"cas mykey1 0 1 6 noreply
\r\n
"
),
[]
byte
(
"ERRCMDERR
\r\n
"
)},
}
conn
,
err
:=
net
.
Dial
(
"tcp"
,
":"
+
strconv
.
Itoa
(
server_port
))
if
err
!=
nil
{
t
.
Error
(
"Error in connecting the server at port: "
+
strconv
.
Itoa
(
server_port
))
}
else
{
time
.
Sleep
(
time
.
Millisecond
)
}
}
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