本文整理汇总了Golang中go/uber/org/yarpc.NewReqMeta函数的典型用法代码示例。如果您正苦于以下问题:Golang NewReqMeta函数的具体用法?Golang NewReqMeta怎么用?Golang NewReqMeta使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewReqMeta函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCallOnewayFailure
func TestCallOnewayFailure(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
ctx := context.Background()
caller := "caller"
service := "service"
procedure := "procedure"
body := []byte{1, 2, 3}
outbound := transporttest.NewMockOnewayOutbound(mockCtrl)
client := New(channel.MultiOutbound(caller, service,
transport.Outbounds{
Oneway: outbound,
}))
outbound.EXPECT().CallOneway(gomock.Any(),
transporttest.NewRequestMatcher(t,
&transport.Request{
Service: service,
Caller: caller,
Procedure: procedure,
Encoding: Encoding,
Body: bytes.NewReader(body),
}),
).Return(nil, errors.New("some error"))
_, err := client.CallOneway(
ctx,
yarpc.NewReqMeta().Procedure(procedure),
body)
assert.Error(t, err)
}
示例2: TestRecording
func TestRecording(t *testing.T) {
tMock := testingTMock{t, 0}
dir, err := ioutil.TempDir("", "yarpcgorecorder")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
recorder := NewRecorder(&tMock, RecordMode(Append), RecordsPath(dir))
withConnectedClient(t, recorder, func(client raw.Client) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
rbody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
require.NoError(t, err)
assert.Equal(t, []byte("Hello, World"), rbody)
})
recordPath := path.Join(dir, refRecordFilename)
_, err = os.Stat(recordPath)
require.NoError(t, err)
recordContent, err := ioutil.ReadFile(recordPath)
require.NoError(t, err)
assert.Equal(t, refRecordContent, string(recordContent))
}
示例3: Handle
func (h *multiHopHandler) Handle(ctx context.Context, reqMeta yarpc.ReqMeta, body interface{}) (interface{}, yarpc.ResMeta, error) {
if h.phoneClient == nil {
panic("call SetClient() and SetTransport() first")
}
assertBaggageMatches(ctx, h.t, h.wantBaggage)
span := opentracing.SpanFromContext(ctx)
for key, value := range h.addBaggage {
span.SetBaggageItem(key, value)
}
ctx = opentracing.ContextWithSpan(ctx, span)
var resp js.RawMessage
phoneResMeta, err := h.phoneClient.Call(
ctx,
yarpc.NewReqMeta().Procedure("phone").Headers(reqMeta.Headers()),
&server.PhoneRequest{
Service: "ctxclient",
Procedure: h.phoneCallTo,
Transport: h.phoneCallTransport,
Body: &js.RawMessage{'{', '}'},
}, &resp)
resMeta := yarpc.NewResMeta().Headers(phoneResMeta.Headers())
return map[string]interface{}{}, resMeta, err
}
示例4: JSON
// 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")
}
示例5: TestEndToEnd
func TestEndToEnd(t *testing.T) {
tMock := testingTMock{t, 0}
dir, err := ioutil.TempDir("", "yarpcgorecorder")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
// First we double check that our cache is empty.
recorder := NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir))
withDisconnectedClient(t, recorder, func(client raw.Client) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
require.Panics(t, func() {
client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
})
assert.Equal(t, tMock.fatalCount, 1)
})
// Now let's record our call.
recorder = NewRecorder(&tMock, RecordMode(Overwrite), RecordsPath(dir))
withConnectedClient(t, recorder, func(client raw.Client) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
rbody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
require.NoError(t, err)
assert.Equal(t, rbody, []byte("Hello, World"))
})
// Now replay the call.
recorder = NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir))
withDisconnectedClient(t, recorder, func(client raw.Client) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
rbody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
require.NoError(t, err)
assert.Equal(t, rbody, []byte("Hello, World"))
})
}
示例6: runYARPCClient
func runYARPCClient(b *testing.B, c raw.Client) {
for i := 0; i < b.N; i++ {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
_, _, err := c.Call(ctx, yarpc.NewReqMeta().Procedure("echo"), _reqBody)
require.NoError(b, err, "request %d failed", i+1)
}
}
示例7: echoEcho
func (h handler) echoEcho(ctx context.Context) error {
var resBody echoResBody
_, err := h.client.Call(
ctx,
yarpc.NewReqMeta().Procedure("echoecho"),
&echoReqBody{},
&resBody,
)
return err
}
示例8: set
func set(ctx context.Context, c json.Client, k string, v string) error {
var response setResponse
ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
defer cancel()
_, err := c.Call(
ctx,
yarpc.NewReqMeta().Procedure("set"),
&setRequest{Key: k, Value: v},
&response,
)
return err
}
示例9: rawCall
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
}
示例10: get
func get(ctx context.Context, c json.Client, k string) (string, error) {
var response getResponse
ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
defer cancel()
_, err := c.Call(
ctx,
yarpc.NewReqMeta().Procedure("get"),
&getRequest{Key: k},
&response,
)
return response.Value, err
}
示例11: jsonCall
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
}
示例12: Call
func (c rawCaller) Call(h yarpc.Headers) (yarpc.Headers, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, res, err := c.c.Call(
ctx,
yarpc.NewReqMeta().Headers(h).Procedure("echo/raw"),
[]byte("hello"))
if err != nil {
return yarpc.Headers{}, err
}
return res.Headers(), nil
}
示例13: handleEchoEcho
func (h handler) handleEchoEcho(ctx context.Context, reqMeta yarpc.ReqMeta, reqBody *echoReqBody) (*echoResBody, yarpc.ResMeta, error) {
h.assertBaggage(ctx)
var resBody echoResBody
_, err := h.client.Call(
ctx,
yarpc.NewReqMeta().Procedure("echo"),
reqBody,
&resBody,
)
if err != nil {
return nil, nil, err
}
return &resBody, nil, nil
}
示例14: call
func call(client helloclient.Interface, message string) (*echo.EchoResponse, yarpc.Headers) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
resBody, resMeta, err := client.Echo(
ctx,
yarpc.NewReqMeta().Headers(yarpc.NewHeaders().With("from", "self")),
&echo.EchoRequest{Message: message, Count: 1},
)
if err != nil {
log.Fatal(err)
}
return resBody, resMeta.Headers()
}
示例15: thriftCall
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
}