Search in sources :

Example 31 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class TarsPluginTest method setUp.

@BeforeEach
public void setUp() {
    ConfigurableApplicationContext applicationContext = mock(ConfigurableApplicationContext.class);
    when(applicationContext.getBean(ShenyuResult.class)).thenReturn(new DefaultShenyuResult());
    SpringBeanUtils springBeanUtils = SpringBeanUtils.getInstance();
    springBeanUtils.setApplicationContext(applicationContext);
    metaData = new MetaData("id", "127.0.0.1:8080", "contextPath", "path", RpcTypeEnum.TARS.getName(), "serviceName", "method1", "parameterTypes", "{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":" + "[{\"left\":\"java.lang.String\",\"right\":\"param1\"},{\"left\":\"java.lang.String\"," + "\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}", false);
    ApplicationConfigCache.getInstance().initPrx(metaData);
    exchange = MockServerWebExchange.from(MockServerHttpRequest.get("localhost").build());
    tarsPluginUnderTest = new TarsPlugin();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MetaData(org.apache.shenyu.common.dto.MetaData) SpringBeanUtils(org.apache.shenyu.plugin.api.utils.SpringBeanUtils) DefaultShenyuResult(org.apache.shenyu.plugin.api.result.DefaultShenyuResult) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 32 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class ApplicationConfigCacheTest method testGet.

@Test
public void testGet() throws ClassNotFoundException {
    final String rpcExt = "{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":" + "[{\"left\":\"int\",\"right\":\"param1\"},{\"left\":\"java.lang.Integer\"," + "\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}";
    final MetaData metaData = new MetaData("id", "127.0.0.1:8080", "contextPath", "path5", RpcTypeEnum.TARS.getName(), "serviceName5", "method1", "parameterTypes", rpcExt, false);
    assertThrows(NullPointerException.class, () -> {
        applicationConfigCacheUnderTest.initPrx(metaData);
        final TarsInvokePrxList result = applicationConfigCacheUnderTest.get("path5");
        assertNotNull(result);
        assertEquals("promise_method1", result.getMethod().getName());
        assertEquals(2, result.getParamTypes().length);
        assertEquals(2, result.getParamNames().length);
        Class<?> prxClazz = Class.forName(PrxInfoUtil.getPrxName(metaData));
        assertTrue(Arrays.stream(prxClazz.getAnnotations()).anyMatch(annotation -> annotation instanceof Servant));
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Arrays(java.util.Arrays) ShenyuThreadFactory(org.apache.shenyu.common.concurrent.ShenyuThreadFactory) Servant(com.qq.tars.protocol.annotation.Servant) Executors(java.util.concurrent.Executors) RpcTypeEnum(org.apache.shenyu.common.enums.RpcTypeEnum) Test(org.junit.jupiter.api.Test) TarsInvokePrxList(org.apache.shenyu.plugin.tars.proxy.TarsInvokePrxList) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Lists(org.assertj.core.util.Lists) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PrxInfoUtil(org.apache.shenyu.plugin.tars.util.PrxInfoUtil) MetaData(org.apache.shenyu.common.dto.MetaData) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) MetaData(org.apache.shenyu.common.dto.MetaData) TarsInvokePrxList(org.apache.shenyu.plugin.tars.proxy.TarsInvokePrxList) Servant(com.qq.tars.protocol.annotation.Servant) Test(org.junit.jupiter.api.Test)

Example 33 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class ApplicationConfigCacheTest method testConcurrentInitPrx.

@Test
public void testConcurrentInitPrx() {
    final String rpcExt1 = "{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":" + "[{\"left\":\"int\",\"right\":\"param1\"},{\"left\":\"java.lang.Integer\"," + "\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}";
    final String rpcExt2 = "{\"methodInfo\":[{\"methodName\":\"method2\",\"params\":" + "[{\"left\":\"int\",\"right\":\"param1\"},{\"left\":\"java.lang.Integer\"," + "\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}";
    final String rpcExt3 = "{\"methodInfo\":[{\"methodName\":\"method3\",\"params\":" + "[{\"left\":\"int\",\"right\":\"param1\"},{\"left\":\"java.lang.Integer\"," + "\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}";
    final String rpcExt4 = "{\"methodInfo\":[{\"methodName\":\"method4\",\"params\":" + "[{\"left\":\"int\",\"right\":\"param1\"},{\"left\":\"java.lang.Integer\"," + "\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}";
    final MetaData metaData1 = new MetaData("id", "127.0.0.1:8080", "contextPath", "path1", RpcTypeEnum.TARS.getName(), "serviceName1", "method1", "parameterTypes", rpcExt1, false);
    final MetaData metaData2 = new MetaData("id", "127.0.0.1:8080", "contextPath", "path2", RpcTypeEnum.TARS.getName(), "serviceName2", "method2", "parameterTypes", rpcExt2, false);
    final MetaData metaData3 = new MetaData("id", "127.0.0.1:8080", "contextPath", "path3", RpcTypeEnum.TARS.getName(), "serviceName3", "method3", "parameterTypes", rpcExt3, false);
    final MetaData metaData4 = new MetaData("id", "127.0.0.1:8080", "contextPath", "path4", RpcTypeEnum.TARS.getName(), "serviceName4", "method4", "parameterTypes", rpcExt4, false);
    List<MetaData> metaDataList = Lists.list(metaData1, metaData2, metaData3, metaData4);
    assertThrows(NullPointerException.class, () -> {
        ExecutorService executorService = Executors.newFixedThreadPool(4, ShenyuThreadFactory.create("ApplicationConfigCache-tars-initPrx", false));
        CountDownLatch countDownLatch = new CountDownLatch(4);
        metaDataList.forEach(metaData -> executorService.execute(() -> {
            applicationConfigCacheUnderTest.initPrx(metaData);
            countDownLatch.countDown();
        }));
        countDownLatch.await();
        assertEquals("promise_method1", applicationConfigCacheUnderTest.get("path1").getMethod().getName());
        assertEquals("promise_method2", applicationConfigCacheUnderTest.get("path2").getMethod().getName());
        assertEquals("promise_method3", applicationConfigCacheUnderTest.get("path3").getMethod().getName());
        assertEquals("promise_method4", applicationConfigCacheUnderTest.get("path4").getMethod().getName());
    });
}
Also used : MetaData(org.apache.shenyu.common.dto.MetaData) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 34 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class TarsMetaDataSubscriberTest method setUp.

@BeforeEach
public void setUp() {
    metaData = new MetaData("id", "127.0.0.1:8080", "contextPath", "path", RpcTypeEnum.TARS.getName(), "serviceName", "method1", "parameterTypes", "{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":[{\"left\":\"int\",\"right\":\"param1\"}," + "{\"left\":\"java.lang.Integer\",\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}", false);
    tarsMetaDataSubscriber = new TarsMetaDataSubscriber();
}
Also used : MetaData(org.apache.shenyu.common.dto.MetaData) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class ConsulCacheHandlerTest method testUpdateMetaDataMap.

@Test
public void testUpdateMetaDataMap() {
    String metadataPath1 = "METADATA_PATH_1";
    String metadataPath2 = "METADATA_PATH_2";
    MetaData metaData1 = MetaData.builder().path(metadataPath1).id("meta_1").build();
    MetaData metaData2 = MetaData.builder().path(metadataPath2).id("meta_2").build();
    String metaDataParam = GsonUtils.getInstance().toJson(ImmutableMap.of(metadataPath1, metaData1, metadataPath2, metaData2));
    final List<MetaData> subscribeList = new ArrayList<>();
    final List<MetaData> unsubscribeList = new ArrayList<>();
    MetaDataSubscriber metaDataSubscriber = new MetaDataSubscriber() {

        @Override
        public void onSubscribe(final MetaData metaData) {
            subscribeList.add(metaData);
        }

        @Override
        public void unSubscribe(final MetaData metaData) {
            unsubscribeList.add(metaData);
        }
    };
    ConsulCacheHandler consulCacheHandler = new ConsulCacheHandler(null, Lists.newArrayList(metaDataSubscriber), Collections.emptyList());
    consulCacheHandler.updateMetaDataMap(metaDataParam);
    assertEquals(2, subscribeList.size());
    assertEquals(2, unsubscribeList.size());
}
Also used : MetaDataSubscriber(org.apache.shenyu.sync.data.api.MetaDataSubscriber) MetaData(org.apache.shenyu.common.dto.MetaData) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

MetaData (org.apache.shenyu.common.dto.MetaData)70 Test (org.junit.jupiter.api.Test)31 BeforeEach (org.junit.jupiter.api.BeforeEach)14 RuleData (org.apache.shenyu.common.dto.RuleData)11 SelectorData (org.apache.shenyu.common.dto.SelectorData)10 ShenyuContext (org.apache.shenyu.plugin.api.context.ShenyuContext)9 ArrayList (java.util.ArrayList)8 MetaDataSubscriber (org.apache.shenyu.sync.data.api.MetaDataSubscriber)8 ServerWebExchange (org.springframework.web.server.ServerWebExchange)7 Objects (java.util.Objects)6 ShenyuException (org.apache.shenyu.common.exception.ShenyuException)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Optional (java.util.Optional)5 Constants (org.apache.shenyu.common.constant.Constants)5 ShenyuPluginChain (org.apache.shenyu.plugin.api.ShenyuPluginChain)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ResultEnum (org.apache.shenyu.common.enums.ResultEnum)4 RpcTypeEnum (org.apache.shenyu.common.enums.RpcTypeEnum)4 GsonUtils (org.apache.shenyu.common.utils.GsonUtils)4