use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent in project java-chassis by ServiceComb.
the class ServiceCombConfigurationEventAdapter method onConfigurationChangedEvent.
@Subscribe
public void onConfigurationChangedEvent(RefreshGovernanceConfigurationEvent event) {
Set<String> changedKeys = new HashSet<>();
addMap(changedKeys, event.getEvent().getAdded());
addMap(changedKeys, event.getEvent().getDeleted());
addMap(changedKeys, event.getEvent().getChanged());
addMap(changedKeys, event.getEvent().getComplete());
GovernanceConfigurationChangedEvent newEvent = new GovernanceConfigurationChangedEvent(changedKeys);
GovernanceEventManager.post(newEvent);
}
use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent in project java-chassis by ServiceComb.
the class GovernancePropertiesTest method test_bulkhead_properties_changed.
@Test
public void test_bulkhead_properties_changed() {
dynamicValues.put("servicecomb.bulkhead.demo-bulkhead", "rules:\n" + "maxConcurrentCalls: 2\n" + "maxWaitDuration: 2000");
dynamicValues.put("servicecomb.bulkhead.bulkhead1", "rules:\n" + "maxConcurrentCalls: 3\n" + "maxWaitDuration: 3000");
GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
Map<String, BulkheadPolicy> policies = bulkheadProperties.getParsedEntity();
Assert.assertEquals(2, policies.size());
BulkheadPolicy policy = policies.get("demo-bulkhead");
Assert.assertEquals(2, policy.getMaxConcurrentCalls());
Assert.assertEquals(2000, Duration.parse(policy.getMaxWaitDuration()).toMillis());
policies = bulkheadProperties.getParsedEntity();
Assert.assertEquals(2, policies.size());
policy = policies.get("bulkhead1");
Assert.assertEquals(3, policy.getMaxConcurrentCalls());
Assert.assertEquals(3000, Duration.parse(policy.getMaxWaitDuration()).toMillis());
Assert.assertEquals("bulkhead1", policy.getName());
}
use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent 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.event.GovernanceConfigurationChangedEvent in project java-chassis by ServiceComb.
the class GovernancePropertiesTest method tearDown.
@After
public void tearDown() {
Set<String> keys = dynamicValues.keySet();
keys.forEach(k -> dynamicValues.put(k, null));
GovernanceEventManager.post(new GovernanceConfigurationChangedEvent(new HashSet<>(dynamicValues.keySet())));
}
use of org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent in project java-chassis by ServiceComb.
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());
}
Aggregations