Search in sources :

Example 1 with FaultToleranceSubscriber

use of com.alipay.sofa.rpc.event.FaultToleranceSubscriber in project sofa-rpc by sofastack.

the class FaultToleranceModule method install.

@Override
public void install() {
    subscriber = new FaultToleranceSubscriber();
    EventBus.register(ClientSyncReceiveEvent.class, subscriber);
    EventBus.register(ClientAsyncReceiveEvent.class, subscriber);
    EventBus.register(ProviderInfoRemoveEvent.class, subscriber);
    EventBus.register(ProviderInfoUpdateEvent.class, subscriber);
    EventBus.register(ProviderInfoUpdateAllEvent.class, subscriber);
    String regulatorAlias = RpcConfigs.getOrDefaultValue(RpcOptions.AFT_REGULATOR, "timeWindow");
    regulator = ExtensionLoaderFactory.getExtensionLoader(Regulator.class).getExtension(regulatorAlias);
    regulator.init();
}
Also used : FaultToleranceSubscriber(com.alipay.sofa.rpc.event.FaultToleranceSubscriber)

Example 2 with FaultToleranceSubscriber

use of com.alipay.sofa.rpc.event.FaultToleranceSubscriber 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);
}
Also used : ProviderInfoRemoveEvent(com.alipay.sofa.rpc.event.ProviderInfoRemoveEvent) SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) ProviderInfoUpdateEvent(com.alipay.sofa.rpc.event.ProviderInfoUpdateEvent) ProviderInfoUpdateAllEvent(com.alipay.sofa.rpc.event.ProviderInfoUpdateAllEvent) FaultToleranceSubscriber(com.alipay.sofa.rpc.event.FaultToleranceSubscriber) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) ClientSyncReceiveEvent(com.alipay.sofa.rpc.event.ClientSyncReceiveEvent) Test(org.junit.Test)

Example 3 with FaultToleranceSubscriber

use of com.alipay.sofa.rpc.event.FaultToleranceSubscriber in project sofa-rpc by sofastack.

the class FaultToleranceSubscriberTest method onEvent.

@Test
public void onEvent() throws Exception {
    ProviderInfo providerInfo = ProviderHelper.toProviderInfo("127.0.0.1");
    FaultToleranceSubscriber subscriber = new FaultToleranceSubscriber();
    subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo, new SofaRequest(), new SofaResponse(), null));
    InvocationStat stat = InvocationStatFactory.getInvocationStat(consumerConfig, providerInfo);
    Assert.assertNull(stat);
    FaultToleranceConfig config = new FaultToleranceConfig();
    config.setRegulationEffective(true);
    FaultToleranceConfigManager.putAppConfig(APP_NAME1, config);
    subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo, new SofaRequest(), new SofaResponse(), null));
    stat = InvocationStatFactory.getInvocationStat(consumerConfig, providerInfo);
    Assert.assertTrue(stat.getInvokeCount() == 1);
    subscriber.onEvent(new ClientAsyncReceiveEvent(consumerConfig, providerInfo, new SofaRequest(), new SofaResponse(), null));
    Assert.assertTrue(stat.getInvokeCount() == 2);
    subscriber.onEvent(new ClientSyncReceiveEvent(consumerConfig, providerInfo, new SofaRequest(), null, new SofaTimeOutException("")));
    Assert.assertTrue(stat.getExceptionCount() == 1);
    subscriber.onEvent(new ClientAsyncReceiveEvent(consumerConfig, providerInfo, new SofaRequest(), null, new SofaTimeOutException("")));
    Assert.assertTrue(stat.getExceptionCount() == 2);
    Assert.assertTrue(stat.getExceptionRate() == 0.5d);
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) ClientAsyncReceiveEvent(com.alipay.sofa.rpc.event.ClientAsyncReceiveEvent) FaultToleranceSubscriber(com.alipay.sofa.rpc.event.FaultToleranceSubscriber) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) ClientSyncReceiveEvent(com.alipay.sofa.rpc.event.ClientSyncReceiveEvent) Test(org.junit.Test)

Aggregations

FaultToleranceSubscriber (com.alipay.sofa.rpc.event.FaultToleranceSubscriber)3 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)2 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)2 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)2 ClientSyncReceiveEvent (com.alipay.sofa.rpc.event.ClientSyncReceiveEvent)2 Test (org.junit.Test)2 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)1 SofaTimeOutException (com.alipay.sofa.rpc.core.exception.SofaTimeOutException)1 ClientAsyncReceiveEvent (com.alipay.sofa.rpc.event.ClientAsyncReceiveEvent)1 ProviderInfoRemoveEvent (com.alipay.sofa.rpc.event.ProviderInfoRemoveEvent)1 ProviderInfoUpdateAllEvent (com.alipay.sofa.rpc.event.ProviderInfoUpdateAllEvent)1 ProviderInfoUpdateEvent (com.alipay.sofa.rpc.event.ProviderInfoUpdateEvent)1