Search in sources :

Example 6 with TrafficMarker

use of org.apache.servicecomb.governance.marker.TrafficMarker 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"));
}
Also used : Matcher(org.apache.servicecomb.governance.marker.Matcher) GovernanceConfigurationChangedEvent(org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent) TrafficMarker(org.apache.servicecomb.governance.marker.TrafficMarker) Test(org.junit.Test)

Example 7 with TrafficMarker

use of org.apache.servicecomb.governance.marker.TrafficMarker 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"));
}
Also used : Matcher(org.apache.servicecomb.governance.marker.Matcher) GovernanceConfigurationChangedEvent(org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent) TrafficMarker(org.apache.servicecomb.governance.marker.TrafficMarker) Test(org.junit.Test)

Example 8 with TrafficMarker

use of org.apache.servicecomb.governance.marker.TrafficMarker in project incubator-servicecomb-java-chassis by apache.

the class MatchersServiceImpl method checkMatch.

@Override
public boolean checkMatch(GovernanceRequest governanceRequest, String key) {
    Map<String, TrafficMarker> parsedEntity = matchProperties.getParsedEntity();
    TrafficMarker trafficMarker = parsedEntity.get(key);
    if (trafficMarker == null) {
        return false;
    }
    return trafficMarker.checkMatch(governanceRequest, requestProcessor);
}
Also used : TrafficMarker(org.apache.servicecomb.governance.marker.TrafficMarker)

Aggregations

TrafficMarker (org.apache.servicecomb.governance.marker.TrafficMarker)8 Test (org.junit.Test)6 GovernanceConfigurationChangedEvent (org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent)4 Matcher (org.apache.servicecomb.governance.marker.Matcher)4