use of org.apache.servicecomb.governance.marker.GovernanceRequest in project incubator-servicecomb-java-chassis by apache.
the class OperatorTest method test_exact_api_path_not_match.
@Test
public void test_exact_api_path_not_match() {
GovernanceRequest request = new GovernanceRequest();
request.setUri("/bulkhead/");
Matcher matcher = new Matcher();
RawOperator apiPath = new RawOperator();
apiPath.put("exact", "/bulkhead");
matcher.setApiPath(apiPath);
Assert.assertFalse(requestProcessor.match(request, matcher));
request.setUri("/bulkhead");
request.setUri(null);
Assert.assertFalse(requestProcessor.match(request, matcher));
request.setUri("/bulkhead");
apiPath.clear();
matcher.setApiPath(apiPath);
Assert.assertFalse(requestProcessor.match(request, matcher));
}
use of org.apache.servicecomb.governance.marker.GovernanceRequest in project incubator-servicecomb-java-chassis by apache.
the class OperatorTest method test_exact_api_path_match_header_not_match.
@Test
public void test_exact_api_path_match_header_not_match() {
GovernanceRequest request = new GovernanceRequest();
request.setUri("/bulkhead");
request.setMethod("GET");
Map<String, String> reqHeaders = new HashMap<>();
reqHeaders.put("header1", "value2");
request.setHeaders(reqHeaders);
Matcher matcher = new Matcher();
RawOperator apiPath = new RawOperator();
apiPath.put("exact", "/bulkhead");
matcher.setApiPath(apiPath);
matcher.setMethod(Arrays.asList("GET"));
Map<String, RawOperator> headers = new HashMap<>();
RawOperator header1 = new RawOperator();
header1.put("exact", "value1");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertFalse(requestProcessor.match(request, matcher));
reqHeaders.clear();
request.setHeaders(reqHeaders);
Assert.assertFalse(requestProcessor.match(request, matcher));
}
use of org.apache.servicecomb.governance.marker.GovernanceRequest in project incubator-servicecomb-java-chassis by apache.
the class OperatorTest method test_suffix_api_path_not_match_null.
@Test
public void test_suffix_api_path_not_match_null() {
GovernanceRequest request = new GovernanceRequest();
request.setUri("/api/bulkhead");
Matcher matcher = new Matcher();
RawOperator apiPath = new RawOperator();
apiPath.put("suffix", null);
matcher.setApiPath(apiPath);
Assert.assertFalse(requestProcessor.match(request, matcher));
}
use of org.apache.servicecomb.governance.marker.GovernanceRequest in project incubator-servicecomb-java-chassis by apache.
the class FlowControlTest method test_rate_limiting_work.
@Test
public void test_rate_limiting_work() throws Throwable {
DecorateCheckedSupplier<Object> ds = Decorators.ofCheckedSupplier(() -> {
return "test";
});
GovernanceRequest request = new GovernanceRequest();
request.setUri("/hello");
RateLimiter rateLimiter = rateLimitingHandler.getActuator(request);
ds.withRateLimiter(rateLimiter);
Assert.assertEquals("test", ds.get());
// flow control
CountDownLatch cd = new CountDownLatch(10);
AtomicBoolean expected = new AtomicBoolean(false);
AtomicBoolean notExpected = new AtomicBoolean(false);
for (int i = 0; i < 10; i++) {
new Thread() {
public void run() {
try {
Object result = ds.get();
if (!"test".equals(result)) {
notExpected.set(true);
}
} catch (Throwable e) {
if (e instanceof RequestNotPermitted) {
expected.set(true);
} else {
notExpected.set(true);
}
}
cd.countDown();
}
}.start();
}
cd.await(1, TimeUnit.SECONDS);
Assert.assertTrue(expected.get());
Assert.assertFalse(notExpected.get());
}
use of org.apache.servicecomb.governance.marker.GovernanceRequest in project incubator-servicecomb-java-chassis by apache.
the class MatchType method createGovHttpRequest.
public static GovernanceRequest createGovHttpRequest(Invocation invocation) {
GovernanceRequest request = new GovernanceRequest();
if (MatchType.REST.equalsIgnoreCase(invocation.getOperationMeta().getConfig().getGovernanceMatchType())) {
if (invocation.isConsumer()) {
request.setUri(invocation.getSchemaMeta().getSwagger().getBasePath() + invocation.getOperationMeta().getOperationPath());
request.setMethod(invocation.getOperationMeta().getHttpMethod());
request.setHeaders(getHeaderMap(invocation, true));
return request;
}
request.setUri(invocation.getRequestEx().getRequestURI());
request.setMethod(invocation.getRequestEx().getMethod());
request.setHeaders(getHeaderMap(invocation, false));
return request;
}
if (invocation.isConsumer()) {
request.setUri(invocation.getOperationMeta().getMicroserviceQualifiedName());
} else {
request.setUri(invocation.getOperationMeta().getSchemaQualifiedName());
}
request.setMethod(invocation.getOperationMeta().getHttpMethod());
request.setHeaders(getHeaderMap(invocation, true));
return request;
}
Aggregations