예제 #1
0
파일: tribtest.go 프로젝트: ammarar/DS-P2
// Initialize proxy and tribserver
func initTribserver(storage string, server string, myhostport string) net.Listener {
	// Start proxy
	l, err := net.Listen("tcp", server)
	if err != nil {
		log.Fatal("listen error:", err)
	}
	pc = proxycounter.NewProxyCounter(storage, server)
	if pc == nil {
		fmt.Println("Could not start proxy")
		return nil
	}
	srpc := storagerpc.NewStorageRPC(pc)
	rpc.Register(srpc)
	rpc.HandleHTTP()
	go http.Serve(l, nil)

	// Start tribserver
	ts = tribimpl.NewTribserver(server, myhostport)
	if ts == nil {
		fmt.Println("Could not start tribserver")
		return nil
	}
	rpc.Register(ts)
	return l
}
예제 #2
0
파일: tribtest.go 프로젝트: ammarar/DS-P2
// Test tribserver returns nil when it cannot connect to the server
func testNonexistentServer() {
	if tribimpl.NewTribserver(fmt.Sprintf("localhost:%d", *portnum), fmt.Sprintf("localhost:%d", *portnum)) == nil {
		fmt.Fprintln(output, "PASS")
		passCount++
	} else {
		fmt.Fprintln(output, "FAIL: tribserver does not return nil when it cannot connect to nonexistent storage server")
		failCount++
	}
	cleanupTribserver(nil)
}
예제 #3
0
func main() {
	flag.Parse()
	if flag.NArg() < 1 {
		log.Fatal("usage:  tribserver <storage master node>")
	}
	l, e := net.Listen("tcp", fmt.Sprintf(":%d", *portnum))
	if e != nil {
		log.Fatal("listen error:", e)
	}
	log.Printf("Server starting on port %d\n", *portnum)
	ts := tribimpl.NewTribserver(flag.Arg(0), fmt.Sprintf("localhost:%d", *portnum))
	rpc.Register(ts)
	rpc.HandleHTTP()
	http.Serve(l, nil)
}