use of org.apache.servicecomb.qps.strategy.FixedWindowStrategy in project java-chassis by ServiceComb.
the class TestConsumerQpsFlowControlHandler method testHandleIsLimitNewRequestAsFalse.
@Test
public void testHandleIsLimitNewRequestAsFalse() throws Exception {
String key = "service.schema.id";
AbstractQpsStrategy qpsStrategy = new FixedWindowStrategy();
qpsStrategy.setKey("service");
qpsStrategy.setQpsLimit(12L);
Mockito.when(invocation.getMicroserviceName()).thenReturn("service");
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(operationMeta.getSchemaQualifiedName()).thenReturn("schema.id");
setQpsController(key, qpsStrategy);
new MockUp<QpsStrategy>() {
@Mock
public boolean isLimitNewRequest() {
return false;
}
};
new MockUp<QpsControllerManager>() {
@Mock
protected QpsStrategy create(String qualifiedNameKey) {
return qpsStrategy;
}
};
handler.handle(invocation, asyncResp);
Mockito.verify(invocation).next(asyncResp);
}
use of org.apache.servicecomb.qps.strategy.FixedWindowStrategy in project java-chassis by ServiceComb.
the class TestQpsStrategy method testFixedWindowStrategy.
@Test
public void testFixedWindowStrategy() {
AbstractQpsStrategy qpsStrategy = new FixedWindowStrategy();
qpsStrategy.setKey("abc");
qpsStrategy.setQpsLimit(100L);
Assert.assertEquals(false, qpsStrategy.isLimitNewRequest());
qpsStrategy.setQpsLimit(1L);
Assert.assertEquals(true, qpsStrategy.isLimitNewRequest());
}
use of org.apache.servicecomb.qps.strategy.FixedWindowStrategy in project java-chassis by ServiceComb.
the class TestProviderQpsFlowControlHandler method testQpsController.
@Test
public void testQpsController() {
AbstractQpsStrategy qpsStrategy = new FixedWindowStrategy();
qpsStrategy.setKey("abc");
qpsStrategy.setQpsLimit(100L);
assertFalse(qpsStrategy.isLimitNewRequest());
qpsStrategy.setQpsLimit(1L);
assertTrue(qpsStrategy.isLimitNewRequest());
}
use of org.apache.servicecomb.qps.strategy.FixedWindowStrategy in project java-chassis by ServiceComb.
the class TestProviderQpsFlowControlHandler method testHandle.
@Test
public void testHandle() throws Exception {
Mockito.when(invocation.getContext(Const.SRC_MICROSERVICE)).thenReturn("test");
OperationMeta mockOperationMeta = QpsControllerManagerTest.getMockOperationMeta("pojo", "server", "opr");
Mockito.when(invocation.getOperationMeta()).thenReturn(mockOperationMeta);
Mockito.when(invocation.getSchemaId()).thenReturn("server");
new MockUp<QpsControllerManager>() {
@Mock
protected QpsStrategy create(String qualifiedNameKey) {
AbstractQpsStrategy strategy = new FixedWindowStrategy();
strategy.setKey(qualifiedNameKey);
strategy.setQpsLimit(1L);
return strategy;
}
};
handler.handle(invocation, asyncResp);
handler.handle(invocation, asyncResp);
ArgumentCaptor<InvocationException> captor = ArgumentCaptor.forClass(InvocationException.class);
Mockito.verify(asyncResp, times(1)).producerFail(captor.capture());
InvocationException invocationException = captor.getValue();
assertEquals(QpsConst.TOO_MANY_REQUESTS_STATUS, invocationException.getStatus());
assertEquals("provider request rejected by qps flowcontrol", ((CommonExceptionData) invocationException.getErrorData()).getMessage());
}
use of org.apache.servicecomb.qps.strategy.FixedWindowStrategy in project java-chassis by ServiceComb.
the class TestProviderQpsFlowControlHandler method testHandleIsLimitNewRequestAsFalse.
@Test
public void testHandleIsLimitNewRequestAsFalse() throws Exception {
Mockito.when(invocation.getContext(Const.SRC_MICROSERVICE)).thenReturn("test");
OperationMeta mockOperationMeta = QpsControllerManagerTest.getMockOperationMeta("pojo", "server", "opr");
Mockito.when(invocation.getOperationMeta()).thenReturn(mockOperationMeta);
Mockito.when(invocation.getSchemaId()).thenReturn("server");
new MockUp<QpsControllerManager>() {
@Mock
protected QpsStrategy create(String qualifiedNameKey) {
AbstractQpsStrategy strategy = new FixedWindowStrategy();
strategy.setKey(qualifiedNameKey);
strategy.setQpsLimit(1L);
return strategy;
}
};
handler.handle(invocation, asyncResp);
Mockito.verify(invocation, times(0)).next(asyncResp);
Mockito.verify(asyncResp, times(0)).producerFail(Mockito.any(Exception.class));
}
Aggregations