dubbo.apache.org/dubbo-go/v3@v3.1.1/protocol/dubbo3/dubbo3_invoker_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 dubbo3
    19  
    20  import (
    21  	"context"
    22  	"reflect"
    23  	"testing"
    24  	"time"
    25  )
    26  
    27  import (
    28  	"github.com/stretchr/testify/assert"
    29  )
    30  
    31  import (
    32  	"dubbo.apache.org/dubbo-go/v3/common"
    33  	_ "dubbo.apache.org/dubbo-go/v3/metadata/service/exporter/configurable"
    34  	"dubbo.apache.org/dubbo-go/v3/protocol/dubbo3/internal"
    35  	"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
    36  )
    37  
    38  const (
    39  	mockDubbo3CommonUrl2 = "tri://127.0.0.1:20003/DubboGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=greeterImpl" +
    40  		"&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=org.apache.dubbo.DubboGreeterImpl" +
    41  		"&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=" +
    42  		"&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown&registry.role=3&remote.timestamp=1576923717&retries=" +
    43  		"&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider&timestamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!"
    44  )
    45  
    46  func TestInvoke(t *testing.T) {
    47  	go internal.InitDubboServer()
    48  	time.Sleep(time.Second * 3)
    49  
    50  	url, err := common.NewURL(mockDubbo3CommonUrl2)
    51  	assert.Nil(t, err)
    52  
    53  	invoker, err := NewDubboInvoker(url)
    54  
    55  	assert.Nil(t, err)
    56  
    57  	args := []reflect.Value{}
    58  	args = append(args, reflect.ValueOf(&internal.HelloRequest{Name: "request name"}))
    59  	bizReply := &internal.HelloReply{}
    60  	invo := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("SayHello"),
    61  		invocation.WithParameterValues(args), invocation.WithReply(bizReply))
    62  	res := invoker.Invoke(context.Background(), invo)
    63  	assert.Nil(t, res.Error())
    64  	assert.NotNil(t, res.Result())
    65  	assert.Equal(t, "Hello request name", bizReply.Message)
    66  }
    67  
    68  func TestInvokeTimoutConfig(t *testing.T) {
    69  	go internal.InitDubboServer()
    70  	time.Sleep(time.Second * 3)
    71  
    72  	// test for millisecond
    73  	tmpMockUrl := mockDubbo3CommonUrl2 + "&timeout=300ms"
    74  	url, err := common.NewURL(tmpMockUrl)
    75  	assert.Nil(t, err)
    76  
    77  	invoker, err := NewDubboInvoker(url)
    78  	assert.Nil(t, err)
    79  
    80  	assert.Equal(t, invoker.timeout, time.Duration(time.Millisecond*300))
    81  
    82  	// test for second
    83  	tmpMockUrl = mockDubbo3CommonUrl2 + "&timeout=1s"
    84  	url, err = common.NewURL(tmpMockUrl)
    85  	assert.Nil(t, err)
    86  
    87  	invoker, err = NewDubboInvoker(url)
    88  	assert.Nil(t, err)
    89  	assert.Equal(t, invoker.timeout, time.Duration(time.Second))
    90  
    91  	// test for timeout default config
    92  	url, err = common.NewURL(mockDubbo3CommonUrl2)
    93  	assert.Nil(t, err)
    94  
    95  	invoker, err = NewDubboInvoker(url)
    96  	assert.Nil(t, err)
    97  	assert.Equal(t, invoker.timeout, time.Duration(time.Second*3))
    98  }