@Override
    public synchronized void stateChanged(CuratorFramework client, ConnectionState newState) {
        if (circuitBreaker.isOpen()) {
            handleOpenStateChange(newState);
        } else {
            handleClosedStateChange(newState);
        }
    }
@Test
    public void testResetsAfterReconnect() throws Exception {
        RecordingListener recordingListener = new RecordingListener();
        TestRetryPolicy retryPolicy = new TestRetryPolicy();
        CircuitBreakingConnectionStateListener listener =
                new CircuitBreakingConnectionStateListener(dummyClient, recordingListener, retryPolicy, service);

        synchronized (listener) // don't let retry policy run while we're pushing state changes
        {
            listener.stateChanged(dummyClient, ConnectionState.LOST);
            listener.stateChanged(dummyClient, ConnectionState.LOST); // second LOST ignored
        }
        assertEquals(timing.takeFromQueue(recordingListener.stateChanges), ConnectionState.LOST);
        assertTrue(recordingListener.stateChanges.isEmpty());

        listener.stateChanged(dummyClient, ConnectionState.RECONNECTED); // causes circuit to close on next retry
        assertEquals(timing.takeFromQueue(recordingListener.stateChanges), ConnectionState.RECONNECTED);
    }