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 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 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 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 testReceivedSnapshotClobbersOnlyAppropriateChannel() 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); // This snapshot should clobber wavelet 1's channel committed = HashedVersion.of(1, SIG1); checkSendClobberingSnapshot(viewListener, ch, snapshotUpdate, committed); muxListener.verifyNoMoreInteractions(); // This snapshot should only create a new channel and nothing else viewListener.onSnapshot(WAVELET_ID_2, snapshotUpdate, committed, null); muxListener.verifyOperationChannelCreated(snapshotUpdate, Accessibility.READ_WRITE); muxListener.verifyNoMoreInteractions(); }
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); }
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); }
/** * 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 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(); }
/** * 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 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 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 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 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 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 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(); }