use of org.apache.shenyu.common.dto.convert.selector.TarsUpstream in project incubator-shenyu by apache.
the class ShenyuClientRegisterDivideServiceImplTest method testBuildHandle.
@Test
public void testBuildHandle() {
shenyuClientRegisterDivideService = spy(shenyuClientRegisterDivideService);
final String returnStr = "[{protocol:'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8090',warmup:10,weight:50,status:true,timestamp:1637826588267}," + "{protocol:'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8091',warmup:10,weight:50,status:true,timestamp:1637826588267}]";
final String expected = "[{\"weight\":50,\"warmup\":10,\"protocol\":\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267}," + "{\"weight\":50,\"warmup\":10,\"protocol\":\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267}]";
List<URIRegisterDTO> list = new ArrayList<>();
list.add(URIRegisterDTO.builder().protocol("http://").appName("test1").rpcType(RpcTypeEnum.HTTP.getName()).host(LOCALHOST).port(8090).build());
SelectorDO selectorDO = mock(SelectorDO.class);
when(selectorDO.getHandle()).thenReturn(returnStr);
doNothing().when(shenyuClientRegisterDivideService).doSubmit(any(), any());
String actual = shenyuClientRegisterDivideService.buildHandle(list, selectorDO);
assertEquals(expected, actual);
List<TarsUpstream> resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 2);
list.clear();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.HTTP.getName()).host(LOCALHOST).port(8092).build());
selectorDO = mock(SelectorDO.class);
when(selectorDO.getHandle()).thenReturn(returnStr);
doNothing().when(shenyuClientRegisterDivideService).doSubmit(any(), any());
actual = shenyuClientRegisterDivideService.buildHandle(list, selectorDO);
resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 3);
list.clear();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.HTTP.getName()).host(LOCALHOST).port(8090).build());
doNothing().when(shenyuClientRegisterDivideService).doSubmit(any(), any());
selectorDO = mock(SelectorDO.class);
actual = shenyuClientRegisterDivideService.buildHandle(list, selectorDO);
resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 1);
}
use of org.apache.shenyu.common.dto.convert.selector.TarsUpstream in project incubator-shenyu by apache.
the class ShenyuClientRegisterGrpcServiceImplTest method testBuildHandle.
@Test
public void testBuildHandle() {
shenyuClientRegisterGrpcService = spy(shenyuClientRegisterGrpcService);
final String returnStr = "[{upstreamUrl='localhost:8090',weight=1,status=true,timestamp=1637826588267}," + "{upstreamUrl='localhost:8091',weight=2,status=true,timestamp=1637826588267}]";
final String expected = "[{\"weight\":1,\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267}," + "{\"weight\":2,\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267}]";
List<URIRegisterDTO> list = new ArrayList<>();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.GRPC.getName()).host("localhost").port(8090).build());
SelectorDO selectorDO = mock(SelectorDO.class);
when(selectorDO.getHandle()).thenReturn(returnStr);
doNothing().when(shenyuClientRegisterGrpcService).doSubmit(any(), any());
String actual = shenyuClientRegisterGrpcService.buildHandle(list, selectorDO);
assertEquals(actual, expected);
List<TarsUpstream> resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 2);
list.clear();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.GRPC.getName()).host("localhost").port(8092).build());
selectorDO = mock(SelectorDO.class);
when(selectorDO.getHandle()).thenReturn(returnStr);
doNothing().when(shenyuClientRegisterGrpcService).doSubmit(any(), any());
actual = shenyuClientRegisterGrpcService.buildHandle(list, selectorDO);
resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 3);
list.clear();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.GRPC.getName()).host("localhost").port(8090).build());
doNothing().when(shenyuClientRegisterGrpcService).doSubmit(any(), any());
selectorDO = mock(SelectorDO.class);
actual = shenyuClientRegisterGrpcService.buildHandle(list, selectorDO);
resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 1);
}
use of org.apache.shenyu.common.dto.convert.selector.TarsUpstream in project incubator-shenyu by apache.
the class ShenyuClientRegisterTarsServiceImplTest method testBuildHandle.
@Test
public void testBuildHandle() {
shenyuClientRegisterTarsService = spy(shenyuClientRegisterTarsService);
final String returnStr = "[{upstreamUrl:'localhost:8090',weight:1,warmup:10,status:true,timestamp:1637826588267}," + "{upstreamUrl:'localhost:8091',weight:2,warmup:10,status:true,timestamp:1637826588267}]";
final String expected = "[{\"weight\":1,\"warmup\":10,\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267}," + "{\"weight\":2,\"warmup\":10,\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267}]";
List<URIRegisterDTO> list = new ArrayList<>();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.TARS.getName()).host("localhost").port(8090).build());
SelectorDO selectorDO = mock(SelectorDO.class);
when(selectorDO.getHandle()).thenReturn(returnStr);
doNothing().when(shenyuClientRegisterTarsService).doSubmit(any(), any());
String actual = shenyuClientRegisterTarsService.buildHandle(list, selectorDO);
assertEquals(actual, expected);
List<TarsUpstream> resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 2);
list.clear();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.TARS.getName()).host("localhost").port(8092).build());
selectorDO = mock(SelectorDO.class);
when(selectorDO.getHandle()).thenReturn(returnStr);
doNothing().when(shenyuClientRegisterTarsService).doSubmit(any(), any());
actual = shenyuClientRegisterTarsService.buildHandle(list, selectorDO);
resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 3);
list.clear();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.TARS.getName()).host("localhost").port(8090).build());
doNothing().when(shenyuClientRegisterTarsService).doSubmit(any(), any());
selectorDO = mock(SelectorDO.class);
actual = shenyuClientRegisterTarsService.buildHandle(list, selectorDO);
resultList = GsonUtils.getInstance().fromCurrentList(actual, TarsUpstream.class);
assertEquals(resultList.size(), 1);
}
use of org.apache.shenyu.common.dto.convert.selector.TarsUpstream in project incubator-shenyu by apache.
the class ApplicationConfigCache method initPrxClass.
/**
* initPrxClass.
*
* @param selectorData selectorData
*/
public void initPrxClass(final SelectorData selectorData) {
try {
final List<TarsUpstream> upstreamList = GsonUtils.getInstance().fromList(selectorData.getHandle(), TarsUpstream.class);
if (CollectionUtils.isEmpty(upstreamList)) {
invalidate(selectorData.getName());
return;
}
refreshUpstreamCache.put(selectorData.getName(), upstreamList);
List<MetaData> metaDataList = ctxPathCache.getOrDefault(selectorData.getName(), new ArrayList<>());
for (MetaData metaData : metaDataList) {
refreshTarsInvokePrxList(metaData, upstreamList);
}
} catch (ExecutionException | NoSuchMethodException e) {
throw new ShenyuException(e.getCause());
}
}
use of org.apache.shenyu.common.dto.convert.selector.TarsUpstream in project incubator-shenyu by apache.
the class ShenyuClientRegisterGrpcServiceImplTest method testBuildGrpcUpstreamList.
@Test
public void testBuildGrpcUpstreamList() {
List<URIRegisterDTO> list = new ArrayList<>();
list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.GRPC.getName()).host("localhost").port(8090).build());
list.add(URIRegisterDTO.builder().appName("test2").rpcType(RpcTypeEnum.GRPC.getName()).host("localhost").port(8091).build());
try {
Method testMethod = shenyuClientRegisterGrpcService.getClass().getDeclaredMethod("buildGrpcUpstreamList", List.class);
testMethod.setAccessible(true);
List<TarsUpstream> result = (List<TarsUpstream>) testMethod.invoke(shenyuClientRegisterGrpcService, list);
assertEquals(result.size(), 2);
} catch (Exception e) {
throw new ShenyuException(e.getCause());
}
}
Aggregations