use of org.apache.servicecomb.governance.marker.GovernanceRequest in project incubator-servicecomb-java-chassis by apache.
the class OperatorTest method test_prefix_api_path_not_match_null.
@Test
public void test_prefix_api_path_not_match_null() {
GovernanceRequest request = new GovernanceRequest();
request.setUri("/bulkhead/hello");
Matcher matcher = new Matcher();
RawOperator apiPath = new RawOperator();
apiPath.put("prefix", 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 OperatorTest method test_unknown_operator.
@Test
public void test_unknown_operator() {
GovernanceRequest request = new GovernanceRequest();
request.setUri("/test");
Matcher matcher = new Matcher();
RawOperator apiPath = new RawOperator();
apiPath.put("unknown", "/test");
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_compare_header_match.
@Test
public void test_compare_header_match() {
GovernanceRequest request = new GovernanceRequest();
Map<String, String> reqHeaders = new HashMap<>();
reqHeaders.put("header1", "100");
request.setHeaders(reqHeaders);
Matcher matcher = new Matcher();
Map<String, RawOperator> headers = new HashMap<>();
RawOperator header1 = new RawOperator();
header1.put("compare", ">10");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertTrue(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", ">=10");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertTrue(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", "<1000");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertTrue(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", "<=1000");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertTrue(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", "=100");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertTrue(requestProcessor.match(request, matcher));
}
use of org.apache.servicecomb.governance.marker.GovernanceRequest in project incubator-servicecomb-java-chassis by apache.
the class InvokerUtils method invoke.
/**
* This method is used in new Filter implementation to replace Handler
* NOTE: this method should never throw exception directly
*/
public static CompletableFuture<Response> invoke(Invocation invocation) {
Supplier<CompletionStage<Response>> next = invokeImpl(invocation);
DecorateCompletionStage<Response> dcs = Decorators.ofCompletionStage(next);
GovernanceRequest request = MatchType.createGovHttpRequest(invocation);
try {
ServiceCombInvocationContext.setInvocationContext(invocation);
decorateReactiveRetry(invocation, dcs, request);
} finally {
ServiceCombInvocationContext.removeInvocationContext();
}
CompletableFuture<Response> result = new CompletableFuture<>();
dcs.get().whenComplete((r, e) -> {
if (e == null) {
result.complete(r);
return;
}
String message = String.format("invoke failed, operation %s, trace id %s", invocation.getMicroserviceQualifiedName(), invocation.getTraceId());
LOGGER.error(message, e);
Response response = Response.createConsumerFail(e, message);
invocation.onFinish(response);
result.complete(response);
});
return result;
}
Aggregations