示例#1
0
func TestLocalServer(t *testing.T) {
	distserver.Init()
	err, listener := distserver.StartListener("8000")
	if err != nil {
		t.Errorf("Couldn't start local server on port 8000 (%v)", err)
	}
	go distserver.RunServer(listener)

	dotserver := DotServer{Hostname: ":8000"}
	err = dotserver.Connect()
	if err != nil {
		t.Errorf("Couldn't connect to local server (%v)", err)
	}

	err, test := dotserver.RemoteDotProduct([]int{1, 2}, []int{2, 1})
	if err != nil {
		t.Errorf("Remote Dot Product error: %v", err)
	} else if test != 4 {
		t.Errorf("Something is fundamentally wrong (4 != %d)", test)
	}

	err, _ = dotserver.RemoteDotProduct([]int{1, 2}, []int{2})
	if err == nil {
		t.Errorf("Expected error not returned (vectors of different lenght)")
	}
}
示例#2
0
func main() {
	distserver.Init()
	err, listener := distserver.StartListener("9999")
	if err != nil {
		fmt.Printf("Failed to start server: %v", err)
		return
	}
	fmt.Println("Started on port 9999")
	distserver.RunServer(listener)
}