Search in sources :

Example 6 with SofaTimeOutException

use of com.alipay.sofa.rpc.core.exception.SofaTimeOutException in project sofa-rpc by sofastack.

the class InvocationStatDimensionStatTest method testInvocationStatStatic.

@Test
public void testInvocationStatStatic() {
    InvocationStatDimension invocation = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip"), consumerConfig);
    InvocationStat invocationStat = new ServiceExceptionInvocationStat(invocation);
    /**
     *test info static
     */
    for (int i = 0; i < 10; i++) {
        invocationStat.invoke();
    }
    for (int i = 0; i < 5; i++) {
        invocationStat.catchException(new SofaTimeOutException(""));
    }
    for (int i = 0; i < 3; i++) {
        invocationStat.catchException(new SofaRpcException(RpcErrorType.SERVER_BUSY, ""));
    }
    Assert.assertTrue(10 == invocationStat.getInvokeCount());
    Assert.assertTrue(8 == invocationStat.getExceptionCount());
    Assert.assertTrue(0.8 == invocationStat.getExceptionRate());
    /**
     *test window update
     */
    InvocationStat snapshot = invocationStat.snapshot();
    Assert.assertTrue(10 == snapshot.getInvokeCount());
    Assert.assertTrue(8 == snapshot.getExceptionCount());
    Assert.assertTrue(0.8 == snapshot.getExceptionRate());
    for (int i = 0; i < 15; i++) {
        invocationStat.invoke();
    }
    for (int i = 0; i < 8; i++) {
        invocationStat.catchException(new SofaTimeOutException(""));
    }
    for (int i = 0; i < 2; i++) {
        invocationStat.catchException(new SofaRpcException(RpcErrorType.SERVER_BUSY, ""));
    }
    Assert.assertTrue(25 == invocationStat.getInvokeCount());
    Assert.assertTrue(18 == invocationStat.getExceptionCount());
    Assert.assertTrue(0.72 == invocationStat.getExceptionRate());
    // 时间窗口更新
    invocationStat.update(snapshot);
    Assert.assertTrue(15 == invocationStat.getInvokeCount());
    Assert.assertTrue(10 == invocationStat.getExceptionCount());
    Assert.assertTrue(0.67 == invocationStat.getExceptionRate());
}
Also used : ServiceExceptionInvocationStat(com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat) ServiceExceptionInvocationStat(com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) Test(org.junit.Test)

Example 7 with SofaTimeOutException

use of com.alipay.sofa.rpc.core.exception.SofaTimeOutException in project sofa-rpc by sofastack.

the class MeasureStrategyTest method testAllNotReachLeastWindowCountIgnore.

@Test
public void testAllNotReachLeastWindowCountIgnore() {
    FaultToleranceConfig config = new FaultToleranceConfig();
    config.setLeastWindowCount(10);
    config.setLeastWindowExceptionRateMultiple(3D);
    FaultToleranceConfigManager.putAppConfig(APP_NAME1, config);
    InvocationStatDimension invocation1 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfig);
    InvocationStatDimension invocation2 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip2"), consumerConfig);
    InvocationStatDimension invocation3 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip3"), consumerConfig);
    InvocationStatDimension invocation4 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip4"), consumerConfig);
    InvocationStat InvocationStat1 = InvocationStatFactory.getInvocationStat(invocation1);
    InvocationStat InvocationStat2 = InvocationStatFactory.getInvocationStat(invocation2);
    InvocationStat InvocationStat3 = InvocationStatFactory.getInvocationStat(invocation3);
    InvocationStat InvocationStat4 = InvocationStatFactory.getInvocationStat(invocation4);
    MeasureModel measureModel = new MeasureModel(APP_NAME1, "service");
    measureModel.addInvocationStat(InvocationStat1);
    measureModel.addInvocationStat(InvocationStat2);
    measureModel.addInvocationStat(InvocationStat3);
    measureModel.addInvocationStat(InvocationStat4);
    /**
     *统计1-4都调用9次,异常5次
     */
    for (int i = 0; i < 9; i++) {
        InvocationStat1.invoke();
        InvocationStat2.invoke();
        InvocationStat3.invoke();
        InvocationStat4.invoke();
    }
    for (int i = 0; i < 5; i++) {
        InvocationStat1.catchException(new SofaTimeOutException(""));
        InvocationStat2.catchException(new SofaTimeOutException(""));
        InvocationStat3.catchException(new SofaRpcException(RpcErrorType.SERVER_BUSY, ""));
        InvocationStat4.catchException(new SofaRpcException(RpcErrorType.SERVER_BUSY, ""));
    }
    /**
     *度量
     */
    MeasureStrategy measureStrategy = new ServiceHorizontalMeasureStrategy();
    MeasureResult measureResult = measureStrategy.measure(measureModel);
    /**
     *校验结果
     */
    List<MeasureResultDetail> measureDetais = measureResult.getAllMeasureResultDetails();
    for (MeasureResultDetail measureResultDetail : measureDetais) {
        MeasureState measureState = measureResultDetail.getMeasureState();
        if (measureResultDetail.getInvocationStatDimension().equals(invocation1)) {
            Assert.assertTrue(measureState.equals(MeasureState.IGNORE));
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation2)) {
            Assert.assertTrue(measureState.equals(MeasureState.IGNORE));
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation3)) {
            Assert.assertTrue(measureState.equals(MeasureState.IGNORE));
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation4)) {
            Assert.assertTrue(measureState.equals(MeasureState.IGNORE));
        } else {
            Assert.fail("期望的度量目标与实际的度量结果目标不符");
        }
    }
}
Also used : ServiceExceptionInvocationStat(com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat) ServiceHorizontalMeasureStrategy(com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) ServiceHorizontalMeasureStrategy(com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) Test(org.junit.Test)

Example 8 with SofaTimeOutException

use of com.alipay.sofa.rpc.core.exception.SofaTimeOutException in project sofa-rpc by sofastack.

the class MeasureStrategyTest method testHealthAndAbnormalAndIgnore.

@Test
public void testHealthAndAbnormalAndIgnore() {
    FaultToleranceConfig config = new FaultToleranceConfig();
    config.setLeastWindowCount(10);
    config.setLeastWindowExceptionRateMultiple(3D);
    FaultToleranceConfigManager.putAppConfig(APP_NAME1, config);
    InvocationStatDimension invocation1 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfig);
    InvocationStatDimension invocation2 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip2"), consumerConfig);
    InvocationStatDimension invocation3 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip3"), consumerConfig);
    InvocationStatDimension invocation4 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip4"), consumerConfig);
    InvocationStatDimension invocation5 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip5"), consumerConfig);
    InvocationStatDimension invocation6 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip6"), consumerConfig);
    InvocationStat InvocationStat1 = InvocationStatFactory.getInvocationStat(invocation1);
    InvocationStat InvocationStat2 = InvocationStatFactory.getInvocationStat(invocation2);
    InvocationStat InvocationStat3 = InvocationStatFactory.getInvocationStat(invocation3);
    InvocationStat InvocationStat4 = InvocationStatFactory.getInvocationStat(invocation4);
    InvocationStat InvocationStat5 = InvocationStatFactory.getInvocationStat(invocation5);
    InvocationStat InvocationStat6 = InvocationStatFactory.getInvocationStat(invocation6);
    MeasureModel measureModel = new MeasureModel(APP_NAME1, "service");
    measureModel.addInvocationStat(InvocationStat1);
    measureModel.addInvocationStat(InvocationStat2);
    measureModel.addInvocationStat(InvocationStat3);
    measureModel.addInvocationStat(InvocationStat4);
    measureModel.addInvocationStat(InvocationStat5);
    measureModel.addInvocationStat(InvocationStat6);
    /**
     *统计6调用9次,异常9次
     */
    for (int i = 0; i < 10; i++) {
        InvocationStat1.invoke();
        InvocationStat2.invoke();
        InvocationStat3.invoke();
        InvocationStat4.invoke();
        InvocationStat5.invoke();
    }
    InvocationStat1.catchException(new SofaTimeOutException(""));
    InvocationStat2.catchException(new SofaTimeOutException(""));
    InvocationStat3.catchException(new SofaTimeOutException(""));
    InvocationStat4.catchException(new SofaTimeOutException(""));
    for (int i = 0; i < 6; i++) {
        InvocationStat5.catchException(new SofaTimeOutException(""));
    }
    for (int i = 0; i < 9; i++) {
        InvocationStat6.invoke();
        InvocationStat6.catchException(new SofaTimeOutException(""));
    }
    /**
     *度量
     */
    MeasureStrategy measureStrategy = new ServiceHorizontalMeasureStrategy();
    MeasureResult measureResult = measureStrategy.measure(measureModel);
    /**
     *校验结果
     */
    List<MeasureResultDetail> measureDetais = measureResult.getAllMeasureResultDetails();
    for (MeasureResultDetail measureResultDetail : measureDetais) {
        MeasureState measureState = measureResultDetail.getMeasureState();
        double abnormalRate = measureResultDetail.getAbnormalRate();
        double averageAbnormalRate = measureResultDetail.getAverageAbnormalRate();
        if (measureResultDetail.getInvocationStatDimension().equals(invocation1)) {
            Assert.assertTrue(measureState.equals(MeasureState.HEALTH));
            Assert.assertTrue(abnormalRate == 0.1);
            Assert.assertTrue(averageAbnormalRate == 0.2);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation2)) {
            Assert.assertTrue(measureState.equals(MeasureState.HEALTH));
            Assert.assertTrue(abnormalRate == 0.1);
            Assert.assertTrue(averageAbnormalRate == 0.2);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation3)) {
            Assert.assertTrue(measureState.equals(MeasureState.HEALTH));
            Assert.assertTrue(abnormalRate == 0.1);
            Assert.assertTrue(averageAbnormalRate == 0.2);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation4)) {
            Assert.assertTrue(measureState.equals(MeasureState.HEALTH));
            Assert.assertTrue(abnormalRate == 0.1);
            Assert.assertTrue(averageAbnormalRate == 0.2);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation5)) {
            Assert.assertTrue(measureState.equals(MeasureState.ABNORMAL));
            Assert.assertTrue(abnormalRate == 0.6);
            Assert.assertTrue(averageAbnormalRate == 0.2);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation6)) {
            Assert.assertTrue(measureState.equals(MeasureState.IGNORE));
        } else {
            Assert.fail("期望的度量目标与实际的度量结果目标不符");
        }
    }
}
Also used : ServiceExceptionInvocationStat(com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat) ServiceHorizontalMeasureStrategy(com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy) ServiceHorizontalMeasureStrategy(com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) Test(org.junit.Test)

Example 9 with SofaTimeOutException

use of com.alipay.sofa.rpc.core.exception.SofaTimeOutException in project sofa-rpc by sofastack.

the class MeasureStrategyTest method testLeastWindowCount.

@Test
public void testLeastWindowCount() {
    FaultToleranceConfig config = new FaultToleranceConfig();
    config.setLeastWindowCount(10);
    config.setLeastWindowExceptionRateMultiple(1.5D);
    FaultToleranceConfigManager.putAppConfig(APP_NAME1, config);
    ProviderInfo providerInfo4 = ProviderHelper.toProviderInfo("ip4");
    InvocationStatDimension invocation1 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfig);
    InvocationStatDimension invocation2 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip2"), consumerConfig);
    InvocationStatDimension invocation3 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip3"), consumerConfig);
    InvocationStatDimension invocation4 = new InvocationStatDimension(providerInfo4, consumerConfig);
    InvocationStat InvocationStat1 = InvocationStatFactory.getInvocationStat(invocation1);
    InvocationStat InvocationStat2 = InvocationStatFactory.getInvocationStat(invocation2);
    InvocationStat InvocationStat3 = InvocationStatFactory.getInvocationStat(invocation3);
    InvocationStat InvocationStat4 = InvocationStatFactory.getInvocationStat(invocation4);
    MeasureModel measureModel = new MeasureModel(APP_NAME1, "service");
    measureModel.addInvocationStat(InvocationStat1);
    measureModel.addInvocationStat(InvocationStat2);
    measureModel.addInvocationStat(InvocationStat3);
    measureModel.addInvocationStat(InvocationStat4);
    /**
     *统计4调用9次,异常9次
     */
    for (int i = 0; i < 10; i++) {
        InvocationStat1.invoke();
        InvocationStat2.invoke();
        InvocationStat3.invoke();
    }
    InvocationStat1.catchException(new SofaTimeOutException(""));
    InvocationStat2.catchException(new SofaTimeOutException(""));
    for (int i = 0; i < 8; i++) {
        InvocationStat3.catchException(new SofaTimeOutException(""));
    }
    for (int i = 0; i < 9; i++) {
        InvocationStat4.invoke();
        InvocationStat4.catchException(new SofaTimeOutException(""));
    }
    /**
     *度量
     */
    MeasureStrategy measureStrategy = new ServiceHorizontalMeasureStrategy();
    MeasureResult measureResult = measureStrategy.measure(measureModel);
    /**
     *校验结果
     */
    List<MeasureResultDetail> measureDetais = measureResult.getAllMeasureResultDetails();
    for (MeasureResultDetail measureResultDetail : measureDetais) {
        MeasureState measureState = measureResultDetail.getMeasureState();
        double abnormalRate = measureResultDetail.getAbnormalRate();
        double averageAbnormalRate = measureResultDetail.getAverageAbnormalRate();
        long leastWindowCount = measureResultDetail.getLeastWindowCount();
        long windowCount = measureResultDetail.getWindowCount();
        if (measureResultDetail.getInvocationStatDimension().equals(invocation1)) {
            Assert.assertTrue(measureState.equals(MeasureState.HEALTH));
            Assert.assertTrue(abnormalRate == 0.1);
            Assert.assertTrue(averageAbnormalRate == 0.33);
            Assert.assertTrue(leastWindowCount == 10);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation2)) {
            Assert.assertTrue(measureState.equals(MeasureState.HEALTH));
            Assert.assertTrue(abnormalRate == 0.1);
            Assert.assertTrue(averageAbnormalRate == 0.33);
            Assert.assertTrue(leastWindowCount == 10);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation3)) {
            Assert.assertTrue(measureState.equals(MeasureState.ABNORMAL));
            Assert.assertTrue(abnormalRate == 0.8);
            Assert.assertTrue(averageAbnormalRate == 0.33);
            Assert.assertTrue(leastWindowCount == 10);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation4)) {
            Assert.assertTrue(measureState.equals(MeasureState.IGNORE));
            Assert.assertTrue(windowCount == 9);
            Assert.assertTrue(leastWindowCount == 10);
        } else {
            Assert.fail("期望的度量目标与实际的度量结果目标不符");
        }
    }
    // 模拟4 被降级,统计次数也跟着变小
    /**
     *统计4权重降级
     */
    ProviderInfoWeightManager.degradeWeight(providerInfo4, 90);
    /**
     *统计4调用9次,异常9次
     */
    for (int i = 0; i < 10; i++) {
        InvocationStat1.invoke();
        InvocationStat2.invoke();
        InvocationStat3.invoke();
    }
    InvocationStat1.catchException(new SofaTimeOutException(""));
    InvocationStat2.catchException(new SofaTimeOutException(""));
    for (int i = 0; i < 8; i++) {
        InvocationStat3.catchException(new SofaTimeOutException(""));
    }
    for (int i = 0; i < 9; i++) {
        InvocationStat4.invoke();
        InvocationStat4.catchException(new SofaTimeOutException(""));
    }
    /**
     *度量
     */
    MeasureResult measureResult2 = measureStrategy.measure(measureModel);
    /**
     *校验结果
     */
    List<MeasureResultDetail> measureDetais2 = measureResult2.getAllMeasureResultDetails();
    for (MeasureResultDetail measureResultDetail : measureDetais2) {
        MeasureState measureState = measureResultDetail.getMeasureState();
        double abnormalRate = measureResultDetail.getAbnormalRate();
        double averageAbnormalRate = measureResultDetail.getAverageAbnormalRate();
        long leastWindowCount = measureResultDetail.getLeastWindowCount();
        long windowCount = measureResultDetail.getWindowCount();
        if (measureResultDetail.getInvocationStatDimension().equals(invocation1)) {
            Assert.assertEquals(measureState, MeasureState.HEALTH);
            Assert.assertEquals(abnormalRate, 0.1, 0);
            Assert.assertEquals(averageAbnormalRate, 0.49, 0);
            Assert.assertEquals(leastWindowCount, 10);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation2)) {
            Assert.assertEquals(measureState, MeasureState.HEALTH);
            Assert.assertEquals(abnormalRate, 0.1, 0);
            Assert.assertEquals(averageAbnormalRate, 0.49, 0);
            Assert.assertEquals(leastWindowCount, 10);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation3)) {
            Assert.assertEquals(measureState, MeasureState.ABNORMAL);
            Assert.assertEquals(abnormalRate, 0.8, 0);
            Assert.assertEquals(averageAbnormalRate, 0.49, 0);
            Assert.assertEquals(leastWindowCount, 10);
        } else if (measureResultDetail.getInvocationStatDimension().equals(invocation4)) {
            Assert.assertEquals(measureState, MeasureState.ABNORMAL);
            Assert.assertEquals(abnormalRate, 1, 0);
            Assert.assertEquals(averageAbnormalRate, 0.49, 0);
            Assert.assertTrue(leastWindowCount == 9);
            Assert.assertEquals(leastWindowCount, 9);
        } else {
            Assert.fail("期望的度量目标与实际的度量结果目标不符");
        }
    }
}
Also used : ServiceExceptionInvocationStat(com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat) ServiceHorizontalMeasureStrategy(com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy) ServiceHorizontalMeasureStrategy(com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) Test(org.junit.Test)

Example 10 with SofaTimeOutException

use of com.alipay.sofa.rpc.core.exception.SofaTimeOutException in project sofa-rpc by sofastack.

the class Http2ClearTextTimeoutTest method testProtobuf.

@Test
public void testProtobuf() throws InterruptedException {
    // 只有1个线程 执行
    ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(12300).setProtocol(RpcConstants.PROTOCOL_TYPE_H2C).setDaemon(true);
    // 发布一个服务,每个请求要执行1秒
    ProviderConfig<HttpService> providerConfig = new ProviderConfig<HttpService>().setInterfaceId(HttpService.class.getName()).setRef(new HttpServiceImpl(1000)).setApplication(new ApplicationConfig().setAppName("serverApp")).setServer(serverConfig).setRegister(false);
    providerConfig.export();
    {
        ConsumerConfig<HttpService> consumerConfig = new ConsumerConfig<HttpService>().setInterfaceId(HttpService.class.getName()).setSerialization(RpcConstants.SERIALIZE_PROTOBUF).setDirectUrl("h2c://127.0.0.1:12300").setApplication(new ApplicationConfig().setAppName("clientApp")).setTimeout(500).setProtocol(RpcConstants.PROTOCOL_TYPE_H2C);
        HttpService httpService = consumerConfig.refer();
        EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("xxx").build();
        try {
            EchoResponse response = httpService.echoPb(request);
            Assert.fail();
        } catch (Exception e) {
            Assert.assertTrue(e instanceof SofaTimeOutException);
        }
    }
    {
        ConsumerConfig<HttpService> consumerConfig2 = new ConsumerConfig<HttpService>().setInterfaceId(HttpService.class.getName()).setSerialization(RpcConstants.SERIALIZE_PROTOBUF).setDirectUrl("h2c://127.0.0.1:12300").setApplication(new ApplicationConfig().setAppName("clientApp")).setTimeout(500).setProtocol(RpcConstants.PROTOCOL_TYPE_H2C).setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY).setRepeatedReferLimit(-1);
        HttpService httpService2 = consumerConfig2.refer();
        EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("xxx").build();
        try {
            httpService2.echoPb(request);
            // NOT SUPPORTED NOW, If want support this, need add key to head.
            Assert.fail();
        } catch (Exception e) {
        }
    }
    {
        ConsumerConfig<HttpService> consumerConfig3 = new ConsumerConfig<HttpService>().setInterfaceId(HttpService.class.getName()).setSerialization(RpcConstants.SERIALIZE_PROTOBUF).setDirectUrl("h2c://127.0.0.1:12300").setApplication(new ApplicationConfig().setAppName("clientApp")).setTimeout(500).setProtocol(RpcConstants.PROTOCOL_TYPE_H2C).setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE).setRepeatedReferLimit(-1);
        HttpService httpService3 = consumerConfig3.refer();
        EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("xxx").build();
        EchoResponse response = httpService3.echoPb(request);
        Assert.assertNull(response);
        ResponseFuture future = RpcInvokeContext.getContext().getFuture();
        try {
            response = (EchoResponse) future.get();
            Assert.fail();
        } catch (Exception e) {
            Assert.assertTrue(e instanceof SofaTimeOutException);
        }
    }
    {
        final Object[] result = new Object[1];
        final CountDownLatch latch = new CountDownLatch(1);
        ConsumerConfig<HttpService> consumerConfig4 = new ConsumerConfig<HttpService>().setInterfaceId(HttpService.class.getName()).setSerialization(RpcConstants.SERIALIZE_PROTOBUF).setTimeout(500).setDirectUrl("h2c://127.0.0.1:12300").setApplication(new ApplicationConfig().setAppName("clientApp")).setProtocol(RpcConstants.PROTOCOL_TYPE_H2C).setInvokeType(RpcConstants.INVOKER_TYPE_CALLBACK).setOnReturn(new SofaResponseCallback() {

            @Override
            public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
                result[0] = appResponse;
                latch.countDown();
            }

            @Override
            public void onAppException(Throwable throwable, String methodName, RequestBase request) {
                result[0] = throwable;
                latch.countDown();
            }

            @Override
            public void onSofaException(SofaRpcException exception, String methodName, RequestBase request) {
                result[0] = exception;
                latch.countDown();
            }
        }).setRepeatedReferLimit(-1);
        HttpService httpService4 = consumerConfig4.refer();
        EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("xxx").build();
        EchoResponse response = httpService4.echoPb(request);
        Assert.assertNull(response);
        latch.await(2000, TimeUnit.MILLISECONDS);
        Throwable throwable = (Throwable) result[0];
        Assert.assertTrue(throwable instanceof SofaTimeOutException);
    }
}
Also used : EchoResponse(com.alipay.sofa.rpc.server.bolt.pb.EchoResponse) EchoRequest(com.alipay.sofa.rpc.server.bolt.pb.EchoRequest) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) ResponseFuture(com.alipay.sofa.rpc.message.ResponseFuture) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServiceImpl(com.alipay.sofa.rpc.server.http.HttpServiceImpl) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) HttpService(com.alipay.sofa.rpc.server.http.HttpService) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Aggregations

SofaTimeOutException (com.alipay.sofa.rpc.core.exception.SofaTimeOutException)14 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)10 Test (org.junit.Test)10 ServiceExceptionInvocationStat (com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat)4 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)4 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)4 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)4 InvokeTimeoutException (com.alipay.remoting.rpc.exception.InvokeTimeoutException)3 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)3 ServiceHorizontalMeasureStrategy (com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy)3 SofaResponseCallback (com.alipay.sofa.rpc.core.invoke.SofaResponseCallback)3 RequestBase (com.alipay.sofa.rpc.core.request.RequestBase)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ConnectionClosedException (com.alipay.remoting.exception.ConnectionClosedException)2 DeserializationException (com.alipay.remoting.exception.DeserializationException)2 SerializationException (com.alipay.remoting.exception.SerializationException)2 InvokeSendFailedException (com.alipay.remoting.rpc.exception.InvokeSendFailedException)2 InvokeServerBusyException (com.alipay.remoting.rpc.exception.InvokeServerBusyException)2 InvokeServerException (com.alipay.remoting.rpc.exception.InvokeServerException)2 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)2