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
58cf8744
Commit
58cf8744
authored
Feb 09, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed connection port problem
parent
1f614702
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
9 deletions
+8
-9
assignment2/src/raft/kvstore.go
assignment2/src/raft/kvstore.go
+1
-0
assignment2/src/server.go
assignment2/src/server.go
+0
-2
assignment2/src/server_test.go
assignment2/src/server_test.go
+7
-7
No files found.
assignment2/src/raft/kvstore.go
View file @
58cf8744
...
...
@@ -491,6 +491,7 @@ func InitKVStore(log *log.Logger) {
//initialize key value store
table
=
&
KeyValueStore
{
dictionary
:
make
(
map
[
string
]
*
Data
)}
logger
.
Println
(
"KVStore initialized"
)
}
//server will not call this, we'll call it from test cases to clear the map
...
...
assignment2/src/server.go
View file @
58cf8744
...
...
@@ -34,7 +34,6 @@ func (t *AppendEntries) AppendEntriesRPC(args *Args, reply *Reply) error {
}
func
initInterServerCommunication
(
server
*
raft
.
ServerConfig
,
rft
*
raft
.
Raft
,
ch
chan
bool
)
{
appendRpc
:=
new
(
AppendEntries
)
rpc
.
Register
(
appendRpc
)
listener
,
e
:=
net
.
Listen
(
"tcp"
,
":"
+
strconv
.
Itoa
(
server
.
LogPort
))
...
...
@@ -66,7 +65,6 @@ func initLogger(serverId int) {
}
func
initClientCommunication
(
server
*
raft
.
ServerConfig
,
rft
*
raft
.
Raft
,
ch
chan
bool
)
{
listener
,
e
:=
net
.
Listen
(
"tcp"
,
":"
+
strconv
.
Itoa
(
server
.
ClientPort
))
if
e
!=
nil
{
Info
.
Fatal
(
"client listen error:"
,
e
)
...
...
assignment2/src/server_test.go
View file @
58cf8744
...
...
@@ -26,7 +26,7 @@ type Testpair struct {
//
func
TestAll
(
t
*
testing
.
T
)
{
//start the servers
for
i
:=
0
;
i
<
NUM_SERVERS
;
i
++
{
for
i
:=
1
;
i
<=
NUM_SERVERS
;
i
++
{
go
testServersCommunic
(
i
,
t
)
}
//wait for some time so that servers are ready
...
...
@@ -38,7 +38,7 @@ func TestAll(t *testing.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
))
cmd
:=
exec
.
Command
(
"go"
,
"run"
,
"server.go"
,
strconv
.
Itoa
(
i
),
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
)
...
...
@@ -53,14 +53,14 @@ func testServersCommunic(i int, t *testing.T) {
//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
.
LOG
_PORT
+
i
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
.
LOG
_PORT
+
1
)
+
"
\r\n
"
+
"ERR_REDIRECT 127.0.0.1 "
+
strconv
.
Itoa
(
raft
.
CLIENT_PORT
+
1
)
+
"
\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
)
...
...
@@ -82,11 +82,11 @@ func testConnectFollower(t *testing.T) {
//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
(
"ERR
CMD
ERR
\r\n
"
)},
{[]
byte
(
"cas mykey1 0 1 6 noreply
\r\n
"
),
[]
byte
(
"ERR
CMD
ERR
\r\n
"
)},
{[]
byte
(
"set mykey1 100 3 noreply
\r\n
"
),
[]
byte
(
"ERR
_CMD_
ERR
\r\n
"
)},
{[]
byte
(
"cas mykey1 0 1 6 noreply
\r\n
"
),
[]
byte
(
"ERR
_CMD_
ERR
\r\n
"
)},
}
server_port
:=
raft
.
LOG
_PORT
+
1
server_port
:=
raft
.
CLIENT
_PORT
+
1
conn
,
err
:=
net
.
Dial
(
"tcp"
,
":"
+
strconv
.
Itoa
(
server_port
))
if
err
!=
nil
{
...
...
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