Search in sources :

Example 1 with StatInfo

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);
}
Also used : StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo)

Example 2 with 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);
}
Also used : DefaultRateLimitResult(com.tencent.polaris.api.plugin.stat.DefaultRateLimitResult) CountDownLatch(java.util.concurrent.CountDownLatch) StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) Test(org.junit.Test)

Example 3 with StatInfo

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();
}
Also used : ServiceCallResult(com.tencent.polaris.api.rpc.ServiceCallResult) StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) Test(org.junit.Test)

Example 4 with StatInfo

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();
}
Also used : StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) Test(org.junit.Test)

Example 5 with StatInfo

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);
}
Also used : ServiceCallResult(com.tencent.polaris.api.rpc.ServiceCallResult) StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) Test(org.junit.Test)

Aggregations

StatInfo (com.tencent.polaris.api.plugin.stat.StatInfo)11 Test (org.junit.Test)7 ServiceCallResult (com.tencent.polaris.api.rpc.ServiceCallResult)4 PolarisException (com.tencent.polaris.api.exception.PolarisException)2 Plugin (com.tencent.polaris.api.plugin.Plugin)2 DefaultRateLimitResult (com.tencent.polaris.api.plugin.stat.DefaultRateLimitResult)2 StatReporter (com.tencent.polaris.api.plugin.stat.StatReporter)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 IOException (java.io.IOException)1