Search in sources :

Example 21 with RefreshEndpointEvent

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));
}
Also used : AddressManager(org.apache.servicecomb.config.center.client.AddressManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 22 with RefreshEndpointEvent

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 23 with RefreshEndpointEvent

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());
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 24 with RefreshEndpointEvent

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));
}
Also used : AddressManager(org.apache.servicecomb.config.center.client.AddressManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 25 with RefreshEndpointEvent

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());
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)27 List (java.util.List)27 RefreshEndpointEvent (org.apache.servicecomb.http.client.event.RefreshEndpointEvent)27 HashMap (java.util.HashMap)23 Test (org.junit.jupiter.api.Test)23 EventBus (com.google.common.eventbus.EventBus)10 Expectations (mockit.Expectations)2 AddressManager (org.apache.servicecomb.config.center.client.AddressManager)2 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)1