/** * Expects a channel creation. * * @return the channel which will be returned at {@link #create(WaveId)} */ public MockViewChannel expectCreate() { MockViewChannel ch = new MockViewChannel(); channels.add(ch); return ch; }
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 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 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; }
/** * 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 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(); }
MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); view.expectClose(); viewListener.onClosed(); view2.expectOpen(IdFilters.ALL_IDS, createKnownVersions(WAVELET_ID_1, 1, SIG1)); scheduler.command.execute(); ViewChannel.Listener viewListener2 = view2.takeListener(); viewListener2.onConnected(); view2.expectSubmitDelta(WAVELET_ID_1, delta); reconnectChannel(viewListener2, WAVELET_ID_1, chInfo1.initialVersion, chInfo1.initialSignature); viewListener2.onOpenFinished();
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(); }
MockViewChannel view = openMux(); muxListener.verifyNoMoreInteractions(); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected(); view.expectClose(); viewListener.onClosed(); view.expectOpen(IdFilters.ALL_IDS, createKnownVersions(WAVELET_ID_1, 1, SIG1)); assertNotNull(scheduler.command); scheduler.command.execute(); scheduler.command = null; viewListener = view.takeListener(); viewListener.onConnected();
view.expectOpen(IdFilters.ALL_IDS, NO_KNOWN_WAVELETS); mux.open(muxListener, IdFilters.ALL_IDS); ViewChannel.Listener viewListener = view.takeListener(); viewListener.onConnected();
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 } }
/** * 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(); }
private MockViewChannel openMux(IdFilter idFilter) { MockViewChannel viewChannel = viewFactory.expectCreate(); viewChannel.expectOpen(idFilter, NO_KNOWN_WAVELETS); mux.open(muxListener, idFilter); return viewChannel; }
public void testReceivedSnapshotClobbersExistingChannel() throws ChannelException { MockViewChannel viewChannel = openMux(); ViewChannel.Listener viewListener = viewChannel.takeListener(); muxListener.verifyNoMoreInteractions(); viewListener.onConnected(); ObservableWaveletData snapshotUpdate = createSnapshot(WAVELET_ID_1, 1, SIG1); HashedVersion committed = HashedVersion.unsigned(0); viewListener.onSnapshot(WAVELET_ID_1, snapshotUpdate, committed, null); OperationChannel ch = muxListener.verifyOperationChannelCreated(snapshotUpdate, Accessibility.READ_WRITE); // The second snapshot may have a non-zero version. committed = HashedVersion.unsigned(1); ch = checkSendClobberingSnapshot(viewListener, ch, snapshotUpdate, committed); // Repeat the clobbering with a higher version. committed = HashedVersion.unsigned(2000); checkSendClobberingSnapshot(viewListener, ch, snapshotUpdate, committed); }
/** * Sends an operation on an operation channel and expects the delta to * be submitted to the view. */ private static WaveletDelta checkSendDelta(MockViewChannel viewChannel, OperationChannel opChannel, HashedVersion initialVersion, WaveletId expectedWaveletId) throws ChannelException { WaveletOperation op = createOp(); WaveletDelta delta = createDelta(initialVersion, op); viewChannel.expectSubmitDelta(expectedWaveletId, delta); opChannel.send(op); return delta; }
/** * Acks a delta and checks that the fake version-incrementing op is received * from the operation channel. */ private static void checkAckDelta(MockViewChannel viewChannel, OperationChannel opChannel, MockOperationChannelListener opChannelListener, int ackedOps, long version, byte[] signature) throws ChannelException { viewChannel.ackSubmit(ackedOps, version, signature); opChannelListener.checkOpsReceived(1); opChannelListener.clear(); assertNotNull(opChannel.receive()); opChannelListener.checkOpsReceived(0); opChannelListener.clear(); }
/** * 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; }
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(); }