Search in sources :

Example 1 with DefaultCircuitBreakResult

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

Example 2 with DefaultCircuitBreakResult

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

Example 3 with DefaultCircuitBreakResult

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

Example 4 with DefaultCircuitBreakResult

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

Example 5 with DefaultCircuitBreakResult

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));
}
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