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();
}
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));
});
}
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());
});
}
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();
}
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());
}
Aggregations