Search in sources :

Example 6 with DefaultCircuitBreakResult

use of com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult in project polaris-java by polarismesh.

the class InMemoryRegistry method convertToCircuitBreakGauge.

private CircuitBreakGauge convertToCircuitBreakGauge(Entry<StatusDimension, CircuitBreakerStatus> dimensionEntry, Instance instance) {
    DefaultCircuitBreakResult result = new DefaultCircuitBreakResult();
    result.setMethod(dimensionEntry.getKey().getMethod());
    result.setCallerService(dimensionEntry.getKey().getCallerService());
    result.setCircuitBreakStatus(dimensionEntry.getValue());
    result.setHost(instance.getHost());
    result.setPort(instance.getPort());
    result.setInstanceId(instance.getId());
    result.setService(instance.getService());
    result.setNamespace(instance.getNamespace());
    return result;
}
Also used : DefaultCircuitBreakResult(com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult)

Example 7 with DefaultCircuitBreakResult

use of com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult in project polaris-java by polarismesh.

the class PrometheusPushHandlerTest method testCircuitBreakerRepeatOpenToHalfOpen.

@Test
public void testCircuitBreakerRepeatOpenToHalfOpen() throws InterruptedException {
    changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
    changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.HALF_OPEN));
    changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
    changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.HALF_OPEN));
    changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
    Thread.sleep(pushInterval + 1000);
    handler.stopHandle();
    DefaultCircuitBreakResult example = mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN);
    Assert.assertEquals(new Double(1), getOpenResult(example));
    Assert.assertEquals(new Double(0), getHalfOpenResult(example));
}
Also used : DefaultCircuitBreakResult(com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult) Test(org.junit.Test)

Aggregations

DefaultCircuitBreakResult (com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult)7 Test (org.junit.Test)5 CircuitBreakerStatus (com.tencent.polaris.api.pojo.CircuitBreakerStatus)1