/** * 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(); } }
/** * Reconnects a mux on a view, returning the reconnected view's listener. */ private static ViewChannel.Listener reconnectView(MockViewChannel view, ConnectionInfo... channels) throws ChannelException { ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); for (ConnectionInfo chInfo : channels) { reconnectChannel(viewListener, chInfo.waveletId, chInfo.initialVersion, chInfo.initialSignature); } viewListener.onOpenFinished(); view.checkExpectationsSatisified(); return viewListener; }
/** * Reconnects a mux on a view, returning the reconnected view's listener. */ private static ViewChannel.Listener reconnectView(MockViewChannel view, ConnectionInfo... channels) throws ChannelException { ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); for (ConnectionInfo chInfo : channels) { reconnectChannel(viewListener, chInfo.waveletId, chInfo.initialVersion, chInfo.initialSignature); } viewListener.onOpenFinished(); view.checkExpectationsSatisified(); return viewListener; }
public void testMuxOpenOpensView() { // Connect to the server. MockViewChannel viewChannel = viewFactory.expectCreate(); viewChannel.expectOpen(IdFilters.ALL_IDS, NO_KNOWN_WAVELETS); mux.open(muxListener, IdFilters.ALL_IDS); viewChannel.takeListener().onConnected(); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
public void testMuxOpenOpensView() { // Connect to the server. MockViewChannel viewChannel = viewFactory.expectCreate(); viewChannel.expectOpen(IdFilters.ALL_IDS, NO_KNOWN_WAVELETS); mux.open(muxListener, IdFilters.ALL_IDS); viewChannel.takeListener().onConnected(); viewChannel.checkExpectationsSatisified(); muxListener.verifyNoMoreInteractions(); }
/** * Sends a ChannelException to a view listener and expects a new view to be opened * to reconnect it. * * @return the new mock view */ private MockViewChannel failViewAndExpectReconnection(ViewChannel.Listener viewListenerToFail, MockViewChannel failingView, String failureReason, Map<WaveletId, List<HashedVersion>> expectedReconnectionSigs) { failingView.expectClose(); MockViewChannel newView = viewFactory.expectCreate(); newView.expectOpen(IdFilters.ALL_IDS, expectedReconnectionSigs); viewListenerToFail.onException(new ChannelException(failureReason, Recoverable.RECOVERABLE)); viewListenerToFail.onClosed(); failingView.checkExpectationsSatisified(); return newView; }
/** * Sends a ChannelException to a view listener and expects a new view to be opened * to reconnect it. * * @return the new mock view */ private MockViewChannel failViewAndExpectReconnection(ViewChannel.Listener viewListenerToFail, MockViewChannel failingView, String failureReason, Map<WaveletId, List<HashedVersion>> expectedReconnectionSigs) { failingView.expectClose(); MockViewChannel newView = viewFactory.expectCreate(); newView.expectOpen(IdFilters.ALL_IDS, expectedReconnectionSigs); viewListenerToFail.onException(new ChannelException(failureReason, Recoverable.RECOVERABLE)); viewListenerToFail.onClosed(); failingView.checkExpectationsSatisified(); return newView; }
/** * Tests that the mux ignores known wavelets that don't match the * wavelet filter, hence will never receive updates from the server. */ public void testOpenWithKnownWaveletsIgnoresFilteredWavelets() { long knownVersion = 40; byte[] knownSig = SIG1; IdFilter onlyWavelet1 = IdFilter.ofPrefixes("w+1"); ObservableWaveletData knownSnapshot1 = createSnapshot(WAVELET_ID_1, knownVersion, knownSig); ObservableWaveletData knownSnapshot2 = createSnapshot(WAVELET_ID_2, 0, NOSIG); MockViewChannel view = viewFactory.expectCreate(); Map<WaveletId, List<HashedVersion>> expectedSigs = createKnownVersions(WAVELET_ID_1, knownVersion, knownSig); view.expectOpen(onlyWavelet1, expectedSigs); mux.open(muxListener, onlyWavelet1, Arrays.asList( createKnownWavelet(knownSnapshot1, knownVersion, knownSig, Accessibility.READ_WRITE), createKnownWavelet(knownSnapshot2, 0, NOSIG, Accessibility.READ_WRITE))); view.checkExpectationsSatisified(); }
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 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 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 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 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 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(); }