Commit 19eb5b7e authored by Harshit Pande's avatar Harshit Pande

mutex added to shared log - facing import errors from package raft while testing

parent 60731d30
...@@ -4,14 +4,15 @@ import ( ...@@ -4,14 +4,15 @@ import (
"log" "log"
"net/rpc" "net/rpc"
"strconv" "strconv"
"sync"
"time" "time"
) )
//constant values used //constant values used
const ( const (
CLIENT_PORT = 9000 ClientPORT = 9000
LOG_PORT = 8000 LogPORT = 20000
ACK_TIMEOUT = 5 AckTIMEOUT = 5
) )
// Logger // Logger
...@@ -45,6 +46,7 @@ type Raft struct { ...@@ -45,6 +46,7 @@ type Raft struct {
commitCh chan LogEntry commitCh chan LogEntry
cluster_config *ClusterConfig //cluster cluster_config *ClusterConfig //cluster
id int //this server id id int //this server id
sync.RWMutex
} }
type LogEntry interface { type LogEntry interface {
...@@ -128,6 +130,10 @@ func (entry *LogEntryData) Committed() bool { ...@@ -128,6 +130,10 @@ func (entry *LogEntryData) Committed() bool {
return entry.committed return entry.committed
} }
func Test() {
}
//make raft implement the append function //make raft implement the append function
func (rft *Raft) Append(data []byte, conn net.Conn) (LogEntry, error) { func (rft *Raft) Append(data []byte, conn net.Conn) (LogEntry, error) {
if rft.id != 1 { if rft.id != 1 {
......
...@@ -53,14 +53,14 @@ func testServersCommunic(i int, t *testing.T) { ...@@ -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 //on trying to connect with the followers the client should get redirect err from the followers
func testConnectFollower(t *testing.T) { func testConnectFollower(t *testing.T) {
for i := 2; i < NUM_SERVERS; i++ { //the followers start at second position for i := 2; i < NUM_SERVERS; i++ { //the followers start at second position
server_port := raft.CLIENT_PORT + i server_port := raft.LogPORT + i
conn, err := net.Dial("tcp", ":"+strconv.Itoa(server_port)) conn, err := net.Dial("tcp", ":"+strconv.Itoa(server_port))
if err != nil { if err != nil {
t.Error("Error in connecting the server at port: " + strconv.Itoa(server_port)) t.Error("Error in connecting the server at port: " + strconv.Itoa(server_port))
} else { } else {
time.Sleep(time.Millisecond) time.Sleep(time.Millisecond)
sending := []byte("set mykey1 100 3\r\nlul\r\n") sending := []byte("set mykey1 100 3\r\nlul\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") expecting := []byte("ERR_REDIRECT 127.0.0.1 " + strconv.Itoa(raft.LogPORT+1) + "\r\n" + "ERR_REDIRECT 127.0.0.1 " + strconv.Itoa(raft.CLIENT_PORT+1) + "\r\n")
conn.Write(sending) conn.Write(sending)
buffer := make([]byte, 1024) buffer := make([]byte, 1024)
conn.Read(buffer) conn.Read(buffer)
...@@ -85,7 +85,9 @@ func testNoReply(t *testing.T) { ...@@ -85,7 +85,9 @@ func testNoReply(t *testing.T) {
{[]byte("set mykey1 100 3 noreply\r\n"), []byte("ERRCMDERR\r\n")}, {[]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")}, {[]byte("cas mykey1 0 1 6 noreply\r\n"), []byte("ERRCMDERR\r\n")},
} }
server_port := raft.CLIENT_PORT + 1
server_port := raft.LogPORT + 1
conn, err := net.Dial("tcp", ":"+strconv.Itoa(server_port)) conn, err := net.Dial("tcp", ":"+strconv.Itoa(server_port))
if err != nil { if err != nil {
t.Error("Error in connecting the server at port: " + strconv.Itoa(server_port)) t.Error("Error in connecting the server at port: " + strconv.Itoa(server_port))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment