use of org.apache.servicecomb.governance.marker.Matcher in project java-chassis by ServiceComb.
the class GovernancePropertiesTest method test_match_properties_successfully_loaded.
@Test
public void test_match_properties_successfully_loaded() {
Map<String, TrafficMarker> markers = matchProperties.getParsedEntity();
Assert.assertEquals(4, markers.size());
TrafficMarker demoRateLimiting = markers.get("demo-rateLimiting");
List<Matcher> matchers = demoRateLimiting.getMatches();
Assert.assertEquals(1, matchers.size());
Matcher matcher = matchers.get(0);
Assert.assertEquals("/hello", matcher.getApiPath().get("exact"));
TrafficMarker demoBulkhead = markers.get("demo-bulkhead");
matchers = demoBulkhead.getMatches();
Assert.assertEquals(2, matchers.size());
matcher = matchers.get(0);
Assert.assertEquals("/bulkhead", matcher.getApiPath().get("exact"));
Assert.assertEquals("matchPath", matcher.getName());
}
use of org.apache.servicecomb.governance.marker.Matcher in project java-chassis by ServiceComb.
the class GovernancePropertiesTest method test_match_properties_changed.
@Test
public void test_match_properties_changed() {
dynamicValues.put("servicecomb.matchGroup.demo-rateLimiting", "matches:\n" + " - apiPath:\n" + " exact: \"/hello2\"\n" + " name: match0");
dynamicValues.put("servicecomb.matchGroup.demo-rateLimiting2", "matches:\n" + " - apiPath:\n" + " exact: \"/hello2\"\n" + " name: match0");
GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
Map<String, TrafficMarker> markers = matchProperties.getParsedEntity();
Assert.assertEquals(5, markers.size());
TrafficMarker demoRateLimiting = markers.get("demo-rateLimiting");
List<Matcher> matchers = demoRateLimiting.getMatches();
Assert.assertEquals(1, matchers.size());
Matcher matcher = matchers.get(0);
Assert.assertEquals("/hello2", matcher.getApiPath().get("exact"));
demoRateLimiting = markers.get("demo-rateLimiting2");
matchers = demoRateLimiting.getMatches();
Assert.assertEquals(1, matchers.size());
matcher = matchers.get(0);
Assert.assertEquals("/hello2", matcher.getApiPath().get("exact"));
}
use of org.apache.servicecomb.governance.marker.Matcher in project incubator-servicecomb-java-chassis by apache.
the class GovernancePropertiesTest method test_match_properties_changed.
@Test
public void test_match_properties_changed() {
dynamicValues.put("servicecomb.matchGroup.demo-rateLimiting", "matches:\n" + " - apiPath:\n" + " exact: \"/hello2\"\n" + " name: match0");
dynamicValues.put("servicecomb.matchGroup.demo-rateLimiting2", "matches:\n" + " - apiPath:\n" + " exact: \"/hello2\"\n" + " name: match0");
GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
Map<String, TrafficMarker> markers = matchProperties.getParsedEntity();
Assert.assertEquals(5, markers.size());
TrafficMarker demoRateLimiting = markers.get("demo-rateLimiting");
List<Matcher> matchers = demoRateLimiting.getMatches();
Assert.assertEquals(1, matchers.size());
Matcher matcher = matchers.get(0);
Assert.assertEquals("/hello2", matcher.getApiPath().get("exact"));
demoRateLimiting = markers.get("demo-rateLimiting2");
matchers = demoRateLimiting.getMatches();
Assert.assertEquals(1, matchers.size());
matcher = matchers.get(0);
Assert.assertEquals("/hello2", matcher.getApiPath().get("exact"));
}
use of org.apache.servicecomb.governance.marker.Matcher in project incubator-servicecomb-java-chassis by apache.
the class OperatorTest method test_exact_api_path_match.
@Test
public void test_exact_api_path_match() {
GovernanceRequest request = new GovernanceRequest();
request.setUri("/bulkhead");
Matcher matcher = new Matcher();
RawOperator apiPath = new RawOperator();
apiPath.put("exact", "/bulkhead");
matcher.setApiPath(apiPath);
Assert.assertTrue(requestProcessor.match(request, matcher));
}
use of org.apache.servicecomb.governance.marker.Matcher in project incubator-servicecomb-java-chassis by apache.
the class OperatorTest method test_compare_header_not_match.
@Test
public void test_compare_header_not_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", ">1000");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertFalse(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", ">=1000");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertFalse(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", "<10");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertFalse(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", "<=10");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertFalse(requestProcessor.match(request, matcher));
header1 = new RawOperator();
header1.put("compare", "=200");
headers.put("header1", header1);
matcher.setHeaders(headers);
Assert.assertFalse(requestProcessor.match(request, matcher));
}
Aggregations