CircuitBreakerFactory { public synchronized CircuitBreaker createCircuitBreaker(String name, CircuitBreakerConfig config) { CircuitBreaker circuitBreaker = findCircuitBreaker(name); if (circuitBreaker == null) { circuitBreaker = new CircuitBreaker(name); configureCircuitBreaker(name, circuitBreaker, config); addCircuitBreakerToMap(name, circuitBreaker); } return circuitBreaker; }  synchronized CircuitBreaker createCircuitBreaker(String name,
            CircuitBreakerConfig config); void setProperties(Properties properties); CircuitBreaker findCircuitBreaker(String name); Set<String> getCircuitBreakerNames(); static final String CONFIG_KEY_PREFIX; static final String LIMIT_KEY; static final String WINDOWMILLIS_KEY; static final String RESETMILLIS_KEY; }
@Test public void testCreateCircuitBreaker() { CircuitBreaker breaker = factory.createCircuitBreaker("testCreate", config); checkBreaker(breaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS); }
@Test public void testCreateDuplicateCircuitBreaker() { String name = "testCreate"; CircuitBreaker createdBreaker = factory.createCircuitBreaker(name, config); CircuitBreaker secondBreaker = factory.createCircuitBreaker(name, config); assertSame(createdBreaker, secondBreaker); checkBreaker(createdBreaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS); }
@Test public void testCreateCircuitBreakerEmptyConfig() { CircuitBreakerConfig emptyConfig = new CircuitBreakerConfig(-1, new DefaultFailureInterpreter()); CircuitBreaker breaker = factory.createCircuitBreaker("testCreateEmpty", emptyConfig); checkBreaker(breaker, 0, 0, 15000L); }
@Test public void testCreateCircuitBreakerNullFailureInterpreter() { CircuitBreakerConfig emptyConfig = new CircuitBreakerConfig(-1, null); CircuitBreaker breaker = factory.createCircuitBreaker("testCreateEmpty", emptyConfig); checkBreakerNoFailureInterpreter(breaker, 15000L); }