Search in sources :

Example 1 with Lock

use of org.swisspush.gateleen.core.lock.Lock in project gateleen by swisspush.

the class QueueCircuitBreakerImplTest method setUp.

@Before
public void setUp() {
    vertx = Vertx.vertx();
    lock = Mockito.mock(Lock.class);
    Mockito.when(lock.acquireLock(Matchers.anyString(), Matchers.anyString(), Matchers.anyLong())).thenReturn(Future.succeededFuture(Boolean.TRUE));
    Mockito.when(lock.releaseLock(Matchers.anyString(), Matchers.anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE));
    storage = Mockito.mock(ResourceStorage.class);
    queueCircuitBreakerStorage = Mockito.mock(QueueCircuitBreakerStorage.class);
    Mockito.when(queueCircuitBreakerStorage.setOpenCircuitsToHalfOpen()).thenReturn(Future.succeededFuture(0L));
    Mockito.when(queueCircuitBreakerStorage.popQueueToUnlock()).thenReturn(Future.succeededFuture("SomeQueue"));
    Mockito.when(queueCircuitBreakerStorage.unlockSampleQueues()).thenReturn(Future.succeededFuture(MultiType.EMPTY_MULTI));
    ruleProvider = new RuleProvider(vertx, "/path/to/routing/rules", storage, props);
    ruleToCircuitMapping = Mockito.mock(QueueCircuitBreakerRulePatternToCircuitMapping.class);
    configResourceManager = Mockito.mock(QueueCircuitBreakerConfigurationResourceManager.class);
    QueueCircuitBreakerConfigurationResource config = new QueueCircuitBreakerConfigurationResource();
    config.setOpenToHalfOpenTaskEnabled(true);
    config.setOpenToHalfOpenTaskInterval(1000);
    config.setUnlockQueuesTaskEnabled(true);
    config.setUnlockQueuesTaskInterval(1000);
    config.setUnlockSampleQueuesTaskEnabled(true);
    config.setUnlockSampleQueuesTaskInterval(1000);
    Mockito.when(configResourceManager.getConfigurationResource()).thenReturn(config);
    Handler<HttpServerRequest> queueCircuitBreakerHttpRequestHandler = Mockito.mock(Handler.class);
    queueCircuitBreaker = Mockito.spy(new QueueCircuitBreakerImpl(vertx, lock, Address.redisquesAddress(), queueCircuitBreakerStorage, ruleProvider, ruleToCircuitMapping, configResourceManager, queueCircuitBreakerHttpRequestHandler, 9999));
}
Also used : QueueCircuitBreakerConfigurationResource(org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResource) ResourceStorage(org.swisspush.gateleen.core.storage.ResourceStorage) HttpServerRequest(io.vertx.core.http.HttpServerRequest) QueueCircuitBreakerStorage(org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreakerStorage) RuleProvider(org.swisspush.gateleen.routing.RuleProvider) QueueCircuitBreakerConfigurationResourceManager(org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager) Lock(org.swisspush.gateleen.core.lock.Lock) Before(org.junit.Before)

Example 2 with Lock

use of org.swisspush.gateleen.core.lock.Lock in project gateleen by swisspush.

the class RedisCacheStorageTest method setUp.

@Before
public void setUp() {
    vertx = Vertx.vertx();
    lock = Mockito.mock(Lock.class);
    Mockito.when(lock.acquireLock(anyString(), anyString(), anyLong())).thenReturn(Future.succeededFuture(Boolean.TRUE));
    Mockito.when(lock.releaseLock(anyString(), anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE));
    redisCacheStorage = new RedisCacheStorage(vertx, lock, RedisAPI.api(new RedisClient(vertx, new RedisOptions())), 2000);
    jedis = new Jedis(new HostAndPort("localhost", 6379));
    try {
        jedis.flushAll();
    } catch (JedisConnectionException e) {
        org.junit.Assume.assumeNoException("Ignoring this test because no running redis is available. This is the case during release", e);
    }
}
Also used : RedisClient(io.vertx.redis.client.impl.RedisClient) Jedis(redis.clients.jedis.Jedis) HostAndPort(redis.clients.jedis.HostAndPort) RedisOptions(io.vertx.redis.client.RedisOptions) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Lock(org.swisspush.gateleen.core.lock.Lock) Before(org.junit.Before)

Example 3 with Lock

use of org.swisspush.gateleen.core.lock.Lock 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();
}
Also used : ZipExtractHandler(org.swisspush.gateleen.expansion.ZipExtractHandler) TestContext(io.vertx.ext.unit.TestContext) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) QueueClient(org.swisspush.gateleen.queue.queuing.QueueClient) EventBusHandler(org.swisspush.gateleen.core.event.EventBusHandler) HttpServer(io.vertx.core.http.HttpServer) RoutingContext(io.vertx.ext.web.RoutingContext) Parser(io.restassured.parsing.Parser) RunConfig(org.swisspush.gateleen.runconfig.RunConfig) RedisBasedLock(org.swisspush.gateleen.core.lock.impl.RedisBasedLock) RequestSpecification(io.restassured.specification.RequestSpecification) LoggingResourceManager(org.swisspush.gateleen.logging.LoggingResourceManager) After(org.junit.After) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) AfterClass(org.junit.AfterClass) Lock(org.swisspush.gateleen.core.lock.Lock) CopyResourceHandler(org.swisspush.gateleen.core.resource.CopyResourceHandler) QueueCircuitBreakerImpl(org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.QueueCircuitBreakerImpl) UserProfileHandler(org.swisspush.gateleen.user.UserProfileHandler) RedisReducedPropagationStorage(org.swisspush.gateleen.hook.reducedpropagation.impl.RedisReducedPropagationStorage) ZipExtractHandler(org.swisspush.gateleen.expansion.ZipExtractHandler) RedisQueueCircuitBreakerStorage(org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.RedisQueueCircuitBreakerStorage) Address(org.swisspush.gateleen.core.util.Address) Router(org.swisspush.gateleen.routing.Router) LocalHttpClient(org.swisspush.gateleen.core.http.LocalHttpClient) Set(java.util.Set) RedisAPI(io.vertx.redis.client.RedisAPI) QueueProcessor(org.swisspush.gateleen.queue.queuing.QueueProcessor) CacheHandler(org.swisspush.gateleen.cache.CacheHandler) DelegateHandler(org.swisspush.gateleen.delegate.DelegateHandler) ResourceStorage(org.swisspush.gateleen.core.storage.ResourceStorage) CustomHttpResponseHandler(org.swisspush.gateleen.routing.CustomHttpResponseHandler) SchedulerResourceManager(org.swisspush.gateleen.scheduler.SchedulerResourceManager) RestAssured(io.restassured.RestAssured) CORSHandler(org.swisspush.gateleen.core.cors.CORSHandler) Async(io.vertx.ext.unit.Async) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) HookHandler(org.swisspush.gateleen.hook.HookHandler) ClientRequestCreator(org.swisspush.gateleen.core.http.ClientRequestCreator) QueueCircuitBreakerHttpRequestHandler(org.swisspush.gateleen.queue.queuing.circuitbreaker.api.QueueCircuitBreakerHttpRequestHandler) HashMap(java.util.HashMap) MonitoringHandler(org.swisspush.gateleen.monitoring.MonitoringHandler) QueueCircuitBreakerConfigurationResourceManager(org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager) EventBusResourceStorage(org.swisspush.gateleen.core.storage.EventBusResourceStorage) QueueCircuitBreakerRulePatternToCircuitMapping(org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueCircuitBreakerRulePatternToCircuitMapping) ConfigurationResourceManager(org.swisspush.gateleen.core.configuration.ConfigurationResourceManager) CustomRedisMonitor(org.swisspush.gateleen.monitoring.CustomRedisMonitor) QoSHandler(org.swisspush.gateleen.qos.QoSHandler) RoleProfileHandler(org.swisspush.gateleen.user.RoleProfileHandler) LogController(org.swisspush.gateleen.logging.LogController) DeltaHandler(org.swisspush.gateleen.delta.DeltaHandler) RuleProvider(org.swisspush.gateleen.routing.RuleProvider) ManagementFactory(java.lang.management.ManagementFactory) QueueCircuitBreakerStorage(org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreakerStorage) Before(org.junit.Before) DefaultCacheDataFetcher(org.swisspush.gateleen.cache.fetch.DefaultCacheDataFetcher) ResetMetricsController(org.swisspush.gateleen.monitoring.ResetMetricsController) ReducedPropagationManager(org.swisspush.gateleen.hook.reducedpropagation.ReducedPropagationManager) javax.management(javax.management) Vertx(io.vertx.core.Vertx) RedisClient(io.vertx.redis.client.impl.RedisClient) PropertyHandler(org.swisspush.gateleen.core.property.PropertyHandler) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) RedisOptions(io.vertx.redis.client.RedisOptions) QueueBrowser(org.swisspush.gateleen.queue.queuing.QueueBrowser) RedisCacheStorage(org.swisspush.gateleen.cache.storage.RedisCacheStorage) ExpansionHandler(org.swisspush.gateleen.expansion.ExpansionHandler) Jedis(redis.clients.jedis.Jedis) MergeHandler(org.swisspush.gateleen.merge.MergeHandler) Handler(io.vertx.core.Handler) QueueCircuitBreaker(org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreaker) SchedulerResourceManager(org.swisspush.gateleen.scheduler.SchedulerResourceManager) JsonObject(io.vertx.core.json.JsonObject) RedisOptions(io.vertx.redis.client.RedisOptions) UserProfileHandler(org.swisspush.gateleen.user.UserProfileHandler) RedisCacheStorage(org.swisspush.gateleen.cache.storage.RedisCacheStorage) Jedis(redis.clients.jedis.Jedis) RoutingContext(io.vertx.ext.web.RoutingContext) Async(io.vertx.ext.unit.Async) LogController(org.swisspush.gateleen.logging.LogController) CustomHttpResponseHandler(org.swisspush.gateleen.routing.CustomHttpResponseHandler) EventBusHandler(org.swisspush.gateleen.core.event.EventBusHandler) ReducedPropagationManager(org.swisspush.gateleen.hook.reducedpropagation.ReducedPropagationManager) RedisAPI(io.vertx.redis.client.RedisAPI) CORSHandler(org.swisspush.gateleen.core.cors.CORSHandler) Router(org.swisspush.gateleen.routing.Router) DeltaHandler(org.swisspush.gateleen.delta.DeltaHandler) RedisBasedLock(org.swisspush.gateleen.core.lock.impl.RedisBasedLock) RedisClient(io.vertx.redis.client.impl.RedisClient) MonitoringHandler(org.swisspush.gateleen.monitoring.MonitoringHandler) RoleProfileHandler(org.swisspush.gateleen.user.RoleProfileHandler) LocalHttpClient(org.swisspush.gateleen.core.http.LocalHttpClient) CustomRedisMonitor(org.swisspush.gateleen.monitoring.CustomRedisMonitor) CacheHandler(org.swisspush.gateleen.cache.CacheHandler) QueueCircuitBreakerConfigurationResourceManager(org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager) ConfigurationResourceManager(org.swisspush.gateleen.core.configuration.ConfigurationResourceManager) QueueClient(org.swisspush.gateleen.queue.queuing.QueueClient) DelegateHandler(org.swisspush.gateleen.delegate.DelegateHandler) QueueCircuitBreakerImpl(org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.QueueCircuitBreakerImpl) ClientRequestCreator(org.swisspush.gateleen.core.http.ClientRequestCreator) RedisQueueCircuitBreakerStorage(org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.RedisQueueCircuitBreakerStorage) RuleProvider(org.swisspush.gateleen.routing.RuleProvider) RedisReducedPropagationStorage(org.swisspush.gateleen.hook.reducedpropagation.impl.RedisReducedPropagationStorage) QueueCircuitBreakerHttpRequestHandler(org.swisspush.gateleen.queue.queuing.circuitbreaker.api.QueueCircuitBreakerHttpRequestHandler) QueueCircuitBreakerConfigurationResourceManager(org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager) ExpansionHandler(org.swisspush.gateleen.expansion.ExpansionHandler) MergeHandler(org.swisspush.gateleen.merge.MergeHandler) PropertyHandler(org.swisspush.gateleen.core.property.PropertyHandler) CopyResourceHandler(org.swisspush.gateleen.core.resource.CopyResourceHandler) ResetMetricsController(org.swisspush.gateleen.monitoring.ResetMetricsController) RedisQueueCircuitBreakerStorage(org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.RedisQueueCircuitBreakerStorage) QueueCircuitBreakerStorage(org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreakerStorage) QoSHandler(org.swisspush.gateleen.qos.QoSHandler) QueueCircuitBreaker(org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreaker) QueueCircuitBreakerRulePatternToCircuitMapping(org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueCircuitBreakerRulePatternToCircuitMapping) LoggingResourceManager(org.swisspush.gateleen.logging.LoggingResourceManager) RunConfig(org.swisspush.gateleen.runconfig.RunConfig) RedisBasedLock(org.swisspush.gateleen.core.lock.impl.RedisBasedLock) Lock(org.swisspush.gateleen.core.lock.Lock) QueueProcessor(org.swisspush.gateleen.queue.queuing.QueueProcessor) ResourceStorage(org.swisspush.gateleen.core.storage.ResourceStorage) EventBusResourceStorage(org.swisspush.gateleen.core.storage.EventBusResourceStorage) EventBusResourceStorage(org.swisspush.gateleen.core.storage.EventBusResourceStorage) DefaultCacheDataFetcher(org.swisspush.gateleen.cache.fetch.DefaultCacheDataFetcher) QueueBrowser(org.swisspush.gateleen.queue.queuing.QueueBrowser) HookHandler(org.swisspush.gateleen.hook.HookHandler) BeforeClass(org.junit.BeforeClass)

Example 4 with Lock

use of org.swisspush.gateleen.core.lock.Lock in project gateleen by swisspush.

the class ReducedPropagationManagerTest method testExpiredQueueProcessingDeleteAllQueueItemsAndDeleteLockOfQueueSuccess.

@Test
public void testExpiredQueueProcessingDeleteAllQueueItemsAndDeleteLockOfQueueSuccess(TestContext context) {
    Async async = context.async();
    JsonObject requestJsonObject = new HttpRequest(HttpMethod.PUT, "/my/uri", MultiMap.caseInsensitiveMultiMap(), null).toJsonObject();
    String expiredQueue = "myExpiredQueue";
    String managerQueue = MANAGER_QUEUE_PREFIX + expiredQueue;
    Mockito.when(reducedPropagationStorage.getQueueRequest(anyString())).thenReturn(Future.succeededFuture(requestJsonObject));
    Mockito.when(requestQueue.deleteAllQueueItems(eq(managerQueue), anyBoolean())).thenReturn(Future.succeededFuture());
    Mockito.when(requestQueue.enqueueFuture(any(), anyString())).thenReturn(Future.succeededFuture());
    Mockito.when(reducedPropagationStorage.removeQueueRequest(eq(expiredQueue))).thenReturn(Future.succeededFuture());
    Mockito.when(requestQueue.deleteAllQueueItems(eq(expiredQueue), anyBoolean())).thenReturn(Future.succeededFuture());
    vertx.eventBus().request(PROCESSOR_ADDRESS, expiredQueue, (Handler<AsyncResult<Message<JsonObject>>>) event -> {
        context.assertTrue(event.succeeded());
        context.assertEquals(OK, event.result().body().getString(STATUS));
        context.assertEquals("Successfully deleted lock and all queue items of queue myExpiredQueue", event.result().body().getString(MESSAGE));
        verify(reducedPropagationStorage, timeout(1000).times(1)).getQueueRequest(eq(expiredQueue));
        verify(requestQueue, timeout(1000).times(1)).deleteAllQueueItems(eq(managerQueue), eq(false));
        verify(requestQueue, timeout(1000).times(1)).enqueueFuture(any(), eq(managerQueue));
        verify(reducedPropagationStorage, timeout(1000).times(1)).removeQueueRequest(eq(expiredQueue));
        verify(requestQueue, timeout(1000).times(1)).deleteAllQueueItems(eq(expiredQueue), eq(true));
        async.complete();
    });
}
Also used : HttpRequest(org.swisspush.gateleen.core.http.HttpRequest) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) MultiType(io.vertx.redis.client.impl.types.MultiType) AdditionalMatchers(org.mockito.AdditionalMatchers) io.vertx.core(io.vertx.core) RunWith(org.junit.runner.RunWith) Timeout(io.vertx.ext.unit.junit.Timeout) HttpRequestHeader.getInteger(org.swisspush.gateleen.core.util.HttpRequestHeader.getInteger) HttpRequest(org.swisspush.gateleen.core.http.HttpRequest) RequestQueue(org.swisspush.gateleen.queue.queuing.RequestQueue) ArgumentCaptor(org.mockito.ArgumentCaptor) CONTENT_LENGTH(org.swisspush.gateleen.core.util.HttpRequestHeader.CONTENT_LENGTH) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before) Lock(org.swisspush.gateleen.core.lock.Lock) InOrder(org.mockito.InOrder) ReducedPropagationManager(org.swisspush.gateleen.hook.reducedpropagation.ReducedPropagationManager) Message(io.vertx.core.eventbus.Message) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Mockito(org.mockito.Mockito) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) RedisquesAPI(org.swisspush.redisques.util.RedisquesAPI) HttpMethod(io.vertx.core.http.HttpMethod) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 5 with Lock

use of org.swisspush.gateleen.core.lock.Lock in project gateleen by swisspush.

the class ReducedPropagationManager method processExpiredQueues.

private void processExpiredQueues(String lockToken) {
    log.debug("Going to process expired queues");
    storage.removeExpiredQueues(System.currentTimeMillis()).onComplete(event -> {
        if (event.failed()) {
            log.error("Going to release lock because process expired queues failed. Cause: " + event.cause());
            releaseLock(this.lock, PROCESS_EXPIRED_QUEUES_LOCK, lockToken, log);
            return;
        }
        Response response = event.result();
        log.debug("Got {} expired queues to process", response.size());
        for (Response expiredQueue : response) {
            log.debug("About to notify a consumer to process expired queue '{}'", expiredQueue);
            vertx.eventBus().request(PROCESSOR_ADDRESS, expiredQueue.toString(), (Handler<AsyncResult<Message<JsonObject>>>) event1 -> {
                if (event1.failed()) {
                    log.error("Failed to process expired queue '{}'. Cause: {}", expiredQueue, event1.cause());
                    handleFailedQueueRetry(expiredQueue.toString());
                } else {
                    failedQueueRetries.remove(expiredQueue.toString());
                    if (!OK.equals(event1.result().body().getString(STATUS))) {
                        log.error("Failed to process expired queue '{}'. Message: {}", expiredQueue, event1.result().body().getString(MESSAGE));
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug(event1.result().body().getString(MESSAGE));
                        }
                    }
                }
            });
        }
    });
}
Also used : Response(io.vertx.redis.client.Response) Lock(org.swisspush.gateleen.core.lock.Lock) LockUtil.releaseLock(org.swisspush.gateleen.core.util.LockUtil.releaseLock) Logger(org.slf4j.Logger) io.vertx.core(io.vertx.core) Response(io.vertx.redis.client.Response) Address(org.swisspush.gateleen.core.util.Address) LoggerFactory(org.slf4j.LoggerFactory) Message(io.vertx.core.eventbus.Message) HashMap(java.util.HashMap) Random(java.util.Random) HttpRequest(org.swisspush.gateleen.core.http.HttpRequest) RequestQueue(org.swisspush.gateleen.queue.queuing.RequestQueue) HttpRequestHeader(org.swisspush.gateleen.core.util.HttpRequestHeader) StringUtils(org.swisspush.gateleen.core.util.StringUtils) CONTENT_LENGTH(org.swisspush.gateleen.core.util.HttpRequestHeader.CONTENT_LENGTH) Buffer(io.vertx.core.buffer.Buffer) RedisquesAPI(org.swisspush.redisques.util.RedisquesAPI) HttpMethod(io.vertx.core.http.HttpMethod) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) LockUtil.acquireLock(org.swisspush.gateleen.core.util.LockUtil.acquireLock) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

Lock (org.swisspush.gateleen.core.lock.Lock)7 Before (org.junit.Before)5 JsonObject (io.vertx.core.json.JsonObject)4 ReducedPropagationManager (org.swisspush.gateleen.hook.reducedpropagation.ReducedPropagationManager)4 RedisOptions (io.vertx.redis.client.RedisOptions)3 RedisClient (io.vertx.redis.client.impl.RedisClient)3 io.vertx.core (io.vertx.core)2 Buffer (io.vertx.core.buffer.Buffer)2 Message (io.vertx.core.eventbus.Message)2 HttpMethod (io.vertx.core.http.HttpMethod)2 Async (io.vertx.ext.unit.Async)2 TestContext (io.vertx.ext.unit.TestContext)2 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RunWith (org.junit.runner.RunWith)2 ResourceStorage (org.swisspush.gateleen.core.storage.ResourceStorage)2 RequestQueue (org.swisspush.gateleen.queue.queuing.RequestQueue)2 QueueCircuitBreakerStorage (org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreakerStorage)2