예제 #1
0
func TestProxyClosesPipe(t *testing.T) {
	request, pointer := echo.CreateMessagePipeForEcho()
	// Create a message with valid header and invalid payload and send it.
	header := bindings.MessageHeader{0, bindings.MessageIsResponseFlag, 1}
	message, err := bindings.EncodeMessage(header, &header)
	if err != nil {
		t.Fatalf("Error encoding message: %v", err)
	}
	requestPipe := request.PassMessagePipe()
	if r := requestPipe.WriteMessage(message.Bytes, nil, system.MOJO_WRITE_MESSAGE_FLAG_NONE); r != system.MOJO_RESULT_OK {
		t.Fatalf("Can't send a message: %v", r)
	}

	// Make echo request with response (that is already sent).
	echoProxy := echo.NewEchoProxy(pointer, waiter)
	_, err = echoProxy.EchoString(bindings.StringPointer("hello, world"))
	if err == nil {
		t.Fatalf("Message is invalid, error expected")
	}

	// Wait for the pipe to be closed.
	waitResponseChan := make(chan bindings.WaitResponse)
	waiter.AsyncWait(requestPipe, system.MOJO_HANDLE_SIGNAL_PEER_CLOSED, waitResponseChan)
	waitResponse := <-waitResponseChan
	if waitResponse.Result != system.MOJO_RESULT_OK {
		t.Fatalf("Error waiting on pipe to be closed: %v", waitResponse.Result)
	}
	requestPipe.Close()
}
예제 #2
0
func checkEcho(echoPointer echo.Echo_Pointer) {
	echo := echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter())
	str := fmt.Sprintf("Hello, world")
	response, err := echo.EchoString(&str)
	if err != nil {
		panic(err)
	}
	if *response != str {
		panic(fmt.Sprintf("invalid response: want %v, got %v", str, *response))
	}
	echo.Close_Proxy()
}
예제 #3
0
파일: echo_client.go 프로젝트: Miaque/mojo
func (delegate *EchoClientDelegate) Initialize(ctx application.Context) {
	echoRequest, echoPointer := echo.CreateMessagePipeForEcho()
	ctx.ConnectToApplication("mojo:go_echo_server").ConnectToService(&echoRequest)
	echoProxy := echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter())
	response, err := echoProxy.EchoString(bindings.StringPointer("Hello, Go world!"))
	if response != nil {
		fmt.Printf("client: %s\n", *response)
	} else {
		log.Println(err)
	}
	echoProxy.Close_Proxy()
	ctx.Close()
}