use of org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder in project carbon-apimgt by wso2.
the class ThrottleHandlerTest method testHandleResponse.
@Test
public void testHandleResponse() {
ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
ThrottleHandler throttleHandler = new ThrottlingHandlerWrapper(timer, throttleDataHolder, throttleEvaluator);
MessageContext messageContext = TestUtils.getMessageContextWithAuthContext(apiContext, apiVersion);
Assert.assertTrue(throttleHandler.handleResponse(messageContext));
}
use of org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder in project carbon-apimgt by wso2.
the class ThrottleHandlerTest method testSubscriptionLevelThrottlingInitialization.
@Test
public void testSubscriptionLevelThrottlingInitialization() {
ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
ThrottleHandler throttleHandler = new ThrottlingHandlerWrapper(timer, throttleDataHolder, throttleEvaluator);
MessageContext messageContext = TestUtils.getMessageContextWithAuthContext(apiContext, apiVersion);
messageContext.setProperty(RESPONSE, "true");
// Test subscription level throttle context initialisation when throttle holder is null
Assert.assertTrue(throttleHandler.handleRequest(messageContext));
// Test subscription level throttle context initialisation when throttle holder is already initialized by first
// request
Assert.assertTrue(throttleHandler.handleRequest(messageContext));
}
use of org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder in project carbon-apimgt by wso2.
the class ThrottleHandlerTest method testMsgDoThrottleWhenUserLevelThrottlingIsTriggerred.
@Test
public void testMsgDoThrottleWhenUserLevelThrottlingIsTriggerred() {
ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
ThrottleHandler throttleHandler = new ThrottlingHandlerWrapper(timer, throttleDataHolder, throttleEvaluator);
MessageContext messageContext = TestUtils.getMessageContextWithAuthContext(apiContext, apiVersion);
verbInfo.setApplicableLevel("userLevel");
messageContext.setProperty(VERB_INFO_DTO, verbInfoDTO);
((Axis2MessageContext) messageContext).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
AuthenticationContext authenticationContext = (AuthenticationContext) messageContext.getProperty(API_AUTH_CONTEXT);
authenticationContext.setApiTier(throttlingTier);
messageContext.setProperty(API_AUTH_CONTEXT, authenticationContext);
// Should continue the message flow, when user level throttling is triggered and not exceeded
Assert.assertTrue(throttleHandler.handleRequest(messageContext));
}
use of org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder in project carbon-apimgt by wso2.
the class ThrottleHandlerTest method testMsgContinueWhenSubscriptionLevelIsThrottledAndStopOnQuotaReachIsDisabled.
@Test
public void testMsgContinueWhenSubscriptionLevelIsThrottledAndStopOnQuotaReachIsDisabled() {
ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
ThrottleHandler throttleHandler = new ThrottlingHandlerWrapper(timer, throttleDataHolder, throttleEvaluator);
MessageContext messageContext = TestUtils.getMessageContextWithAuthContext(apiContext, apiVersion);
messageContext.setProperty(VERB_INFO_DTO, verbInfoDTO);
((Axis2MessageContext) messageContext).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
AuthenticationContext authenticationContext = (AuthenticationContext) messageContext.getProperty(API_AUTH_CONTEXT);
authenticationContext.setApiTier(throttlingTier);
// Set stopOnQuota
authenticationContext.setStopOnQuotaReach(false);
messageContext.setProperty(API_AUTH_CONTEXT, authenticationContext);
verbInfo.setConditionGroups(conditionGroupDTOs);
ArrayList<ConditionGroupDTO> matchingConditions = new ArrayList<>();
matchingConditions.add(conditionGroupDTO);
String subscriptionLevelThrottleKey = authenticationContext.getApplicationId() + ":" + apiContext + ":" + apiVersion;
// Set subscription level throttled out
throttleDataHolder.addThrottleData(subscriptionLevelThrottleKey, System.currentTimeMillis() + 10000);
// Though subscription level is throttled out, should continue the message flow, if stop on quota reach is
// disabled
Assert.assertTrue(throttleHandler.handleRequest(messageContext));
}
use of org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder in project carbon-apimgt by wso2.
the class ThrottleHandlerTest method testMsgDoContinueWhenAllThrottlingLevelsAreNotThrolled.
@Test
public void testMsgDoContinueWhenAllThrottlingLevelsAreNotThrolled() {
ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
ServiceReferenceHolder.getInstance().setThrottleDataPublisher(new ThrottleDataPublisher());
ThrottleHandler throttleHandler = new ThrottlingHandlerWrapper(timer, throttleDataHolder, throttleEvaluator);
MessageContext messageContext = TestUtils.getMessageContextWithAuthContext(apiContext, apiVersion);
messageContext.setProperty(VERB_INFO_DTO, verbInfoDTO);
((Axis2MessageContext) messageContext).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
AuthenticationContext authenticationContext = (AuthenticationContext) messageContext.getProperty(API_AUTH_CONTEXT);
authenticationContext.setApiTier(throttlingTier);
messageContext.setProperty(API_AUTH_CONTEXT, authenticationContext);
// Should continue the message flow if API level, application level, resource level, subscription level,
// subscription spike level and hard throttling limit levels are not throttled
Assert.assertTrue(throttleHandler.handleRequest(messageContext));
}
Aggregations