RedisQueueCircuitBreakerStorage implements QueueCircuitBreakerStorage { @Override public Future<Void> reOpenCircuit(PatternAndCircuitHash patternAndCircuitHash) { Future<Void> future = Future.future(); String circuitHash = patternAndCircuitHash.getCircuitHash(); List<String> keys = Arrays.asList( buildInfosKey(circuitHash), STORAGE_HALFOPEN_CIRCUITS, STORAGE_OPEN_CIRCUITS ); List<String> arguments = Collections.singletonList(circuitHash); ReOpenCircuitRedisCommand cmd = new ReOpenCircuitRedisCommand(reOpenCircuitLuaScriptState, 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 testReOpenCircuit(TestContext context){ Async async = context.async(); String circuitHash = "anotherCircuitHash"; context.assertFalse(jedis.exists(STORAGE_ALL_CIRCUITS)); context.assertFalse(jedis.exists(STORAGE_HALFOPEN_CIRCUITS)); context.assertFalse(jedis.exists(STORAGE_OPEN_CIRCUITS)); writeQueueCircuitStateToDatabase(circuitHash, HALF_OPEN); writeQueueCircuitFailPercentageToDatabase(circuitHash, 50); addToCircuitsSets(HALF_OPEN, "a"); addToCircuitsSets(HALF_OPEN, circuitHash); addToCircuitsSets(HALF_OPEN, "b"); addToCircuitsSets(HALF_OPEN, "c"); addToCircuitsSets(OPEN, "d"); addToCircuitsSets(OPEN, "e"); addToCircuitsSets(OPEN, "f"); addToCircuitsSets(OPEN, "g"); addToCircuitsSets(OPEN, "h"); context.assertEquals(9L, jedis.scard(STORAGE_ALL_CIRCUITS)); context.assertEquals(4L, jedis.scard(STORAGE_HALFOPEN_CIRCUITS)); context.assertEquals(5L, jedis.scard(STORAGE_OPEN_CIRCUITS)); PatternAndCircuitHash patternAndCircuitHash = buildPatternAndCircuitHash("/anotherCircuit", circuitHash); storage.reOpenCircuit(patternAndCircuitHash).setHandler(event -> { context.assertTrue(event.succeeded()); context.assertTrue(jedis.exists(STORAGE_ALL_CIRCUITS)); context.assertTrue(jedis.exists(STORAGE_HALFOPEN_CIRCUITS)); context.assertTrue(jedis.exists(STORAGE_OPEN_CIRCUITS)); assertStateAndErroPercentage(context, circuitHash, OPEN, 50); context.assertEquals(3L, jedis.scard(STORAGE_HALFOPEN_CIRCUITS)); Set<String> halfOpenCircuits = jedis.smembers(STORAGE_HALFOPEN_CIRCUITS); context.assertTrue(halfOpenCircuits.contains("a")); context.assertTrue(halfOpenCircuits.contains("b")); context.assertTrue(halfOpenCircuits.contains("c")); context.assertFalse(halfOpenCircuits.contains(circuitHash)); context.assertEquals(9L, jedis.scard(STORAGE_ALL_CIRCUITS)); Set<String> allCircuits = jedis.smembers(STORAGE_ALL_CIRCUITS); context.assertTrue(allCircuits.contains("a")); context.assertTrue(allCircuits.contains("b")); context.assertTrue(allCircuits.contains("c")); context.assertTrue(allCircuits.contains("d")); context.assertTrue(allCircuits.contains("e")); context.assertTrue(allCircuits.contains("f")); context.assertTrue(allCircuits.contains("g")); context.assertTrue(allCircuits.contains("h")); context.assertTrue(allCircuits.contains(circuitHash)); context.assertEquals(6L, jedis.scard(STORAGE_OPEN_CIRCUITS)); Set<String> openCircuits = jedis.smembers(STORAGE_OPEN_CIRCUITS); context.assertTrue(openCircuits.contains("d")); context.assertTrue(openCircuits.contains("e")); context.assertTrue(openCircuits.contains("f")); context.assertTrue(openCircuits.contains("g")); context.assertTrue(openCircuits.contains("h")); context.assertTrue(openCircuits.contains(circuitHash)); async.complete(); }); }