@Test
public void when_first_node_fails__then_second_node_should_connect() {

	RadixNode badPeer = mock(RadixNode.class);
	RadixNode goodPeer = mock(RadixNode.class);
	ReplaySubject<RadixNetworkState> networkState = ReplaySubject.create();
	networkState.onNext(new RadixNetworkState(ImmutableMap.of(
		badPeer, mockedNodeState(WebSocketStatus.DISCONNECTED),
		goodPeer, mockedNodeState(WebSocketStatus.DISCONNECTED)
	)));
	FindANodeEpic findANodeEpic = new FindANodeEpic(new GetFirstSelector());
	TestObserver<RadixNodeAction> testObserver = TestObserver.create();
	FindANodeRequestAction request = mock(FindANodeRequestAction.class);
	findANodeEpic.epic(
		Observable.<RadixNodeAction>just(request).concatWith(Observable.never()),
		networkState
	)
	.doOnNext(i -> {
		if (i.getNode().equals(badPeer)) {
			networkState.onNext(new RadixNetworkState(ImmutableMap.of(
				badPeer, mockedNodeState(WebSocketStatus.FAILED),
				goodPeer, mockedNodeState(WebSocketStatus.DISCONNECTED)
			)));
		} else {
			networkState.onNext(new RadixNetworkState(ImmutableMap.of(
				badPeer, mockedNodeState(WebSocketStatus.FAILED),
				goodPeer, mockedNodeState(WebSocketStatus.CONNECTED)
			)));
		}
	})
	.subscribe(testObserver);
	testObserver.awaitCount(4);
	testObserver.assertValueAt(0, u -> u instanceof ConnectWebSocketAction && u.getNode().equals(badPeer));
	testObserver.assertValueAt(1, u -> u instanceof ConnectWebSocketAction && u.getNode().equals(goodPeer));
	testObserver.assertValueAt(2, u -> u instanceof CloseWebSocketAction && u.getNode().equals(badPeer));
	testObserver.assertValueAt(3, u -> ((FindANodeResultAction) u).getRequest().equals(request) && u.getNode().equals(goodPeer));
}