Esempio n. 1
0
func main() {
	flag.Parse()
	*masterHostPort = "localhost:8009"

	// Create and start the StorageServer.
	client, err := client.NewPacClient(*masterHostPort, *port, *ID)
	if err != nil {
		log.Fatalln("Failed to create client:", err)
	}

	reader := bufio.NewReader(os.Stdin)
	for {
		//blocks

		input, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println("please retype string")
		}
		message := string([]byte(input))
		err = client.MakeMove(message)
		if err != nil {
			fmt.Println("Server is dead")
			return
		}

	}

}
Esempio n. 2
0
func main() {
	flag.Parse()
	if *masterHostPort == "" && *port == 0 {
		// If masterHostPort string is empty, then this storage server is the master.
		*port = defaultPort
	}
	*masterHostPort = "localhost:8009"

	// If nodeID is 0, then assign a random 32-bit integer instead.
	randID := uint32(*nodeID)
	if randID == 0 {
		randint, _ := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
		rand.Seed(randint.Int64())
		randID = rand.Uint32()
	}

	// Create and start the StorageServer.
	client1, err := client.NewPacClient(*masterHostPort, *port)
	if err != nil {
		log.Fatalln("Failed to create client:", err)
	}
	// Run the storage server forever.
	fmt.Println("masterHostPort=", masterHostPort)
	fmt.Println("port=", port)

	for {
		err = client1.MakeMove("up")
	}
}
Esempio n. 3
0
func main() {
	flag.Parse()
	fmt.Println("Starting Test 1. Test 1 checks 1 client 1 loadbalancer 3 servers")

	// If nodeID is 0, then assign a random 32-bit integer instead.

	fmt.Println("starting client")
	client1, err := client.NewPacClient(masterHostPort, 2002, "Karan")
	if err != nil {
		fmt.Println("Failed to create client", err)

	}
	client2, err := client.NewPacClient(masterHostPort, 2003, "KaranLala")
	if err != nil {
		fmt.Println("Failed to create client", err)

	}
	fmt.Println("Writing Msgs ..")
	// Run the storage server forever.
	err = client2.MakeMove("hi")
	if err != nil {
		fmt.Println("Failed to make move", err)
	}
	/*
		err = client1.MakeMove("how are you?")
		if err != nil {
			fmt.Println("Failed to make move", err)
		}
		err = client1.MakeMove("this is a test")
		if err != nil {
			fmt.Println("Failed to make move", err)
		}
		err = client1.MakeMove("Now to see if all messages are stored.")
		if err != nil {
			fmt.Println("Failed to make move", err)
		}*/

	time.Sleep(time.Second * time.Duration(2))

	logs := client1.GetLogs()
	_, ok := logs[10]
	if !ok {
		return
	} else {
		fmt.Println(logs[10])
	}

	/*if value != "KaranLala:hi" {
		fmt.Println("0: failed")
		return
	}*/
	/*
		if index == 1 {
			if value != "Karan:how are you?" {
				fmt.Println("1: failed")
			}
		}
		if index == 2 {
			if value != "Karan:this is a test" {
				fmt.Println("2: failed")
			}
		}
		if index == 3 {
			if value != "Karan:Now to see if all messages are stored." {
				fmt.Println("3: failed")
			}
		}*/

	fmt.Println("All 4 Posting message tests have passed")
	fmt.Println("Test1 Passed")

	fmt.Println("Starting Test 2. Test 2 checks 1 client getting chat history of session")
	fmt.Println("Adding a new client to retrieve history")

	logs = client2.GetLogs()

	_, ok = logs[10]
	if !ok {
		fmt.Println("0: failed")
		return
	} else {
		fmt.Println(logs[10])
	}

	/*else if value != "KaranLala:hi" {
		fmt.Println("0: failed")
		return
	} */ /*
		if index == 1 {
			if value != "Karan:how are you?" {
				fmt.Println("1: failed")
			}
		}
		if index == 2 {
			if value != "Karan:this is a test" {
				fmt.Println("2: failed")
			}
		}
		if index == 3 {
			if value != "Karan:Now to see if all messages are stored." {
				fmt.Println("3: failed")
			}
		}*/

	fmt.Println("History properly retrieved")
	fmt.Println("Test2 Passed")

	fmt.Println("Starting Test 3. Test 3 checks 3 clients, 3 servers and 1 loadbalancer with many messages")
}