use of org.apache.servicecomb.qps.strategy.FixedWindowStrategy in project java-chassis by ServiceComb.
the class TestConsumerQpsFlowControlHandler method testQpsController.
@Test
public void testQpsController() {
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 TestConsumerQpsFlowControlHandler method testHandle.
@Test
public void testHandle() throws Exception {
String key = "svc.schema.opr";
AbstractQpsStrategy qpsStrategy = new FixedWindowStrategy();
qpsStrategy.setKey("key");
qpsStrategy.setQpsLimit(12L);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(operationMeta.getSchemaQualifiedName()).thenReturn("schema.opr");
Mockito.when(invocation.getSchemaId()).thenReturn("schema");
Mockito.when(invocation.getMicroserviceName()).thenReturn("svc");
setQpsController(key, qpsStrategy);
new MockUp<FixedWindowStrategy>() {
@Mock
public boolean isLimitNewRequest() {
return true;
}
};
new MockUp<QpsControllerManager>() {
@Mock
protected QpsStrategy create(String qualifiedNameKey) {
return qpsStrategy;
}
};
handler.handle(invocation, asyncResp);
ArgumentCaptor<InvocationException> captor = ArgumentCaptor.forClass(InvocationException.class);
Mockito.verify(asyncResp).consumerFail(captor.capture());
InvocationException invocationException = captor.getValue();
assertEquals(QpsConst.TOO_MANY_REQUESTS_STATUS, invocationException.getStatus());
assertEquals("consumer request rejected by qps flowcontrol", ((CommonExceptionData) invocationException.getErrorData()).getMessage());
}
Aggregations