use of com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testCircuitBreakerOpenToClose.
@Test
public void testCircuitBreakerOpenToClose() throws InterruptedException {
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.HALF_OPEN));
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.CLOSE));
// mock pushing
Thread.sleep(pushInterval + 1000);
handler.stopHandle();
DefaultCircuitBreakResult example = mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN);
Assert.assertEquals(new Double(0), getOpenResult(example));
Assert.assertEquals(new Double(0), getHalfOpenResult(example));
}
use of com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method mockFixedCircuitResult.
private DefaultCircuitBreakResult mockFixedCircuitResult(CircuitBreakerStatus.Status status) {
DefaultCircuitBreakResult circuitBreakResult = new DefaultCircuitBreakResult();
circuitBreakResult.setService("callService");
circuitBreakResult.setNamespace("callNamespace");
circuitBreakResult.setMethod("GET");
circuitBreakResult.setSubset("callSubset");
circuitBreakResult.setHost("callHost");
circuitBreakResult.setPort(8080);
circuitBreakResult.setInstanceId("callInstanceId");
circuitBreakResult.setCallerService(mockCallerService());
CircuitBreakerStatus circuitBreakerStatus = new CircuitBreakerStatus("mockCB", status, System.currentTimeMillis());
circuitBreakResult.setCircuitBreakStatus(circuitBreakerStatus);
return circuitBreakResult;
}
use of com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testCircuitBreakerOpenToHalf.
@Test
public void testCircuitBreakerOpenToHalf() throws InterruptedException {
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.HALF_OPEN));
// mock pushing
Thread.sleep(pushInterval + 1000);
handler.stopHandle();
DefaultCircuitBreakResult example = mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN);
Assert.assertEquals(new Double(0), getOpenResult(example));
Assert.assertEquals(new Double(1), getHalfOpenResult(example));
}
use of com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testCircuitBreakerCloseToOpen.
@Test
public void testCircuitBreakerCloseToOpen() throws InterruptedException {
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.HALF_OPEN));
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.CLOSE));
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
// mock pushing
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));
}
use of com.tencent.polaris.api.plugin.stat.DefaultCircuitBreakResult in project polaris-java by polarismesh.
the class PrometheusPushHandlerTest method testCircuitBreakerOpen.
@Test
public void testCircuitBreakerOpen() throws InterruptedException {
changeCircuitBreakerStatus(mockFixedCircuitResult(CircuitBreakerStatus.Status.OPEN));
// mock pushing
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));
}
Aggregations