use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method changeCircuitBreakerStatus.
private void changeCircuitBreakerStatus(DefaultCircuitBreakResult toStatus) {
StatInfo statInfo = new StatInfo();
statInfo.setCircuitBreakGauge(toStatus);
handler.handle(statInfo);
}
use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testRateLimitStrategy.
@Test
public void testRateLimitStrategy() throws InterruptedException {
int count = 10;
int passedNum = 3;
CountDownLatch latch = new CountDownLatch(2);
new Thread(() -> {
try {
batchDone(() -> {
StatInfo statInfo = new StatInfo();
DefaultRateLimitResult rateLimitResult = mockFixedRateLimitResult(RateLimitGauge.Result.PASSED);
statInfo.setRateLimitGauge(rateLimitResult);
handler.handle(statInfo);
}, passedNum);
} catch (InterruptedException e) {
e.printStackTrace();
}
latch.countDown();
}).start();
new Thread(() -> {
try {
batchDone(() -> {
StatInfo statInfo = new StatInfo();
DefaultRateLimitResult rateLimitResult = mockFixedRateLimitResult(RateLimitGauge.Result.LIMITED);
statInfo.setRateLimitGauge(rateLimitResult);
handler.handle(statInfo);
}, count - passedNum);
} catch (InterruptedException e) {
e.printStackTrace();
}
latch.countDown();
}).start();
latch.await();
Thread.sleep(pushInterval + 1000);
handler.stopHandle();
DefaultRateLimitResult example = mockFixedRateLimitResult(RateLimitGauge.Result.LIMITED);
// assert result
Double totalResult = getRateLimitTotalResult(example);
Double passResult = getRateLimitPassedResult(example);
Double limitResult = getRateLimitLimitedResult(example);
Assert.assertEquals(new Double(count), totalResult);
Assert.assertEquals(new Double(passedNum), passResult);
Assert.assertEquals(new Double(count - passedNum), limitResult);
}
use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testExpiredDataClean.
@Test
public void testExpiredDataClean() throws InterruptedException {
int count = 5;
StatInfo statInfo = new StatInfo();
ServiceCallResult callResult = mockServiceCallResult();
statInfo.setRouterGauge(callResult);
batchDone(() -> handler.handle(statInfo), count);
// mock push
LOG.info("first mock push finish...");
Thread.sleep(pushInterval + 1000);
Double result = getServiceCallTotalResult(callResult);
Assert.assertEquals(new Double(count), result);
// mock next push
LOG.info("second mock push finish...");
Thread.sleep(pushInterval + 1000);
result = getServiceCallTotalResult(callResult);
Assert.assertEquals(new Double(0), result);
LOG.info("mock sleep {} times end...", REVISION_MAX_SCOPE);
Thread.sleep(pushInterval * REVISION_MAX_SCOPE + 1000);
result = getServiceCallTotalResult(callResult);
Assert.assertNull(result);
// stop handle
handler.stopHandle();
}
use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testPushNullStatInfo.
@Test
public void testPushNullStatInfo() throws InterruptedException {
StatInfo statInfo = new StatInfo();
handler.handle(statInfo);
handler.handle(null);
Thread.sleep(pushInterval + 1000);
handler.stopHandle();
}
use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testServiceCallTotalStrategy.
@Test
public void testServiceCallTotalStrategy() throws InterruptedException {
StatInfo statInfo = new StatInfo();
ServiceCallResult callResult = mockServiceCallResult();
statInfo.setRouterGauge(callResult);
int count = 10;
batchDone(() -> handler.handle(statInfo), count);
// mock pushing
Thread.sleep(pushInterval + 1000);
handler.stopHandle();
Double result = getServiceCallTotalResult(callResult);
Assert.assertEquals(new Double(count), result);
}
Aggregations