dubbo.apache.org/dubbo-go/v3@v3.1.1/filter/tracing/filter_test.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package tracing 19 20 import ( 21 "context" 22 "testing" 23 ) 24 25 import ( 26 "github.com/opentracing/opentracing-go" 27 ) 28 29 import ( 30 "dubbo.apache.org/dubbo-go/v3/common" 31 "dubbo.apache.org/dubbo-go/v3/common/constant" 32 "dubbo.apache.org/dubbo-go/v3/protocol" 33 "dubbo.apache.org/dubbo-go/v3/protocol/invocation" 34 ) 35 36 func TestTracingFilterInvoke(t *testing.T) { 37 url, _ := common.NewURL( 38 "dubbo://:20000/UserProvider?app.version=0.0.1&application=BDTService&bean.name=UserProvider" + 39 "&cluster=failover&environment=dev&group=&interface=com.ikurento.user.UserProvider&loadbalance=random&methods.GetUser." + 40 "loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=" + 41 "BDTService&organization=ikurento.com&owner=ZX®istry.role=3&retries=&" + 42 "service.filter=echo%2Ctoken%2Caccesslog×tamp=1569153406&token=934804bf-b007-4174-94eb-96e3e1d60cc7&version=&warmup=100") 43 invoker := protocol.NewBaseInvoker(url) 44 45 attach := make(map[string]interface{}, 10) 46 inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach) 47 ctx := context.Background() 48 tf := newTracingFilter() 49 50 // do not has any span 51 tf.Invoke(ctx, invoker, inv) 52 53 span, ctx := opentracing.StartSpanFromContext(ctx, "Test-Operation") 54 defer span.Finish() 55 56 // has previous span 57 tf.Invoke(ctx, invoker, inv) 58 59 // has remote ctx 60 ctx = context.WithValue(context.Background(), constant.DubboCtxKey(constant.TracingRemoteSpanCtx), span.Context()) 61 tf.Invoke(ctx, invoker, inv) 62 }