use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project java-chassis by ServiceComb.
the class ConfigCenterConfigurationSourceImplTest method onRefreshEndpointEventTest.
@Test
void onRefreshEndpointEventTest() {
List<String> addresses = new ArrayList<>();
addresses.add("http://127.0.0.1:30103");
List<String> addressAZ = new ArrayList<>();
addressAZ.add("rest://127.0.0.1:30100?sslEnabled=true");
Map<String, List<String>> zoneAndRegion = new HashMap<>();
zoneAndRegion.put("sameZone", addressAZ);
zoneAndRegion.put("sameRegion", new ArrayList<>());
RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "CseConfigCenter");
AddressManager addressManager = new AddressManager("test", addresses, EventManager.getEventBus());
addressManager.onRefreshEndpointEvent(event);
List<String> availableAZ = Deencapsulation.getField(addressManager, "availableZone");
Assert.assertEquals("https://127.0.0.1:30100/v3/test", availableAZ.get(0));
}
use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project java-chassis by ServiceComb.
the class AbstractAddressManagerTest method refreshEndpointTest.
@Test
public void refreshEndpointTest() {
List<String> addressAZ = new ArrayList<>();
addressAZ.add("rest://127.0.0.1:30100");
Map<String, List<String>> zoneAndRegion = new HashMap<>();
zoneAndRegion.put("sameZone", addressAZ);
zoneAndRegion.put("sameRegion", new ArrayList<>());
RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "TEST");
addressManager1.refreshEndpoint(event, "KIE");
Assert.assertEquals("https://127.0.0.2:30103", addressManager1.address());
Assert.assertEquals("http://127.0.0.1:30103", addressManager1.address());
Assert.assertEquals("https://127.0.0.2:30103", addressManager1.address());
addressManager2.refreshEndpoint(event, "TEST");
Assert.assertEquals("http://127.0.0.1:30100", addressManager2.address());
Assert.assertEquals("http://127.0.0.1:30100", addressManager2.address());
}
use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project java-chassis by ServiceComb.
the class AbstractAddressManagerTest method recordStateTest.
@Test
public void recordStateTest() throws ExecutionException {
List<String> addressAZ = new ArrayList<>();
addressAZ.add("http://127.0.0.3:30100");
List<String> addressRG = new ArrayList<>();
addressRG.add("http://127.0.0.4:30100");
Map<String, List<String>> zoneAndRegion = new HashMap<>();
zoneAndRegion.put("sameZone", addressAZ);
zoneAndRegion.put("sameRegion", addressRG);
RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "TEST");
AbstractAddressManager addressManager = new AbstractAddressManager(addresses);
addressManager.refreshEndpoint(event, "TEST");
String address = "http://127.0.0.3:30100";
addressManager.recordFailState(address);
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
addressManager.recordFailState(address);
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
// test fail 2 times ,it will not be isolated
addressManager.recordSuccessState(address);
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
// test recodeStatus times
Map<String, Integer> recodeStatus = Deencapsulation.getField(addressManager, "recodeStatus");
Assert.assertEquals(0, (int) recodeStatus.get("http://127.0.0.3:30100"));
// test fail 3 times ,it will be isolated
addressManager.recordFailState(address);
addressManager.recordFailState(address);
addressManager.recordFailState(address);
Assert.assertEquals("http://127.0.0.4:30100", addressManager.address());
// mock cacheAddress status refresh after 10 minute
Cache<String, Boolean> cache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(10, TimeUnit.MINUTES).build();
cache.put("http://127.0.0.3:30100", true);
// mock the address telnetTest is access
new Expectations(addressManager) {
{
Deencapsulation.setField(addressManager, "cacheAddress", cache);
Deencapsulation.invoke(addressManager, "telnetTest", "http://127.0.0.3:30100");
result = true;
}
};
Cache<String, Boolean> result = Deencapsulation.getField(addressManager, "cacheAddress");
Assert.assertEquals(true, result.get("http://127.0.0.3:30100", () -> false));
// test restore isolation
addressManager.checkHistory();
addressManager.rejoinAddress("http://127.0.0.3:30100");
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
}
use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project incubator-servicecomb-java-chassis by apache.
the class ConfigCenterConfigurationSourceImplTest method onRefreshEndpointEventTest.
@Test
void onRefreshEndpointEventTest() {
List<String> addresses = new ArrayList<>();
addresses.add("http://127.0.0.1:30103");
List<String> addressAZ = new ArrayList<>();
addressAZ.add("rest://127.0.0.1:30100?sslEnabled=true");
Map<String, List<String>> zoneAndRegion = new HashMap<>();
zoneAndRegion.put("sameZone", addressAZ);
zoneAndRegion.put("sameRegion", new ArrayList<>());
RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "CseConfigCenter");
AddressManager addressManager = new AddressManager("test", addresses, EventManager.getEventBus());
addressManager.onRefreshEndpointEvent(event);
List<String> availableAZ = Deencapsulation.getField(addressManager, "availableZone");
Assert.assertEquals("https://127.0.0.1:30100/v3/test", availableAZ.get(0));
}
use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project incubator-servicecomb-java-chassis by apache.
the class AbstractAddressManagerTest method recordStateTest.
@Test
public void recordStateTest() throws ExecutionException {
List<String> addressAZ = new ArrayList<>();
addressAZ.add("http://127.0.0.3:30100");
List<String> addressRG = new ArrayList<>();
addressRG.add("http://127.0.0.4:30100");
Map<String, List<String>> zoneAndRegion = new HashMap<>();
zoneAndRegion.put("sameZone", addressAZ);
zoneAndRegion.put("sameRegion", addressRG);
RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "TEST");
AbstractAddressManager addressManager = new AbstractAddressManager(addresses);
addressManager.refreshEndpoint(event, "TEST");
String address = "http://127.0.0.3:30100";
addressManager.recordFailState(address);
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
addressManager.recordFailState(address);
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
// test fail 2 times ,it will not be isolated
addressManager.recordSuccessState(address);
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
// test recodeStatus times
Map<String, Integer> recodeStatus = Deencapsulation.getField(addressManager, "recodeStatus");
Assert.assertEquals(0, (int) recodeStatus.get("http://127.0.0.3:30100"));
// test fail 3 times ,it will be isolated
addressManager.recordFailState(address);
addressManager.recordFailState(address);
addressManager.recordFailState(address);
Assert.assertEquals("http://127.0.0.4:30100", addressManager.address());
// mock cacheAddress status refresh after 10 minute
Cache<String, Boolean> cache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(10, TimeUnit.MINUTES).build();
cache.put("http://127.0.0.3:30100", true);
// mock the address telnetTest is access
new Expectations(addressManager) {
{
Deencapsulation.setField(addressManager, "cacheAddress", cache);
Deencapsulation.invoke(addressManager, "telnetTest", "http://127.0.0.3:30100");
result = true;
}
};
Cache<String, Boolean> result = Deencapsulation.getField(addressManager, "cacheAddress");
Assert.assertEquals(true, result.get("http://127.0.0.3:30100", () -> false));
// test restore isolation
addressManager.checkHistory();
addressManager.rejoinAddress("http://127.0.0.3:30100");
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
Assert.assertEquals("http://127.0.0.3:30100", addressManager.address());
}
Aggregations