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 (
"log"
"net/rpc"
"strconv"
"sync"
"time"
)
//constant values used
const (
CLIENT_PORT = 9000
LOG_PORT = 8000
ACK_TIMEOUT = 5
ClientPORT = 9000
LogPORT = 20000
AckTIMEOUT = 5
)
// Logger
......@@ -45,6 +46,7 @@ type Raft struct {
commitCh chan LogEntry
cluster_config *ClusterConfig //cluster
id int //this server id
sync.RWMutex
}
type LogEntry interface {
......@@ -128,6 +130,10 @@ func (entry *LogEntryData) Committed() bool {
return entry.committed
}
func Test() {
}
//make raft implement the append function
func (rft *Raft) Append(data []byte, conn net.Conn) (LogEntry, error) {
if rft.id != 1 {
......
......@@ -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.CLIENT_PORT + i
server_port := raft.LogPORT + 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\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)
buffer := make([]byte, 1024)
conn.Read(buffer)
......@@ -85,7 +85,9 @@ func testNoReply(t *testing.T) {
{[]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")},
}
server_port := raft.CLIENT_PORT + 1
server_port := raft.LogPORT + 1
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))
......
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