Exemple #1
0
// JSON starts an http run using JSON encoding
func JSON(t crossdock.T, dispatcher yarpc.Dispatcher) {
	fatals := crossdock.Fatals(t)

	client := json.New(dispatcher.Channel("oneway-test"))
	token := getRandomID()

	ack, err := client.CallOneway(
		context.Background(),
		yarpc.NewReqMeta().Procedure("echo/json"),
		&jsonToken{Token: token},
	)

	// ensure channel hasn't been filled yet
	select {
	case <-serverCalledBack:
		fatals.FailNow("oneway json test failed", "client waited for server to fill channel")
	default:
	}

	fatals.NoError(err, "call to oneway/json failed: %v", err)
	fatals.NotNil(ack, "ack is nil")

	serverToken := <-serverCalledBack
	fatals.Equal(token, string(serverToken), "Client/Server token mismatch")
}
Exemple #2
0
func rawCall(dispatcher yarpc.Dispatcher, headers yarpc.Headers, procedure string,
	token []byte) ([]byte, yarpc.CallResMeta, error) {
	client := raw.New(dispatcher.Channel(serverName))

	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()

	reqMeta := yarpc.NewReqMeta().Procedure(procedure).Headers(headers)
	resBody, resMeta, err := client.Call(ctx, reqMeta, token)

	return resBody, resMeta, err
}
Exemple #3
0
func jsonCall(dispatcher yarpc.Dispatcher, headers yarpc.Headers, token string) (string, yarpc.CallResMeta, error) {
	client := json.New(dispatcher.Channel(serverName))

	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()

	reqMeta := yarpc.NewReqMeta().Procedure("echo").Headers(headers)
	reqBody := &jsonEcho{Token: token}

	var resBody jsonEcho
	resMeta, err := client.Call(ctx, reqMeta, reqBody, &resBody)
	return resBody.Token, resMeta, err
}
Exemple #4
0
func thriftCall(dispatcher yarpc.Dispatcher, headers yarpc.Headers, token string) (string, yarpc.CallResMeta, error) {
	client := echoclient.New(dispatcher.Channel(serverName))

	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()

	reqMeta := yarpc.NewReqMeta().Headers(headers)
	ping := &echo.Ping{Beep: token}

	resBody, resMeta, err := client.Echo(ctx, reqMeta, ping)
	if err != nil {
		return "", nil, err
	}
	return resBody.Boop, resMeta, err
}
Exemple #5
0
// Thrift starts an http oneway run using Thrift encoding
func Thrift(t crossdock.T, dispatcher yarpc.Dispatcher) {
	fatals := crossdock.Fatals(t)

	client := onewayclient.New(dispatcher.Channel("oneway-test"))
	ctx := context.Background()

	token := getRandomID()
	ack, err := client.Echo(ctx, nil, &token)

	// ensure channel hasn't been filled yet
	select {
	case <-serverCalledBack:
		fatals.FailNow("oneway thrift test failed", "client waited for server to fill channel")
	default:
	}

	fatals.NoError(err, "call to Oneway::echo failed: %v", err)
	fatals.NotNil(ack, "ack is nil")

	serverToken := <-serverCalledBack
	fatals.Equal(token, string(serverToken), "Client/Server token mismatch")
}
Exemple #6
0
// runRaw tests if a yarpc client returns a remote timeout error behind the
// TimeoutError interface when a remote http handler returns a handler timeout.
func runRaw(t crossdock.T, disp yarpc.Dispatcher) {
	assert := crossdock.Assert(t)
	fatals := crossdock.Fatals(t)

	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
	defer cancel()

	ch := raw.New(disp.Channel("yarpc-test"))
	_, _, err := ch.Call(ctx, yarpc.NewReqMeta().Procedure("handlertimeout/raw"), nil)
	fatals.Error(err, "expected an error")

	if transport.IsBadRequestError(err) {
		t.Skipf("handlertimeout/raw method not implemented: %v", err)
		return
	}

	assert.True(transport.IsTimeoutError(err), "returns a TimeoutError: %T", err)

	form := strings.HasPrefix(err.Error(),
		`Timeout: call to procedure "handlertimeout/raw" of service "service" from caller "caller" timed out after`)
	assert.True(form, "must be a remote handler timeout: %q", err.Error())
}
Exemple #7
0
// Raw starts an http run using raw encoding
func Raw(t crossdock.T, dispatcher yarpc.Dispatcher) {
	fatals := crossdock.Fatals(t)

	client := raw.New(dispatcher.Channel("oneway-test"))
	ctx := context.Background()

	token := []byte(getRandomID())
	ack, err := client.CallOneway(ctx, yarpc.NewReqMeta().Procedure("echo/raw"), token)

	// ensure channel hasn't been filled yet
	select {
	case <-serverCalledBack:
		fatals.FailNow("oneway raw test failed", "client waited for server to fill channel")
	default:
	}

	fatals.NoError(err, "call to oneway/raw failed: %v", err)
	fatals.NotNil(ack, "ack is nil")

	serverToken := <-serverCalledBack
	fatals.Equal(token, serverToken, "Client/Server token mismatch.")
}
Exemple #8
0
func (h handler) register(dispatcher yarpc.Dispatcher) {
	dispatcher.Register(json.Procedure("echo", h.handleEcho))
	dispatcher.Register(json.Procedure("echoecho", h.handleEchoEcho))
}