@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);
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/FaultToleranceSubscriberTest.java