private ConnectedChannel connectChannelSnapshot(ViewChannel.Listener viewListener, ConnectionInfo info) throws ChannelException { return connectChannelSnapshot(viewListener, info.snapshot, info.initialHashedVersion); }
private ConnectedChannel connectChannelSnapshot(ViewChannel.Listener viewListener, ConnectionInfo info) throws ChannelException { return connectChannelSnapshot(viewListener, info.snapshot, info.initialHashedVersion); }
public void testMuxCloseClosesViewAndChannels() throws ChannelException { final ConnectionInfo chInfo1 = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final ConnectionInfo chInfo2 = new ConnectionInfo(WAVELET_ID_2, 20, SIG2); MockViewChannel view = openMux(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch1 = connectChannelSnapshot(viewListener, chInfo1); ConnectedChannel ch2 = connectChannelSnapshot(viewListener, chInfo2); triggerAndCheckOpenFinished(viewListener); view.expectClose(); mux.close(); // Receive lagging delta from view channel, expect nothing. final List<TransformedWaveletDelta> update = createServerDeltaList(1, 1, SIG4); viewListener.onUpdate(chInfo1.waveletId, update, null, null); ch1.listener.checkOpsReceived(0); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testReceivedSnapshotOpensChannel() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); muxListener.verifyNoMoreInteractions(); viewListener.onConnected(); ConnectedChannel opChannel = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); // Also proves that an expected (initial) snapshot doesn't clobber the channel }
public void testReceivedSnapshotOpensChannel() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); muxListener.verifyNoMoreInteractions(); viewListener.onConnected(); ConnectedChannel opChannel = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); // Also proves that an expected (initial) snapshot doesn't clobber the channel }
public void testMuxCloseClosesViewAndChannels() throws ChannelException { final ConnectionInfo chInfo1 = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final ConnectionInfo chInfo2 = new ConnectionInfo(WAVELET_ID_2, 20, SIG2); MockViewChannel view = openMux(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch1 = connectChannelSnapshot(viewListener, chInfo1); ConnectedChannel ch2 = connectChannelSnapshot(viewListener, chInfo2); triggerAndCheckOpenFinished(viewListener); view.expectClose(); mux.close(); // Receive lagging delta from view channel, expect nothing. final List<TransformedWaveletDelta> update = createServerDeltaList(1, 1, SIG4); viewListener.onUpdate(chInfo1.waveletId, update, null, null); ch1.listener.checkOpsReceived(0); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testOpReceivedOnChannel() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final int serverOps = 1; final byte[] finalSignature = SIG2; MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Receive a delta. checkReceiveDelta(viewListener, ch.channel, ch.listener, WAVELET_ID_1, chInfo.initialVersion, serverOps, finalSignature); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testOpReceivedOnChannel() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final int serverOps = 1; final byte[] finalSignature = SIG2; MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Receive a delta. checkReceiveDelta(viewListener, ch.channel, ch.listener, WAVELET_ID_1, chInfo.initialVersion, serverOps, finalSignature); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testAckResultsInChannelOp() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final byte[] finalSignature = SIG2; MockViewChannel view = openMux(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); checkSendDelta(view, ch.channel, chInfo.initialHashedVersion, WAVELET_ID_1); checkAckDelta(view, ch.channel, ch.listener, 1, 2, finalSignature); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testAckResultsInChannelOp() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final byte[] finalSignature = SIG2; MockViewChannel view = openMux(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); checkSendDelta(view, ch.channel, chInfo.initialHashedVersion, WAVELET_ID_1); checkAckDelta(view, ch.channel, ch.listener, 1, 2, finalSignature); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testMuxFailsAfterChannelCorrupt() throws ChannelException { final ConnectionInfo chInfo1 = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo1); triggerAndCheckOpenFinished(viewListener); // Receive a message that should not be received. ObservableWaveletData update = createSnapshot(WAVELET_ID_1, 1, SIG1); view.expectClose(); try { viewListener.onSnapshot(WAVELET_ID_1, update, null, null); fail("Expected exception corruption"); } catch (ChannelException ex) { // Expected } }
public void testChannelSendSubmitsToView() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Send an operation and check view submission WaveletOperation op = createOp(); WaveletDelta delta = createDelta(chInfo.initialHashedVersion, op); viewChannel.expectSubmitDelta(WAVELET_ID_1, delta); ch.channel.send(op); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testChannelSendSubmitsToView() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Send an operation and check view submission WaveletOperation op = createOp(); WaveletDelta delta = createDelta(chInfo.initialHashedVersion, op); viewChannel.expectSubmitDelta(WAVELET_ID_1, delta); ch.channel.send(op); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testMuxFailsAfterChannelCorrupt() throws ChannelException { final ConnectionInfo chInfo1 = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo1); triggerAndCheckOpenFinished(viewListener); // Receive a message that should not be received. ObservableWaveletData update = createSnapshot(WAVELET_ID_1, 1, SIG1); view.expectClose(); try { viewListener.onSnapshot(WAVELET_ID_1, update, null, null); fail("Expected exception corruption"); } catch (ChannelException ex) { // Expected } }
public void testOpsReceivedAndChannelClobbered() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final int serverOps = 1; final byte[] finalSignature = SIG2; MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Receive a delta. checkReceiveDelta(viewListener, ch.channel, ch.listener, WAVELET_ID_1, chInfo.initialVersion, serverOps, finalSignature); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); // Now receive a snapshot and it should clobber the existing channel HashedVersion committed = HashedVersion.of(1000000L, SIG3); ObservableWaveletData update = createSnapshot(WAVELET_ID_1, committed.getVersion(), committed.getHistoryHash()); checkSendClobberingSnapshot(viewListener, ch.channel, update, committed); }
public void testOpsReceivedAndChannelClobbered() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); final int serverOps = 1; final byte[] finalSignature = SIG2; MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); viewListener.onConnected(); ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Receive a delta. checkReceiveDelta(viewListener, ch.channel, ch.listener, WAVELET_ID_1, chInfo.initialVersion, serverOps, finalSignature); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); // Now receive a snapshot and it should clobber the existing channel HashedVersion committed = HashedVersion.of(1000000L, SIG3); ObservableWaveletData update = createSnapshot(WAVELET_ID_1, committed.getVersion(), committed.getHistoryHash()); checkSendClobberingSnapshot(viewListener, ch.channel, update, committed); }
public void testMuxReconnectsAfterDisconnectWithOutstandingSubmit() throws ChannelException { final ConnectionInfo chInfo1 = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo1); triggerAndCheckOpenFinished(viewListener); // Send but don't ack delta. WaveletDelta delta = checkSendDelta(view, ch.channel, chInfo1.initialHashedVersion, WAVELET_ID_1); // Reconnect channel. MockViewChannel view2 = failViewAndExpectReconnection(viewListener, view, "View failed with outstanding submit", createKnownVersions(WAVELET_ID_1, 1, SIG1)); // Expect retransmit of the sent delta after reconnect. view2.expectSubmitDelta(WAVELET_ID_1, delta); ViewChannel.Listener viewListener2 = reconnectView(view2, chInfo1); muxListener.verifyNoMoreInteractions(); // No callback on reconnection. checkAckDelta(view2, ch.channel, ch.listener, 1, chInfo1.initialVersion + 1, SIG1); checkReceiveAndSend(viewListener2, view2, ch, WAVELET_ID_1, chInfo1.initialVersion + 1); // If the submit is then acked, it should be ignored. view.ackSubmit(1, chInfo1.initialVersion + 1, SIG5); view.checkExpectationsSatisified(); view2.checkExpectationsSatisified(); ch.listener.checkOpsReceived(0); muxListener.verifyNoMoreInteractions(); }
public void testMuxReconnectsAgainAfterReconnectFailure() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Disconnect, expect reconnection. view.expectClose(); MockViewChannel view2 = viewFactory.expectCreate(); view2.expectOpen(IdFilters.ALL_IDS, createKnownVersions(WAVELET_ID_1, 1, SIG1)); viewListener.onClosed(); ViewChannel.Listener viewListener2 = view2.takeListener(); // Disconnect, expect reconnection again. view2.expectClose(); MockViewChannel view3 = viewFactory.expectCreate(); view3.expectOpen(IdFilters.ALL_IDS, createKnownVersions(WAVELET_ID_1, 1, SIG1)); viewListener2.onClosed(); view2.checkExpectationsSatisified(); view3.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testMuxReconnectsAgainAfterReconnectFailure() throws ChannelException { final ConnectionInfo chInfo = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo); triggerAndCheckOpenFinished(viewListener); // Disconnect, expect reconnection. view.expectClose(); MockViewChannel view2 = viewFactory.expectCreate(); view2.expectOpen(IdFilters.ALL_IDS, createKnownVersions(WAVELET_ID_1, 1, SIG1)); viewListener.onClosed(); ViewChannel.Listener viewListener2 = view2.takeListener(); // Disconnect, expect reconnection again. view2.expectClose(); MockViewChannel view3 = viewFactory.expectCreate(); view3.expectOpen(IdFilters.ALL_IDS, createKnownVersions(WAVELET_ID_1, 1, SIG1)); viewListener2.onClosed(); view2.checkExpectationsSatisified(); view3.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testMuxReconnectsAfterSubmitFailure() throws ChannelException { final ConnectionInfo chInfo1 = new ConnectionInfo(WAVELET_ID_1, 1, SIG1); MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive initial snapshots. ConnectedChannel ch = connectChannelSnapshot(viewListener, chInfo1); triggerAndCheckOpenFinished(viewListener); // Send but don't ack delta. WaveletDelta delta = checkSendDelta(view, ch.channel, chInfo1.initialHashedVersion, WAVELET_ID_1); // Fail the submission, expecting reconnection. MockViewChannel view2 = failViewAndExpectReconnection(viewListener, view, "View failed with outstanding submit", createKnownVersions(WAVELET_ID_1, 1, SIG1)); // Expect retransmit of the sent delta after reconnect. view2.expectSubmitDelta(WAVELET_ID_1, delta); ViewChannel.Listener viewListener2 = reconnectView(view2, chInfo1); muxListener.verifyNoMoreInteractions(); // No callback on reconnection. checkAckDelta(view2, ch.channel, ch.listener, 1, chInfo1.initialVersion + 1, SIG2); // If the first view later disconnects, it should be ignored viewListener.onException(new ChannelException("failed for testing", Recoverable.RECOVERABLE)); checkReceiveAndSend(viewListener2, view2, ch, WAVELET_ID_1, chInfo1.initialVersion + 1); view.checkExpectationsSatisified(); view2.checkExpectationsSatisified(); ch.listener.checkOpsReceived(0); muxListener.verifyNoMoreInteractions(); }