Search in sources :

Example 1 with SimpleFuture

use of com.alibaba.dubbo.remoting.exchange.support.SimpleFuture in project incubator-shenyu by apache.

the class AlibabaDubboProxyServiceTest method testGenericInvoker.

@Test
public void testGenericInvoker() throws Exception {
    GenericService genericService = mock(GenericService.class);
    String sample = String.format("%x", System.nanoTime());
    when(referenceConfig.get()).thenReturn(genericService);
    when(genericService.$invoke(METHOD_NAME, LEFT, RIGHT)).then(invocationOnMock -> {
        RpcContext.getContext().setFuture(new FutureAdapter<>(new SimpleFuture(new RpcResult(sample))));
        return sample;
    });
    try (MockedStatic<AlibabaDubboConfigCache> ignored = mockStatic(AlibabaDubboConfigCache.class)) {
        AlibabaDubboConfigCache alibabaDubboConfigCache = mock(AlibabaDubboConfigCache.class);
        when(AlibabaDubboConfigCache.getInstance()).thenReturn(alibabaDubboConfigCache);
        when(alibabaDubboConfigCache.initRef(metaData)).thenReturn(referenceConfig);
        AlibabaDubboProxyService alibabaDubboProxyService = new AlibabaDubboProxyService(new BodyParamResolveServiceImpl());
        ResponseFuture responseFuture = alibabaDubboProxyService.genericInvoker("", metaData);
        assertNotNull(responseFuture);
        assertEquals(sample, RpcContext.getContext().getFuture().get());
    }
}
Also used : GenericService(com.alibaba.dubbo.rpc.service.GenericService) RpcResult(com.alibaba.dubbo.rpc.RpcResult) AlibabaDubboConfigCache(org.apache.shenyu.plugin.alibaba.dubbo.cache.AlibabaDubboConfigCache) ResponseFuture(com.alibaba.dubbo.remoting.exchange.ResponseFuture) SimpleFuture(com.alibaba.dubbo.remoting.exchange.support.SimpleFuture) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleFuture

use of com.alibaba.dubbo.remoting.exchange.support.SimpleFuture in project incubator-shenyu by apache.

the class AlibabaDubboPluginTest method setUp.

@BeforeEach
public void setUp() {
    metaData = new MetaData();
    metaData.setId("1332017966661636096");
    metaData.setAppName("dubbo");
    metaData.setPath("/dubbo/findAll");
    metaData.setServiceName("org.apache.shenyu.test.dubbo.api.service.DubboTestService");
    metaData.setMethodName("findAll");
    metaData.setRpcType(RpcTypeEnum.DUBBO.getName());
    when(mockAlibabaDubboProxyService.genericInvoker(null, metaData)).thenReturn(new SimpleFuture(new RpcResult(metaData.getId())));
    alibabaDubboPluginUnderTest = new AlibabaDubboPlugin(mockAlibabaDubboProxyService);
}
Also used : MetaData(org.apache.shenyu.common.dto.MetaData) RpcResult(com.alibaba.dubbo.rpc.RpcResult) SimpleFuture(com.alibaba.dubbo.remoting.exchange.support.SimpleFuture) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SimpleFuture (com.alibaba.dubbo.remoting.exchange.support.SimpleFuture)2 RpcResult (com.alibaba.dubbo.rpc.RpcResult)2 ResponseFuture (com.alibaba.dubbo.remoting.exchange.ResponseFuture)1 GenericService (com.alibaba.dubbo.rpc.service.GenericService)1 MetaData (org.apache.shenyu.common.dto.MetaData)1 AlibabaDubboConfigCache (org.apache.shenyu.plugin.alibaba.dubbo.cache.AlibabaDubboConfigCache)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1