use of com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat in project sofa-rpc by sofastack.
the class MeasureStrategyTest method testCreateMeasureModel.
@Test
public void testCreateMeasureModel() {
MeasureStrategy measureStrategy = new ServiceHorizontalMeasureStrategy();
InvocationStatDimension invocation1 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfig);
InvocationStat invocationStat1 = new ServiceExceptionInvocationStat(invocation1);
MeasureModel measureModel1 = measureStrategy.buildMeasureModel(invocationStat1);
Assert.assertTrue(measureModel1 != null);
/**
*同一应用,不同服务
*/
InvocationStatDimension invocation2 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfig2);
InvocationStat invocationStat2 = new ServiceExceptionInvocationStat(invocation2);
MeasureModel measureModel2 = measureStrategy.buildMeasureModel(invocationStat2);
Assert.assertTrue(measureModel2 != null);
/**
*不同应用,同一服务
*/
InvocationStatDimension invocation3 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfigAnotherApp);
InvocationStat invocationStat3 = new ServiceExceptionInvocationStat(invocation3);
MeasureModel measureModel3 = measureStrategy.buildMeasureModel(invocationStat3);
Assert.assertTrue(measureModel3 != null);
/**
*同一应用,同一服务,不同IP
*/
InvocationStatDimension invocation4 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip2"), consumerConfig);
InvocationStat invocationStat4 = new ServiceExceptionInvocationStat(invocation4);
MeasureModel measureModel4 = measureStrategy.buildMeasureModel(invocationStat4);
Assert.assertTrue(measureModel4 == null);
Assert.assertTrue(measureModel1.getInvocationStats().contains(invocationStat4));
/**
*同一应用,同一服务,相同IP
*/
InvocationStatDimension invocation5 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfig);
InvocationStat invocationStat5 = new ServiceExceptionInvocationStat(invocation5);
MeasureModel measureModel5 = measureStrategy.buildMeasureModel(invocationStat5);
Assert.assertTrue(measureModel5 == null);
Assert.assertTrue(measureModel1.getInvocationStats().contains(invocationStat1));
Assert.assertTrue(measureModel1.getInvocationStats().contains(invocationStat5));
}
use of com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat 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());
}
use of com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat in project sofa-rpc by sofastack.
the class MeasureStrategyTest method concurrentTestCreateMeasureModel.
@Test
public void concurrentTestCreateMeasureModel() throws InterruptedException {
final MeasureStrategy measureStrategy = new ServiceHorizontalMeasureStrategy();
final AtomicInteger isNullCount = new AtomicInteger(0);
final CountDownLatch countDownLatch = new CountDownLatch(20);
for (int i = 0; i < 20; i++) {
new Thread(new Runnable() {
@Override
public void run() {
InvocationStatDimension invocation1 = new InvocationStatDimension(ProviderHelper.toProviderInfo("ip1"), consumerConfig);
MeasureModel measureModel1 = measureStrategy.buildMeasureModel(new ServiceExceptionInvocationStat(invocation1));
if (measureModel1 == null) {
isNullCount.incrementAndGet();
}
countDownLatch.countDown();
}
}).start();
}
countDownLatch.await();
Assert.assertTrue(isNullCount.get() == 19);
}
use of com.alipay.sofa.rpc.client.aft.impl.ServiceExceptionInvocationStat in project sofa-rpc by sofastack.
the class InvocationStatFactory method getInvocationStat.
/**
* 根据Invocation获取InvocationStat
* 该Invocation对应的InvocationStat会在被第一次获取(也就是刚被创建的时候)时被放入到Regulation中进行能力的持续调控。
*
* @param statDimension InvocationStatDimension
* @return InvocationStat
*/
public static InvocationStat getInvocationStat(InvocationStatDimension statDimension) {
InvocationStat invocationStat = ALL_STATS.get(statDimension);
if (invocationStat == null) {
invocationStat = new ServiceExceptionInvocationStat(statDimension);
InvocationStat old = ALL_STATS.putIfAbsent(statDimension, invocationStat);
if (old != null) {
invocationStat = old;
}
for (InvocationStatListener listener : LISTENERS) {
listener.onAddInvocationStat(invocationStat);
}
}
return invocationStat;
}
Aggregations