Search in sources :

Example 26 with Matcher

use of org.apache.servicecomb.governance.marker.Matcher 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));
}
Also used : GovernanceRequest(org.apache.servicecomb.governance.marker.GovernanceRequest) Matcher(org.apache.servicecomb.governance.marker.Matcher) RawOperator(org.apache.servicecomb.governance.marker.operator.RawOperator) Test(org.junit.Test)

Example 27 with Matcher

use of org.apache.servicecomb.governance.marker.Matcher 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));
}
Also used : GovernanceRequest(org.apache.servicecomb.governance.marker.GovernanceRequest) Matcher(org.apache.servicecomb.governance.marker.Matcher) RawOperator(org.apache.servicecomb.governance.marker.operator.RawOperator) Test(org.junit.Test)

Example 28 with Matcher

use of org.apache.servicecomb.governance.marker.Matcher 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));
}
Also used : GovernanceRequest(org.apache.servicecomb.governance.marker.GovernanceRequest) HashMap(java.util.HashMap) Matcher(org.apache.servicecomb.governance.marker.Matcher) RawOperator(org.apache.servicecomb.governance.marker.operator.RawOperator) Test(org.junit.Test)

Aggregations

Matcher (org.apache.servicecomb.governance.marker.Matcher)28 Test (org.junit.Test)28 GovernanceRequest (org.apache.servicecomb.governance.marker.GovernanceRequest)24 RawOperator (org.apache.servicecomb.governance.marker.operator.RawOperator)24 HashMap (java.util.HashMap)10 TrafficMarker (org.apache.servicecomb.governance.marker.TrafficMarker)4 GovernanceConfigurationChangedEvent (org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent)2