dubbo.apache.org/dubbo-go/v3@v3.1.1/filter/metrics/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 metrics 19 20 import ( 21 "context" 22 "testing" 23 ) 24 25 import ( 26 "github.com/stretchr/testify/assert" 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/metrics" 33 "dubbo.apache.org/dubbo-go/v3/protocol" 34 "dubbo.apache.org/dubbo-go/v3/protocol/invocation" 35 ) 36 37 func TestMetricsFilterInvoke(t *testing.T) { 38 mockChan := make(chan metrics.MetricsEvent, 10) 39 defer close(mockChan) 40 metrics.Subscribe(constant.MetricsRpc, mockChan) 41 42 url, _ := common.NewURL( 43 "dubbo://:20000/UserProvider?app.version=0.0.1&application=BDTService&bean.name=UserProvider" + 44 "&cluster=failover&environment=dev&group=&interface=com.ikurento.user.UserProvider&loadbalance=random&methods.GetUser." + 45 "loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=" + 46 "BDTService&organization=ikurento.com&owner=ZX®istry.role=3&retries=&" + 47 "service.filter=echo%2Ctoken%2Caccesslog×tamp=1569153406&token=934804bf-b007-4174-94eb-96e3e1d60cc7&version=&warmup=100") 48 invoker := protocol.NewBaseInvoker(url) 49 50 attach := make(map[string]interface{}, 10) 51 inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach) 52 ctx := context.Background() 53 54 filter := newFilter() 55 result := filter.Invoke(ctx, invoker, inv) 56 assert.NotNil(t, result) 57 result = filter.OnResponse(ctx, nil, invoker, inv) 58 assert.Nil(t, result) 59 60 assert.Equal(t, 2, len(mockChan)) 61 assert.Equal(t, constant.MetricsRpc, (<-mockChan).Type()) 62 }