use of org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager in project gateleen by swisspush.
the class QueueCircuitBreakerConfigurationResourceManagerTest method testInvalidContentShouldNotBeStoredInStorage.
@Test
public void testInvalidContentShouldNotBeStoredInStorage(TestContext context) {
Async async = context.async();
QueueCircuitBreakerConfigurationResourceManager manager = new QueueCircuitBreakerConfigurationResourceManager(vertx, storage, CONFIGURATION_URI);
final DummyHttpServerResponse response = new DummyHttpServerResponse();
class UpdateLoggingResourceWithValidDataRequest extends ConfigResourcePUTRequest {
@Override
public HttpServerRequest bodyHandler(Handler<Buffer> bodyHandler) {
bodyHandler.handle(Buffer.buffer(INVALID_CONFIG_RESOURCE));
return this;
}
@Override
public HttpServerResponse response() {
return response;
}
}
storage.get(CONFIGURATION_URI, result -> {
context.assertEquals(INITIAL_CONFIG_RESOURCE, result.toString());
context.assertTrue(manager.handleConfigurationResource(new UpdateLoggingResourceWithValidDataRequest()));
storage.get(CONFIGURATION_URI, updatedResult -> {
context.assertEquals(INITIAL_CONFIG_RESOURCE, updatedResult.toString(), "The configuration resource in the storage should still be equal to the initial resource");
context.assertEquals(StatusCode.BAD_REQUEST.getStatusCode(), response.getStatusCode());
async.complete();
});
});
}
use of org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager in project gateleen by swisspush.
the class QueueCircuitBreakerConfigurationResourceManagerTest method testConfigValuesShouldBeUpdatedInConfigurationResource.
@Test
public void testConfigValuesShouldBeUpdatedInConfigurationResource(TestContext context) {
QueueCircuitBreakerConfigurationResourceManager manager = new QueueCircuitBreakerConfigurationResourceManager(vertx, storage, CONFIGURATION_URI);
final DummyHttpServerResponse response = new DummyHttpServerResponse();
class UpdateConfigResourceWithValidDataRequest extends ConfigResourcePUTRequest {
@Override
public HttpServerRequest bodyHandler(Handler<Buffer> bodyHandler) {
bodyHandler.handle(Buffer.buffer(VALID_CONFIG_RESOURCE));
return this;
}
@Override
public HttpServerResponse response() {
return response;
}
}
QueueCircuitBreakerConfigurationResource config = manager.getConfigurationResource();
context.assertFalse(config.isCircuitCheckEnabled());
context.assertFalse(config.isStatisticsUpdateEnabled());
context.assertEquals(90, config.getErrorThresholdPercentage());
context.assertEquals(86400000, config.getEntriesMaxAgeMS());
context.assertEquals(100, config.getMinQueueSampleCount());
context.assertEquals(5000, config.getMaxQueueSampleCount());
context.assertFalse(config.isOpenToHalfOpenTaskEnabled());
context.assertEquals(30000, config.getOpenToHalfOpenTaskInterval());
context.assertFalse(config.isUnlockQueuesTaskEnabled());
context.assertEquals(20000, config.getUnlockQueuesTaskInterval());
context.assertFalse(config.isUnlockSampleQueuesTaskEnabled());
context.assertEquals(20000, config.getUnlockSampleQueuesTaskInterval());
context.assertTrue(manager.handleConfigurationResource(new UpdateConfigResourceWithValidDataRequest()));
context.assertTrue(config.isCircuitCheckEnabled());
context.assertTrue(config.isStatisticsUpdateEnabled());
context.assertEquals(99, config.getErrorThresholdPercentage());
context.assertEquals(43200000, config.getEntriesMaxAgeMS());
context.assertEquals(200, config.getMinQueueSampleCount());
context.assertEquals(2500, config.getMaxQueueSampleCount());
context.assertTrue(config.isOpenToHalfOpenTaskEnabled());
context.assertEquals(10000, config.getOpenToHalfOpenTaskInterval());
context.assertTrue(config.isUnlockQueuesTaskEnabled());
context.assertEquals(10000, config.getUnlockQueuesTaskInterval());
context.assertTrue(config.isUnlockSampleQueuesTaskEnabled());
context.assertEquals(10000, config.getUnlockSampleQueuesTaskInterval());
}
use of org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager in project gateleen by swisspush.
the class QueueCircuitBreakerConfigurationResourceManagerTest method testDefaultConfigValues.
@Test
public void testDefaultConfigValues(TestContext context) {
QueueCircuitBreakerConfigurationResourceManager manager = new QueueCircuitBreakerConfigurationResourceManager(vertx, new MockResourceStorage(), CONFIGURATION_URI);
QueueCircuitBreakerConfigurationResource config = manager.getConfigurationResource();
context.assertFalse(config.isCircuitCheckEnabled());
context.assertFalse(config.isStatisticsUpdateEnabled());
context.assertEquals(90, config.getErrorThresholdPercentage());
context.assertEquals(86400000, config.getEntriesMaxAgeMS());
context.assertEquals(100, config.getMinQueueSampleCount());
context.assertEquals(5000, config.getMaxQueueSampleCount());
context.assertFalse(config.isOpenToHalfOpenTaskEnabled());
context.assertEquals(120000, config.getOpenToHalfOpenTaskInterval());
context.assertFalse(config.isUnlockQueuesTaskEnabled());
context.assertEquals(10000, config.getUnlockQueuesTaskInterval());
context.assertFalse(config.isUnlockSampleQueuesTaskEnabled());
context.assertEquals(120000, config.getUnlockSampleQueuesTaskInterval());
}
use of org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager in project gateleen by swisspush.
the class QueueCircuitBreakerConfigurationResourceManagerTest method testValidContentShouldBeStoredInStorage.
@Test
public void testValidContentShouldBeStoredInStorage(TestContext context) {
Async async = context.async();
QueueCircuitBreakerConfigurationResourceManager manager = new QueueCircuitBreakerConfigurationResourceManager(vertx, storage, CONFIGURATION_URI);
final DummyHttpServerResponse response = new DummyHttpServerResponse();
class UpdateConfigResourceWithValidDataRequest extends ConfigResourcePUTRequest {
@Override
public HttpServerRequest bodyHandler(Handler<Buffer> bodyHandler) {
bodyHandler.handle(Buffer.buffer(VALID_CONFIG_RESOURCE));
return this;
}
@Override
public HttpServerResponse response() {
return response;
}
}
storage.get(CONFIGURATION_URI, result -> {
context.assertEquals(INITIAL_CONFIG_RESOURCE, result.toString());
context.assertTrue(manager.handleConfigurationResource(new UpdateConfigResourceWithValidDataRequest()));
storage.get(CONFIGURATION_URI, updatedResult -> {
context.assertEquals(VALID_CONFIG_RESOURCE, updatedResult.toString());
async.complete();
});
});
}
use of org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager in project gateleen by swisspush.
the class AbstractTest method setupBeforeClass.
/**
* Starts redis before the test classes are instantiated.
*/
@BeforeClass
public static void setupBeforeClass(TestContext context) {
Async async = context.async();
vertx = Vertx.vertx();
jedis = new Jedis("localhost", REDIS_PORT, 10000);
jedis.flushAll();
final JsonObject info = new JsonObject();
final LocalHttpClient selfClient = new LocalHttpClient(vertx);
props.putAll(RunConfig.buildRedisProps("localhost", REDIS_PORT));
String redisHost = (String) props.get("redis.host");
Integer redisPort = (Integer) props.get("redis.port");
props.put(ExpansionHandler.MAX_EXPANSION_LEVEL_HARD_PROPERTY, "100");
props.put(ExpansionHandler.MAX_EXPANSION_LEVEL_SOFT_PROPERTY, "4");
RunConfig.deployModules(vertx, AbstractTest.class, props, success -> {
if (success) {
RedisClient redisClient = new RedisClient(vertx, new RedisOptions().setConnectionString("redis://" + redisHost + ":" + redisPort));
RedisAPI redisAPI = RedisAPI.api(redisClient);
ResourceStorage storage = new EventBusResourceStorage(vertx.eventBus(), Address.storageAddress() + "-main");
MonitoringHandler monitoringHandler = new MonitoringHandler(vertx, storage, PREFIX);
ConfigurationResourceManager configurationResourceManager = new ConfigurationResourceManager(vertx, storage);
String eventBusConfigurationResource = SERVER_ROOT + "/admin/v1/hookconfig";
EventBusHandler eventBusHandler = new EventBusHandler(vertx, SERVER_ROOT + "/event/v1/", SERVER_ROOT + "/event/v1/sock/", "event-", "channels/([^/]+).*", configurationResourceManager, eventBusConfigurationResource);
eventBusHandler.setEventbusBridgePingInterval(RunConfig.EVENTBUS_BRIDGE_PING_INTERVAL);
LoggingResourceManager loggingResourceManager = new LoggingResourceManager(vertx, storage, SERVER_ROOT + "/admin/v1/logging");
UserProfileHandler userProfileHandler = new UserProfileHandler(vertx, storage, RunConfig.buildUserProfileConfiguration());
RoleProfileHandler roleProfileHandler = new RoleProfileHandler(vertx, storage, SERVER_ROOT + "/roles/v1/([^/]+)/profile");
qosHandler = new QoSHandler(vertx, storage, SERVER_ROOT + "/admin/v1/qos", props, PREFIX);
Lock lock = new RedisBasedLock(redisClient);
QueueClient queueClient = new QueueClient(vertx, monitoringHandler);
ReducedPropagationManager reducedPropagationManager = new ReducedPropagationManager(vertx, new RedisReducedPropagationStorage(redisAPI), queueClient, lock);
reducedPropagationManager.startExpiredQueueProcessing(1000);
hookHandler = new HookHandler(vertx, selfClient, storage, loggingResourceManager, monitoringHandler, SERVER_ROOT + "/users/v1/%s/profile", ROOT + "/server/hooks/v1/", queueClient, false, reducedPropagationManager);
propertyHandler = new PropertyHandler(ROOT, props);
schedulerResourceManager = new SchedulerResourceManager(vertx, redisAPI, storage, monitoringHandler, SERVER_ROOT + "/admin/v1/schedulers");
ResetMetricsController resetMetricsController = new ResetMetricsController(vertx);
resetMetricsController.registerResetMetricsControlMBean(JMX_DOMAIN, PREFIX);
LogController logController = new LogController();
logController.registerLogConfiguratorMBean(JMX_DOMAIN);
ZipExtractHandler zipExtractHandler = new ZipExtractHandler(selfClient);
DelegateHandler delegateHandler = new DelegateHandler(vertx, selfClient, storage, monitoringHandler, DELEGATE_ROOT, props, null);
MergeHandler mergeHandler = new MergeHandler(selfClient);
cacheHandler = new CacheHandler(new DefaultCacheDataFetcher(new ClientRequestCreator(selfClient)), new RedisCacheStorage(vertx, lock, redisAPI, 60000), SERVER_ROOT + "/cache");
customHttpResponseHandler = new CustomHttpResponseHandler(RETURN_HTTP_STATUS_ROOT);
// ------
RuleProvider ruleProvider = new RuleProvider(vertx, RULES_ROOT, storage, props);
QueueCircuitBreakerRulePatternToCircuitMapping rulePatternToCircuitMapping = new QueueCircuitBreakerRulePatternToCircuitMapping();
QueueCircuitBreakerConfigurationResourceManager queueCircuitBreakerConfigurationResourceManager = new QueueCircuitBreakerConfigurationResourceManager(vertx, storage, SERVER_ROOT + "/admin/v1/circuitbreaker");
QueueCircuitBreakerStorage queueCircuitBreakerStorage = new RedisQueueCircuitBreakerStorage(redisAPI);
QueueCircuitBreakerHttpRequestHandler requestHandler = new QueueCircuitBreakerHttpRequestHandler(vertx, queueCircuitBreakerStorage, SERVER_ROOT + "/queuecircuitbreaker/circuit");
QueueCircuitBreaker queueCircuitBreaker = new QueueCircuitBreakerImpl(vertx, lock, Address.redisquesAddress(), queueCircuitBreakerStorage, ruleProvider, rulePatternToCircuitMapping, queueCircuitBreakerConfigurationResourceManager, requestHandler, CIRCUIT_BREAKER_REST_API_PORT);
new QueueProcessor(vertx, selfClient, monitoringHandler, queueCircuitBreaker);
final QueueBrowser queueBrowser = new QueueBrowser(vertx, SERVER_ROOT + "/queuing", Address.redisquesAddress(), monitoringHandler);
new CustomRedisMonitor(vertx, redisAPI, "main", "rest-storage", 10).start();
Router router = new Router(vertx, storage, props, loggingResourceManager, monitoringHandler, selfClient, SERVER_ROOT, SERVER_ROOT + "/admin/v1/routing/rules", SERVER_ROOT + "/users/v1/%s/profile", info, STORAGE_PORT, (Handler<Void>) aVoid -> {
System.out.println("Router initialized!");
hookHandler.init();
delegateHandler.init();
});
router.enableRoutingConfiguration(configurationResourceManager, SERVER_ROOT + "/admin/v1/routing/config");
System.setProperty("org.swisspush.gateleen.addcorsheaders", "true");
RunConfig runConfig = RunConfig.with().cacheHandler(cacheHandler).corsHandler(new CORSHandler()).deltaHandler(new DeltaHandler(redisAPI, selfClient, ruleProvider)).expansionHandler(new ExpansionHandler(vertx, storage, selfClient, props, ROOT, RULES_ROOT)).hookHandler(hookHandler).qosHandler(qosHandler).copyResourceHandler(new CopyResourceHandler(selfClient, SERVER_ROOT + "/v1/copy")).eventBusHandler(eventBusHandler).roleProfileHandler(roleProfileHandler).userProfileHandler(userProfileHandler).loggingResourceManager(loggingResourceManager).configurationResourceManager(configurationResourceManager).queueCircuitBreakerConfigurationResourceManager(queueCircuitBreakerConfigurationResourceManager).schedulerResourceManager(schedulerResourceManager).propertyHandler(propertyHandler).zipExtractHandler(zipExtractHandler).delegateHandler(delegateHandler).mergeHandler(mergeHandler).customHttpResponseHandler(customHttpResponseHandler).build(vertx, redisAPI, AbstractTest.class, router, monitoringHandler, queueBrowser);
Handler<RoutingContext> routingContextHandlerrNew = runConfig.buildRoutingContextHandler();
selfClient.setRoutingContexttHandler(routingContextHandlerrNew);
mainServer = vertx.createHttpServer();
io.vertx.ext.web.Router vertxRouter = io.vertx.ext.web.Router.router(vertx);
eventBusHandler.install(vertxRouter);
vertxRouter.route().handler(routingContextHandlerrNew);
mainServer.requestHandler(vertxRouter);
mainServer.listen(MAIN_PORT, event -> {
if (event.succeeded()) {
async.complete();
} else {
context.fail("Server not listening on port " + MAIN_PORT);
}
});
}
});
async.awaitSuccess();
}
Aggregations