RedisQueueCircuitBreakerStorage implements QueueCircuitBreakerStorage { @Override public Future<Long> setOpenCircuitsToHalfOpen() { Future<Long> future = Future.future(); List<String> keys = Arrays.asList(STORAGE_HALFOPEN_CIRCUITS, STORAGE_OPEN_CIRCUITS); List<String> arguments = Arrays.asList(STORAGE_PREFIX, STORAGE_INFOS_SUFFIX); HalfOpenCircuitRedisCommand cmd = new HalfOpenCircuitRedisCommand(halfOpenCircuitLuaScriptState, 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 testSetOpenCircuitsToHalfOpen(TestContext context){ Async async = context.async(); context.assertFalse(jedis.exists(STORAGE_ALL_CIRCUITS)); context.assertFalse(jedis.exists(STORAGE_HALFOPEN_CIRCUITS)); context.assertFalse(jedis.exists(STORAGE_OPEN_CIRCUITS)); String h1 = "hash_1"; String h2 = "hash_2"; String h3 = "hash_3"; String h4 = "hash_4"; String h5 = "hash_5"; buildCircuitEntry(h1, HALF_OPEN); buildCircuitEntry(h2, OPEN); buildCircuitEntry(h3, OPEN); buildCircuitEntry(h4, OPEN); buildCircuitEntry(h5, HALF_OPEN); context.assertEquals(5L, jedis.scard(STORAGE_ALL_CIRCUITS)); context.assertEquals(2L, jedis.scard(STORAGE_HALFOPEN_CIRCUITS)); context.assertEquals(3L, jedis.scard(STORAGE_OPEN_CIRCUITS)); assertHashInHalfOpenCircuitsSet(context, h1, 2); assertHashInHalfOpenCircuitsSet(context, h5, 2); assertHashInOpenCircuitsSet(context, h2, 3); assertHashInOpenCircuitsSet(context, h3, 3); assertHashInOpenCircuitsSet(context, h4, 3); assertState(context, h1, HALF_OPEN); assertState(context, h2, OPEN); assertState(context, h3, OPEN); assertState(context, h4, OPEN); assertState(context, h5, HALF_OPEN); storage.setOpenCircuitsToHalfOpen().setHandler(event -> { context.assertTrue(event.succeeded()); context.assertEquals(5L, jedis.scard(STORAGE_ALL_CIRCUITS)); context.assertEquals(5L, jedis.scard(STORAGE_HALFOPEN_CIRCUITS)); context.assertEquals(0L, jedis.scard(STORAGE_OPEN_CIRCUITS)); assertHashInHalfOpenCircuitsSet(context, h1, 5); assertHashInHalfOpenCircuitsSet(context, h2, 5); assertHashInHalfOpenCircuitsSet(context, h3, 5); assertHashInHalfOpenCircuitsSet(context, h4, 5); assertHashInHalfOpenCircuitsSet(context, h5, 5); assertState(context, h1, HALF_OPEN); assertState(context, h2, HALF_OPEN); assertState(context, h3, HALF_OPEN); assertState(context, h4, HALF_OPEN); assertState(context, h5, HALF_OPEN); async.complete(); }); }