dubbo.apache.org/dubbo-go/v3@v3.1.1/protocol/jsonrpc/jsonrpc_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 jsonrpc
    19  
    20  //
    21  //import (
    22  //	"context"
    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/proxy/proxy_factory"
    34  //	"dubbo.apache.org/dubbo-go/v3/protocol"
    35  //	"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
    36  //)
    37  //
    38  //func TestJsonrpcInvokerInvoke(t *testing.T) {
    39  //	methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "jsonrpc", "", "", &UserProvider{})
    40  //	assert.NoError(t, err)
    41  //	assert.Equal(t, "GetUser,GetUser0,GetUser1,GetUser2,GetUser3,GetUser4", methods)
    42  //
    43  //	// Export
    44  //	proto := GetProtocol()
    45  //	url, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&" +
    46  //		"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
    47  //		"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
    48  //		"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
    49  //		"side=provider&timeout=3000&timestamp=1556509797245&bean.name=UserProvider")
    50  //	assert.NoError(t, err)
    51  //	proto.Export(&proxy_factory.ProxyInvoker{
    52  //		BaseInvoker: *protocol.NewBaseInvoker(url),
    53  //	})
    54  //	time.Sleep(time.Second * 2)
    55  //
    56  //	client := NewHTTPClient(&HTTPOptions{
    57  //		HandshakeTimeout: time.Second,
    58  //		HTTPTimeout:      time.Second,
    59  //	})
    60  //
    61  //	jsonInvoker := NewJsonrpcInvoker(url, client)
    62  //	user := &User{}
    63  //	res := jsonInvoker.Invoke(context.Background(), invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("GetUser"), invocation.WithArguments([]interface{}{"1", "username"}),
    64  //		invocation.WithReply(user)))
    65  //
    66  //	assert.NoError(t, res.Error())
    67  //	assert.Equal(t, User{ID: "1", Name: "username"}, *res.Result().(*User))
    68  //
    69  //	// destroy
    70  //	proto.Destroy()
    71  //}