コード例 #1
1
ファイル: behavior.go プロジェクト: yarpc/yarpc-go
// Run runs the apachethrift behavior
func Run(t crossdock.T) {
	fatals := crossdock.Fatals(t)

	server := t.Param(serverParam)
	fatals.NotEmpty(server, "apachethriftserver is required")

	baseURL := fmt.Sprintf("http://%v:%v", server, serverPort)

	thriftOutbound := http.NewOutbound(baseURL + "/thrift/ThriftTest")
	secondOutbound := http.NewOutbound(baseURL + "/thrift/SecondService")
	multiplexOutbound := http.NewOutbound(baseURL + "/thrift/multiplexed")

	dispatcher := yarpc.NewDispatcher(yarpc.Config{
		Name: "apache-thrift-client",
		Outbounds: yarpc.Outbounds{
			"ThriftTest": {
				Unary:  thriftOutbound,
				Oneway: thriftOutbound,
			},
			"SecondService": {
				Unary: secondOutbound,
			},
			"Multiplexed": {
				Unary:  multiplexOutbound,
				Oneway: multiplexOutbound,
			},
		},
	})
	fatals.NoError(dispatcher.Start(), "could not start Dispatcher")
	defer dispatcher.Stop()

	// We can just run all the gauntlet tests against each URL because
	// tests for undefined methods are skipped.
	tests := []struct {
		ServerName string
		Services   gauntlet.ServiceSet
		Options    []thrift.ClientOption
	}{
		{
			ServerName: "ThriftTest",
			Services:   gauntlet.ThriftTest,
		},
		{
			ServerName: "SecondService",
			Services:   gauntlet.SecondService,
		},
		{
			ServerName: "Multiplexed",
			Services:   gauntlet.AllServices,
			Options:    []thrift.ClientOption{thrift.Multiplexed},
		},
	}

	for _, tt := range tests {
		t.Tag("outbound", tt.ServerName)
		gauntlet.RunGauntlet(t, gauntlet.Config{
			Dispatcher:    dispatcher,
			ServerName:    tt.ServerName,
			Envelope:      true,
			Services:      tt.Services,
			ClientOptions: tt.Options,
		})
	}
}
コード例 #2
0
ファイル: thrift.go プロジェクト: yarpc/yarpc-go
func runThrift(t crossdock.T, dispatcher yarpc.Dispatcher) {
	assert := crossdock.Assert(t)
	checks := crossdock.Checks(t)

	headers := yarpc.NewHeaders().With("hello", "thrift")
	token := random.String(5)

	resBody, resMeta, err := thriftCall(dispatcher, headers, token)
	if skipOnConnRefused(t, err) {
		return
	}
	if checks.NoError(err, "thrift: call failed") {
		assert.Equal(token, resBody, "body echoed")
		resHeaders := internal.RemoveVariableHeaderKeys(resMeta.Headers())
		assert.Equal(headers, resHeaders, "headers echoed")
	}

	t.Tag("server", t.Param(params.Server))
	gauntlet.RunGauntlet(t, gauntlet.Config{
		Dispatcher: dispatcher,
		ServerName: serverName,
	})
}