QueueCircuitBreakerImpl implements QueueCircuitBreaker, RuleChangesObserver, Refreshable { @Override public Future<Void> closeAllCircuits() { log.info("About to close all circuits"); return queueCircuitBreakerStorage.closeAllCircuits(); } QueueCircuitBreakerImpl(Vertx vertx, Lock lock, String redisquesAddress, QueueCircuitBreakerStorage queueCircuitBreakerStorage, RuleProvider ruleProvider, QueueCircuitBreakerRulePatternToCircuitMapping ruleToCircuitMapping, QueueCircuitBreakerConfigurationResourceManager configResourceManager, Handler<HttpServerRequest> queueCircuitBreakerHttpRequestHandler, int requestHandlerPort); @Override void rulesChanged(List<Rule> rules); @Override void refresh(); @Override boolean isCircuitCheckEnabled(); @Override boolean isStatisticsUpdateEnabled(); @Override Future<QueueCircuitState> handleQueuedRequest(String queueName, HttpRequest queuedRequest); @Override Future<Void> updateStatistics(String queueName, HttpRequest queuedRequest, QueueResponseType queueResponseType); @Override Future<Void> closeCircuit(HttpRequest queuedRequest); @Override Future<Void> closeAllCircuits(); @Override Future<Void> reOpenCircuit(HttpRequest queuedRequest); @Override Future<Void> lockQueue(String queueName, HttpRequest queuedRequest); @Override Future<String> unlockNextQueue(); @Override Future<Long> setOpenCircuitsToHalfOpen(); @Override Future<Long> unlockSampleQueues(); @Override Future<String> unlockQueue(String queueName); static final String OPEN_TO_HALF_OPEN_TASK_LOCK; static final String UNLOCK_QUEUES_TASK_LOCK; static final String UNLOCK_SAMPLE_QUEUES_TASK_LOCK; }
@Test public void testCloseAllCircuits(TestContext context){ Async async = context.async(); Mockito.when(queueCircuitBreakerStorage.closeAllCircuits()) .thenReturn(Future.succeededFuture()); queueCircuitBreaker.closeAllCircuits().setHandler(event -> { context.assertTrue(event.succeeded()); verify(queueCircuitBreakerStorage, times(1)).closeAllCircuits(); async.complete(); }); async.awaitSuccess(); }
@Test public void testCloseAllCircuitsFailingStorage(TestContext context){ Async async = context.async(); Mockito.when(queueCircuitBreakerStorage.closeAllCircuits()) .thenReturn(Future.failedFuture("unable to close all circuits")); queueCircuitBreaker.closeAllCircuits().setHandler(event -> { context.assertTrue(event.failed()); context.assertTrue(event.cause().getMessage().contains("unable to close all circuits")); verify(queueCircuitBreakerStorage, times(1)).closeAllCircuits(); async.complete(); }); async.awaitSuccess(); }