RedisQueueCircuitBreakerStorage implements QueueCircuitBreakerStorage { @Override public Future<JsonObject> getAllCircuits() { Future<JsonObject> future = Future.future(); List<String> keys = Collections.singletonList(STORAGE_ALL_CIRCUITS); List<String> arguments = Arrays.asList(STORAGE_PREFIX, STORAGE_INFOS_SUFFIX); GetAllCircuitsRedisCommand cmd = new GetAllCircuitsRedisCommand(getAllCircuitsLuaScriptState, keys, arguments, redisClient, log, future); cmd.exec(0); 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 testGetAllCircuits(TestContext context){ Async async = context.async(); String hash1 = "hash_1"; String hash2 = "hash_2"; String hash3 = "hash_3"; context.assertFalse(jedis.exists(infosKey(hash1))); context.assertFalse(jedis.exists(infosKey(hash2))); context.assertFalse(jedis.exists(infosKey(hash3))); writeQueueCircuit(hash1, HALF_OPEN, "/path/to/hash_1", 60); writeQueueCircuit(hash2, CLOSED, "/path/to/hash_2", 20); writeQueueCircuit(hash3, OPEN, "/path/to/hash_3", 99); context.assertTrue(jedis.exists(infosKey(hash1))); context.assertTrue(jedis.exists(infosKey(hash2))); context.assertTrue(jedis.exists(infosKey(hash3))); context.assertEquals(3L, jedis.scard(STORAGE_ALL_CIRCUITS)); context.assertEquals(HALF_OPEN.name().toLowerCase(), jedis.hget(infosKey(hash1), FIELD_STATE).toLowerCase()); context.assertEquals("/path/to/hash_1", jedis.hget(infosKey(hash1), FIELD_CIRCUIT)); context.assertEquals("60", jedis.hget(infosKey(hash1), FIELD_FAILRATIO)); context.assertEquals(CLOSED.name().toLowerCase(), jedis.hget(infosKey(hash2), FIELD_STATE).toLowerCase()); context.assertEquals("/path/to/hash_2", jedis.hget(infosKey(hash2), FIELD_CIRCUIT)); context.assertEquals("20", jedis.hget(infosKey(hash2), FIELD_FAILRATIO)); context.assertEquals(OPEN.name().toLowerCase(), jedis.hget(infosKey(hash3), FIELD_STATE).toLowerCase()); context.assertEquals("/path/to/hash_3", jedis.hget(infosKey(hash3), FIELD_CIRCUIT)); context.assertEquals("99", jedis.hget(infosKey(hash3), FIELD_FAILRATIO)); storage.getAllCircuits().setHandler(event -> { context.assertTrue(event.succeeded()); JsonObject result = event.result(); assertJsonObjectContents(context, result, hash1, HALF_OPEN, "/path/to/hash_1", 60); assertJsonObjectContents(context, result, hash2, CLOSED, "/path/to/hash_2", 20); assertJsonObjectContents(context, result, hash3, OPEN, "/path/to/hash_3", 99); async.complete(); }); }
@Test public void testGetAllCircuitsNoCircuits(TestContext context){ Async async = context.async(); context.assertEquals(0L, jedis.scard(STORAGE_ALL_CIRCUITS)); storage.getAllCircuits().setHandler(event -> { context.assertTrue(event.succeeded()); context.assertNotNull(event.result()); JsonObject result = event.result(); context.assertEquals(new JsonObject(), result); async.complete(); }); }