use of com.alipay.sofa.rpc.event.ProviderInfoUpdateAllEvent in project sofa-rpc by sofastack.
the class FaultToleranceSubscriberTest method onProviderEvent.
@Test
public void onProviderEvent() {
FaultToleranceConfig config = new FaultToleranceConfig();
config.setRegulationEffective(true);
FaultToleranceConfigManager.putAppConfig(APP_NAME1, config);
ProviderInfo providerInfo1 = ProviderHelper.toProviderInfo("127.0.0.1");
ProviderInfo providerInfo2 = ProviderHelper.toProviderInfo("127.0.0.2");
ProviderInfo providerInfo3 = ProviderHelper.toProviderInfo("127.0.0.3");
ProviderInfo providerInfo4 = ProviderHelper.toProviderInfo("127.0.0.4");
ProviderInfo providerInfo5 = ProviderHelper.toProviderInfo("127.0.0.5");
FaultToleranceSubscriber subscriber = new FaultToleranceSubscriber();
subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo1, new SofaRequest(), new SofaResponse(), null));
subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo2, new SofaRequest(), new SofaResponse(), null));
subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo3, new SofaRequest(), new SofaResponse(), null));
subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo4, new SofaRequest(), new SofaResponse(), null));
Assert.assertTrue(InvocationStatFactory.ALL_STATS.size() == 4);
subscriber.onEvent(new ProviderInfoRemoveEvent(consumerConfig, new ProviderGroup("x", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1")))));
Assert.assertTrue(InvocationStatFactory.ALL_STATS.size() == 3);
subscriber.onEvent(new ProviderInfoUpdateEvent(consumerConfig, new ProviderGroup("x", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.2"), ProviderHelper.toProviderInfo("127.0.0.3"), ProviderHelper.toProviderInfo("127.0.0.4"))), new ProviderGroup("x", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.2"), ProviderHelper.toProviderInfo("127.0.0.4"), ProviderHelper.toProviderInfo("127.0.0.5")))));
Assert.assertTrue(InvocationStatFactory.ALL_STATS.size() == 2);
subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo5, new SofaRequest(), new SofaResponse(), null));
Assert.assertTrue(InvocationStatFactory.ALL_STATS.size() == 3);
subscriber.onEvent(new ProviderInfoUpdateAllEvent(consumerConfig, Arrays.asList(new ProviderGroup("x", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.2"), ProviderHelper.toProviderInfo("127.0.0.4"), ProviderHelper.toProviderInfo("127.0.0.5")))), Arrays.asList(new ProviderGroup("x", Arrays.asList(ProviderHelper.toProviderInfo("127.0.0.1"), ProviderHelper.toProviderInfo("127.0.0.4"))))));
Assert.assertTrue(InvocationStatFactory.ALL_STATS.size() == 1);
}
use of com.alipay.sofa.rpc.event.ProviderInfoUpdateAllEvent in project sofa-rpc by sofastack.
the class AbstractCluster method updateAllProviders.
@Override
public void updateAllProviders(List<ProviderGroup> providerGroups) {
List<ProviderGroup> oldProviderGroups = new ArrayList<ProviderGroup>(addressHolder.getProviderGroups());
int count = 0;
if (providerGroups != null) {
for (ProviderGroup providerGroup : providerGroups) {
checkProviderInfo(providerGroup);
count += providerGroup.size();
}
}
if (count == 0) {
Collection<ProviderInfo> currentProviderList = currentProviderList();
addressHolder.updateAllProviders(providerGroups);
if (CommonUtils.isNotEmpty(currentProviderList)) {
if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
LOGGER.warnWithApp(consumerConfig.getAppName(), "Provider list is emptied, may be all " + "providers has been closed, or this consumer has been add to blacklist");
closeTransports();
}
}
} else {
addressHolder.updateAllProviders(providerGroups);
connectionHolder.updateAllProviders(providerGroups);
}
if (EventBus.isEnable(ProviderInfoUpdateAllEvent.class)) {
ProviderInfoUpdateAllEvent event = new ProviderInfoUpdateAllEvent(consumerConfig, oldProviderGroups, providerGroups);
EventBus.post(event);
}
}
Aggregations