Search in sources :

Example 11 with GovernanceConfigurationChangedEvent

use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent in project java-chassis by ServiceComb.

the class GovernancePropertiesTest method test_circuit_breaker_properties_Of_type.

@Test
public void test_circuit_breaker_properties_Of_type() {
    dynamicValues.put("servicecomb.circuitBreaker.type1", "rules:\n" + "failureRateThreshold: 20\n" + "slowCallRateThreshold: 100");
    dynamicValues.put("servicecomb.circuitBreaker.type2", "rules:\n" + "failureRateThreshold: 20.33\n" + "slowCallRateThreshold: 0.01");
    GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
    Map<String, CircuitBreakerPolicy> policies = circuitBreakerProperties.getParsedEntity();
    CircuitBreakerPolicy policy = policies.get("type1");
    Assert.assertEquals(20.0f, policy.getFailureRateThreshold(), DELTA);
    Assert.assertEquals(100.0f, policy.getSlowCallRateThreshold(), DELTA);
    policy = policies.get("type2");
    Assert.assertEquals(20.33f, policy.getFailureRateThreshold(), DELTA);
    Assert.assertEquals(0.01f, policy.getSlowCallRateThreshold(), DELTA);
}
Also used : GovernanceConfigurationChangedEvent(org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent) Test(org.junit.Test)

Example 12 with GovernanceConfigurationChangedEvent

use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent in project incubator-servicecomb-java-chassis by apache.

the class GovernancePropertiesTest method test_circuit_breaker_properties_Of_windows_size.

@Test
public void test_circuit_breaker_properties_Of_windows_size() {
    dynamicValues.put("servicecomb.circuitBreaker.name1", "rules:\n" + "slidingWindowType: count\n" + "slidingWindowSize: 2");
    dynamicValues.put("servicecomb.circuitBreaker.name2", "rules:\n" + "slidingWindowType: time\n" + "slidingWindowSize: 2");
    dynamicValues.put("servicecomb.circuitBreaker.name3", "rules:\n" + "slidingWindowType: test\n" + "slidingWindowSize: 1M");
    GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
    Map<String, CircuitBreakerPolicy> policies = circuitBreakerProperties.getParsedEntity();
    Assert.assertEquals(4, policies.size());
    CircuitBreakerPolicy policy = policies.get("name1");
    Assert.assertEquals("count", policy.getSlidingWindowType());
    Assert.assertEquals("2", policy.getSlidingWindowSize());
    policy = policies.get("name2");
    Assert.assertEquals("time", policy.getSlidingWindowType());
    Assert.assertEquals("2", policy.getSlidingWindowSize());
    policy = policies.get("name3");
    Assert.assertEquals("60", policy.getSlidingWindowSize());
}
Also used : GovernanceConfigurationChangedEvent(org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent) Test(org.junit.Test)

Example 13 with GovernanceConfigurationChangedEvent

use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent in project incubator-servicecomb-java-chassis by apache.

the class GovernancePropertiesTest method test_properties_changed_to_duration.

@Test
public void test_properties_changed_to_duration() {
    dynamicValues.put("servicecomb.bulkhead.test1", "rules:\n" + "maxConcurrentCalls: 2\n" + "maxWaitDuration: 2S");
    dynamicValues.put("servicecomb.bulkhead.test2", "rules:\n" + "maxConcurrentCalls: 3\n" + "maxWaitDuration: 1M");
    GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
    Map<String, BulkheadPolicy> policies = bulkheadProperties.getParsedEntity();
    Assert.assertEquals(3, policies.size());
    BulkheadPolicy policy = policies.get("test1");
    Assert.assertEquals(2000, Duration.parse(policy.getMaxWaitDuration()).toMillis());
    policies = bulkheadProperties.getParsedEntity();
    Assert.assertEquals(3, policies.size());
    policy = policies.get("test2");
    Assert.assertEquals(60000, Duration.parse(policy.getMaxWaitDuration()).toMillis());
}
Also used : GovernanceConfigurationChangedEvent(org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent) Test(org.junit.Test)

Example 14 with GovernanceConfigurationChangedEvent

use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent in project incubator-servicecomb-java-chassis by apache.

the class GovernancePropertiesTest method test_circuit_breaker_properties_Of_type.

@Test
public void test_circuit_breaker_properties_Of_type() {
    dynamicValues.put("servicecomb.circuitBreaker.type1", "rules:\n" + "failureRateThreshold: 20\n" + "slowCallRateThreshold: 100");
    dynamicValues.put("servicecomb.circuitBreaker.type2", "rules:\n" + "failureRateThreshold: 20.33\n" + "slowCallRateThreshold: 0.01");
    GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
    Map<String, CircuitBreakerPolicy> policies = circuitBreakerProperties.getParsedEntity();
    CircuitBreakerPolicy policy = policies.get("type1");
    Assert.assertEquals(20.0f, policy.getFailureRateThreshold(), DELTA);
    Assert.assertEquals(100.0f, policy.getSlowCallRateThreshold(), DELTA);
    policy = policies.get("type2");
    Assert.assertEquals(20.33f, policy.getFailureRateThreshold(), DELTA);
    Assert.assertEquals(0.01f, policy.getSlowCallRateThreshold(), DELTA);
}
Also used : GovernanceConfigurationChangedEvent(org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent) Test(org.junit.Test)

Example 15 with GovernanceConfigurationChangedEvent

use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent 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)

Aggregations

GovernanceConfigurationChangedEvent (org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent)18 Test (org.junit.Test)14 TrafficMarker (org.apache.servicecomb.governance.marker.TrafficMarker)4 Subscribe (com.google.common.eventbus.Subscribe)2 HashSet (java.util.HashSet)2 Matcher (org.apache.servicecomb.governance.marker.Matcher)2 After (org.junit.After)2