Search in sources :

Example 6 with RefreshEndpointEvent

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

the class AddressManagerTest 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 AddressManager(addresses, new EventBus());
    RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "CseMonitoring");
    addressManager1.refreshEndpoint(event, "CseMonitoring");
    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)

Example 7 with RefreshEndpointEvent

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

the class ClassificationAddress method refreshEndPoints.

private void refreshEndPoints(MicroserviceCache microserviceCache, String name) {
    Map<String, List<String>> zoneAndRegion = refreshEndPoint(microserviceCache);
    EventManager.post(new RefreshEndpointEvent(zoneAndRegion, name));
}
Also used : RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with RefreshEndpointEvent

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

the class ClassificationAddress method initEndPoint.

public void initEndPoint(String typeName) {
    Map<String, List<String>> zoneAndRegion = generateZoneAndRegionAddress(typeName);
    if (zoneAndRegion == null) {
        return;
    }
    EventManager.post(new RefreshEndpointEvent(zoneAndRegion, typeName));
}
Also used : RefreshEndpointEvent(org.apache.servicecomb.http.client.event.RefreshEndpointEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with RefreshEndpointEvent

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

the class AddressManagerTest 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 AddressManager("project", addresses, new EventBus());
    RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "CseConfigCenter");
    addressManager1.refreshEndpoint(event, "CseConfigCenter");
    List<String> availableZone = Deencapsulation.getField(addressManager1, "availableZone");
    Assert.assertEquals("http://127.0.0.3:30100/v3/project", availableZone.get(0));
    List<String> availableRegion = Deencapsulation.getField(addressManager1, "availableRegion");
    Assert.assertEquals("http://127.0.0.4:30100/v3/project", availableRegion.get(0));
    Assert.assertEquals("http://127.0.0.3:30100/v3/project", addressManager1.address());
}
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)

Example 10 with RefreshEndpointEvent

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

the class AddressManagerTest 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("https://127.0.0.4:30100");
    Map<String, List<String>> zoneAndRegion = new HashMap<>();
    zoneAndRegion.put("sameZone", addressAZ);
    zoneAndRegion.put("sameRegion", addressRG);
    addressManager1 = new AddressManager(addresses, new EventBus());
    RefreshEndpointEvent event = new RefreshEndpointEvent(zoneAndRegion, "SERVICECENTER");
    addressManager1.refreshEndpoint(event, "SERVICECENTER");
    List<String> availableZone = Deencapsulation.getField(addressManager1, "availableZone");
    Assert.assertEquals("127.0.0.3:30100", availableZone.get(0));
    List<String> availableRegion = Deencapsulation.getField(addressManager1, "availableRegion");
    Assert.assertEquals("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