Search in sources :

Example 16 with RefreshEndpointEvent

use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project incubator-servicecomb-java-chassis by apache.

the class AbstractAddressManagerTest method addressForAzAndRegionTest.

@Test
public void addressForAzAndRegionTest() {
    List<String> addressAZ = new ArrayList<>();
    addressAZ.add("rest://127.0.0.1:30100?sslEnabled=true");
    addressAZ.add("https://127.0.0.2:30100");
    List<String> addressRG = new ArrayList<>();
    addressRG.add("rest://127.0.0.3:30100?sslEnabled=true");
    addressRG.add("https://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");
    addressManager1.refreshEndpoint(event, "TEST");
    Assert.assertEquals("https://127.0.0.2:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.1:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.2:30100", addressManager1.address());
    addressManager1.removeAddress("https://127.0.0.2:30100");
    addressManager1.removeAddress("https://127.0.0.1:30100");
    Assert.assertEquals("https://127.0.0.3:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.4:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.3:30100", addressManager1.address());
    addressManager1.removeAddress("https://127.0.0.4:30100");
    addressManager1.removeAddress("https://127.0.0.3:30100");
    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());
}
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 17 with RefreshEndpointEvent

use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project incubator-servicecomb-java-chassis by apache.

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 18 with RefreshEndpointEvent

use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project incubator-servicecomb-java-chassis by apache.

the class AbstractAddressManagerTest method addressForOnlyRegionTest.

@Test
public void addressForOnlyRegionTest() {
    List<String> addressRG = new ArrayList<>();
    addressRG.add("rest://127.0.0.5:30100?sslEnabled=true");
    addressRG.add("rest://127.0.0.6:30100");
    addressRG.add("http://127.0.0.7:30100");
    addressRG.add("https://127.0.0.8:30100");
    Map<String, List<String>> zoneAndRegion = new HashMap<>();
    zoneAndRegion.put("sameZone", new ArrayList<>());
    zoneAndRegion.put("sameRegion", addressRG);
    RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "TEST");
    addressManager1.refreshEndpoint(event, "TEST");
    Assert.assertEquals("http://127.0.0.6:30100", addressManager1.address());
    Assert.assertEquals("http://127.0.0.7:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.8:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.5:30100", addressManager1.address());
    Assert.assertEquals("http://127.0.0.6:30100", addressManager1.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 19 with RefreshEndpointEvent

use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project incubator-servicecomb-java-chassis by apache.

the class AbstractAddressManagerTest method addressForOnlyAzTest.

@Test
public void addressForOnlyAzTest() {
    List<String> addressAZ = new ArrayList<>();
    addressAZ.add("http://127.0.0.1:30100");
    addressAZ.add("https://127.0.0.2:30100");
    addressAZ.add("rest://127.0.0.1:30100?sslEnabled=true");
    addressAZ.add("rest://127.0.0.2:30100?sslEnabled=false");
    Map<String, List<String>> zoneAndRegion = new HashMap<>();
    zoneAndRegion.put("sameZone", addressAZ);
    zoneAndRegion.put("sameRegion", new ArrayList<>());
    RefreshEndpointEvent event1 = new RefreshEndpointEvent(zoneAndRegion, "TEST");
    addressManager1.refreshEndpoint(event1, "TEST");
    Assert.assertEquals("https://127.0.0.2:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.1:30100", addressManager1.address());
    Assert.assertEquals("http://127.0.0.2:30100", addressManager1.address());
    Assert.assertEquals("http://127.0.0.1:30100", addressManager1.address());
    Assert.assertEquals("https://127.0.0.2:30100", addressManager1.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 20 with RefreshEndpointEvent

use of org.apache.servicecomb.http.client.event.RefreshEndpointEvent in project incubator-servicecomb-java-chassis by apache.

the class KieAddressManagerTest method onRefreshEndpointEvent.

@Test
public void onRefreshEndpointEvent() {
    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);
    addressManager1 = new KieAddressManager(addresses, new EventBus());
    RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "KIE");
    addressManager1.refreshEndpoint(event, "KIE");
    List<String> availableZone = Deencapsulation.getField(addressManager1, "availableZone");
    Assert.assertEquals("http://127.0.0.3:30100", availableZone.get(0));
    List<String> availableRegion = Deencapsulation.getField(addressManager1, "availableRegion");
    Assert.assertEquals("http://127.0.0.4:30100", availableRegion.get(0));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) List(java.util.List) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) 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