Beispiel #1
0
func startServer() {
	protorpc.Register(new(Arith))
	protorpc.RegisterName("net.rpc.Arith", new(Arith))

	var l net.Listener
	l, serverAddr = listenTCP()
	log.Println("Test RPC server listening on", serverAddr)
	go protorpc.Accept(l)

	protorpc.HandleHTTP()
	httpOnce.Do(startHttpServer)
}
Beispiel #2
0
// Check that registration handles lots of bad methods and a type with no suitable methods.
func TestRegistrationError(t *testing.T) {
	err := protorpc.Register(new(ReplyNotPointer))
	if err == nil {
		t.Error("expected error registering ReplyNotPointer")
	}
	err = protorpc.Register(new(ArgNotPublic))
	if err == nil {
		t.Error("expected error registering ArgNotPublic")
	}
	err = protorpc.Register(new(ReplyNotPublic))
	if err == nil {
		t.Error("expected error registering ReplyNotPublic")
	}
	err = protorpc.Register(NeedsPtrType(0))
	if err == nil {
		t.Error("expected error registering NeedsPtrType")
	} else if !strings.Contains(err.Error(), "pointer") {
		t.Error("expected hint when registering NeedsPtrType")
	}
	//err = protorpc.Register(new(NotProtoType))
	//if err == nil {
	//	t.Error("expected error registering NotProtoType")
	//}
}
Beispiel #3
0
func TestProtoError(t *testing.T) {
	if runtime.GOOS == "plan9" {
		t.Skip("skipping test; see http://golang.org/issue/8908")
	}
	defer func() {
		err := recover()
		if err == nil {
			t.Fatal("no error")
		}
		if !strings.Contains("reading body proto: wrong wireType = 2 for field C", err.(error).Error()) {
			t.Fatal("expected proto', got", err)
		}
	}()
	protorpc.Register(new(S))

	listen, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}
	go protorpc.Accept(listen)

	client, err := protorpc.Dial("tcp", listen.Addr().String())
	if err != nil {
		panic(err)
	}

	var reply Reply
	err = client.Call("S.Recv", nil, &reply)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n", reply)
	client.Close()

	listen.Close()
}