RedisQueueCircuitBreakerStorage implements QueueCircuitBreakerStorage { @Override public Future<JsonObject> getQueueCircuitInformation(String circuitHash) { Future<JsonObject> future = Future.future(); List<String> fields = Arrays.asList(FIELD_STATE, FIELD_FAILRATIO, FIELD_CIRCUIT); redisClient.hmget(buildInfosKey(circuitHash), fields, event -> { if(event.failed()){ future.fail(event.cause()); } else { try { QueueCircuitState state = QueueCircuitState.fromString(event.result().getString(0), QueueCircuitState.CLOSED); String failRatioStr = event.result().getString(1); String circuit = event.result().getString(2); JsonObject result = new JsonObject(); result.put("status", state.name().toLowerCase()); JsonObject info = new JsonObject(); if (failRatioStr != null) { info.put(FIELD_FAILRATIO, Integer.valueOf(failRatioStr)); } if (circuit != null) { info.put(FIELD_CIRCUIT, circuit); } result.put("info", info); future.complete(result); }catch (Exception e){ future.fail(e); } } }); return future; } RedisQueueCircuitBreakerStorage(RedisClient redisClient); @Override Future<QueueCircuitState> getQueueCircuitState(PatternAndCircuitHash patternAndCircuitHash); @Override Future<QueueCircuitState> getQueueCircuitState(String circuitHash); @Override Future<JsonObject> getQueueCircuitInformation(String circuitHash); @Override Future<JsonObject> getAllCircuits(); @Override Future<UpdateStatisticsResult> updateStatistics(PatternAndCircuitHash patternAndCircuitHash, String uniqueRequestID, long timestamp,
                                                           int errorThresholdPercentage, long entriesMaxAgeMS, long minQueueSampleCount,
                                                           long maxQueueSampleCount, QueueResponseType queueResponseType); @Override Future<Void> lockQueue(String queueName, PatternAndCircuitHash patternAndCircuitHash); @Override Future<String> popQueueToUnlock(); @Override Future<Void> closeCircuit(PatternAndCircuitHash patternAndCircuitHash); @Override Future<Void> closeAndRemoveCircuit(PatternAndCircuitHash patternAndCircuitHash); @Override Future<Void> closeAllCircuits(); @Override Future<Void> reOpenCircuit(PatternAndCircuitHash patternAndCircuitHash); @Override Future<Long> setOpenCircuitsToHalfOpen(); @Override Future<List<String>> unlockSampleQueues(); static final String STORAGE_PREFIX; static final String STORAGE_INFOS_SUFFIX; static final String STORAGE_QUEUES_SUFFIX; static final String STORAGE_ALL_CIRCUITS; static final String STORAGE_HALFOPEN_CIRCUITS; static final String STORAGE_OPEN_CIRCUITS; static final String STORAGE_QUEUES_TO_UNLOCK; static final String FIELD_STATE; static final String FIELD_FAILRATIO; static final String FIELD_CIRCUIT; }
@Test public void testGetQueueCircuitInformation(TestContext context){ Async async = context.async(); String hash = "someCircuitHash"; storage.getQueueCircuitInformation(hash).setHandler(event -> { context.assertTrue(event.succeeded()); JsonObject result = event.result(); context.assertEquals(CLOSED.name().toLowerCase(), result.getString("status")); context.assertTrue(result.containsKey("info")); context.assertFalse(result.getJsonObject("info").containsKey("failRatio")); context.assertFalse(result.getJsonObject("info").containsKey("circuit")); writeQueueCircuit(hash, HALF_OPEN, "/some/circuit/path", 99); storage.getQueueCircuitInformation(hash).setHandler(event1 -> { context.assertTrue(event1.succeeded()); JsonObject result1 = event1.result(); context.assertEquals(HALF_OPEN.name().toLowerCase(), result1.getString("status")); context.assertTrue(result1.containsKey("info")); context.assertEquals(99, result1.getJsonObject("info").getInteger("failRatio")); context.assertEquals("/some/circuit/path", result1.getJsonObject("info").getString("circuit")); async.complete(); }); }); }