/** * Reconnects a view with a single operation channel and checks that the channel * is usable and expectations are satisfied. */ private void reconnectViewAndCheckEverythingStillWorks(MockViewChannel view, ConnectionInfo chInfo, ConnectedChannel ch) throws ChannelException { // Perform the reconnect. ViewChannel.Listener viewListener2 = reconnectView(view, chInfo); ch.listener.checkOpsReceived(0); // Check everything still works. checkReceiveAndSend(viewListener2, view, ch, WAVELET_ID_1, chInfo.initialVersion); view.checkExpectationsSatisified(); } }
/** * Reconnects a view with a single operation channel and checks that the channel * is usable and expectations are satisfied. */ private void reconnectViewAndCheckEverythingStillWorks(MockViewChannel view, ConnectionInfo chInfo, ConnectedChannel ch) throws ChannelException { // Perform the reconnect. ViewChannel.Listener viewListener2 = reconnectView(view, chInfo); ch.listener.checkOpsReceived(0); // Check everything still works. checkReceiveAndSend(viewListener2, view, ch, WAVELET_ID_1, chInfo.initialVersion); view.checkExpectationsSatisified(); } }
checkReceiveAndSend(viewListener2, view2, ch, chInfo.waveletId, chInfo.initialVersion + 1); } else { checkReceiveAndSend(viewListener2, view2, ch, chInfo.waveletId, chInfo.initialVersion);
checkReceiveAndSend(viewListener2, view2, ch, chInfo.waveletId, chInfo.initialVersion + 1); } else { checkReceiveAndSend(viewListener2, view2, ch, chInfo.waveletId, chInfo.initialVersion);
checkReceiveAndSend(viewListener2, view2, ch1, WAVELET_ID_1, chInfo1.initialVersion); checkReceiveAndSend(viewListener2, view2, ch2, WAVELET_ID_2, chInfo2.initialVersion);
checkReceiveAndSend(viewListener2, view2, ch1, WAVELET_ID_1, chInfo1.initialVersion); checkReceiveAndSend(viewListener2, view2, ch2, WAVELET_ID_2, chInfo2.initialVersion);
public void testNewWaveletSuppressesSnapshot() throws ChannelException { MockViewChannel view = openMux(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); triggerAndCheckOpenFinished(viewListener); ConnectedChannel ch = createOperationChannel(WAVELET_ID_1, USER_ID); // Send and ack first op. checkSendDelta(view, ch.channel, HashedVersion.unsigned(0), WAVELET_ID_1); view.checkExpectationsSatisified(); checkAckDelta(view, ch.channel, ch.listener, 1, 1, SIG1); // Drop the empty snapshot sent by the server. ObservableWaveletData snapshot = createSnapshot(WAVELET_ID_1, 0, NOSIG); HashedVersion committed = HashedVersion.unsigned(0); viewListener.onSnapshot(snapshot.getWaveletId(), snapshot, committed, null); muxListener.verifyNoMoreInteractions(); // Now CC should have sent the first client delta so it's acked. view.checkExpectationsSatisified(); checkReceiveAndSend(viewListener, view, ch, WAVELET_ID_1, 1); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testNewWaveletSuppressesSnapshot() throws ChannelException { MockViewChannel view = openMux(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); triggerAndCheckOpenFinished(viewListener); ConnectedChannel ch = createOperationChannel(WAVELET_ID_1, USER_ID); // Send and ack first op. checkSendDelta(view, ch.channel, HashedVersion.unsigned(0), WAVELET_ID_1); view.checkExpectationsSatisified(); checkAckDelta(view, ch.channel, ch.listener, 1, 1, SIG1); // Drop the empty snapshot sent by the server. ObservableWaveletData snapshot = createSnapshot(WAVELET_ID_1, 0, NOSIG); HashedVersion committed = HashedVersion.unsigned(0); viewListener.onSnapshot(snapshot.getWaveletId(), snapshot, committed, null); muxListener.verifyNoMoreInteractions(); // Now CC should have sent the first client delta so it's acked. view.checkExpectationsSatisified(); checkReceiveAndSend(viewListener, view, ch, WAVELET_ID_1, 1); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
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 testOpenWithKnownWaveletWaitsForReconnection() throws ChannelException { long knownVersion = 40; byte[] knownSig = SIG1; ObservableWaveletData knownSnapshot = createSnapshot(WAVELET_ID_1, knownVersion, knownSig); MockViewChannel view = openMuxWithKnownWavelet(knownSnapshot); // The channel is "connected" though the underlying view isn't. ConnectedChannel ch = expectConnectedChannel(knownSnapshot, Accessibility.READ_WRITE); checkOpenFinished(); // Attempt to send a client op. Submission should be held until the view // connects and the channel receives the empty reconnection delta. WaveletOperation clientOp = createOp(); WaveletDelta delta = createDelta(HashedVersion.of(knownVersion, knownSig), clientOp); ch.channel.send(clientOp); ch.listener.checkOpsReceived(0); // Connect the underlying view. ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive the reconnection delta, expect the client delta submission. view.expectSubmitDelta(WAVELET_ID_1, delta); reconnectChannel(viewListener, WAVELET_ID_1, knownVersion, knownSig); // Don't expect this empty delta from the channel. ch.listener.checkOpsReceived(0); assertNull(ch.channel.receive()); checkAckDelta(view, ch.channel, ch.listener, 1, knownVersion + 1, SIG2); // No snapshot, but check we can receive and send deltas on the channel. checkReceiveAndSend(viewListener, view, ch, WAVELET_ID_1, knownVersion + 1); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testOpenWithKnownWaveletWaitsForReconnection() throws ChannelException { long knownVersion = 40; byte[] knownSig = SIG1; ObservableWaveletData knownSnapshot = createSnapshot(WAVELET_ID_1, knownVersion, knownSig); MockViewChannel view = openMuxWithKnownWavelet(knownSnapshot); // The channel is "connected" though the underlying view isn't. ConnectedChannel ch = expectConnectedChannel(knownSnapshot, Accessibility.READ_WRITE); checkOpenFinished(); // Attempt to send a client op. Submission should be held until the view // connects and the channel receives the empty reconnection delta. WaveletOperation clientOp = createOp(); WaveletDelta delta = createDelta(HashedVersion.of(knownVersion, knownSig), clientOp); ch.channel.send(clientOp); ch.listener.checkOpsReceived(0); // Connect the underlying view. ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); // Receive the reconnection delta, expect the client delta submission. view.expectSubmitDelta(WAVELET_ID_1, delta); reconnectChannel(viewListener, WAVELET_ID_1, knownVersion, knownSig); // Don't expect this empty delta from the channel. ch.listener.checkOpsReceived(0); assertNull(ch.channel.receive()); checkAckDelta(view, ch.channel, ch.listener, 1, knownVersion + 1, SIG2); // No snapshot, but check we can receive and send deltas on the channel. checkReceiveAndSend(viewListener, view, ch, WAVELET_ID_1, knownVersion + 1); view.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
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 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(); }
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(); }