/** * 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(); }
/** * 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 ConnectedChannel createOperationChannel(WaveletId waveletId, ParticipantId address) { mux.createOperationChannel(waveletId, address); OperationChannel channel = muxListener.verifyOperationChannelCreated(createSnapshot( WAVELET_ID_1, 0, NOSIG), Accessibility.READ_WRITE); MockOperationChannelListener channelListener = new MockOperationChannelListener(); channel.setListener(channelListener); return new ConnectedChannel(channel, channelListener); }
private ConnectedChannel createOperationChannel(WaveletId waveletId, ParticipantId address) { mux.createOperationChannel(waveletId, address); OperationChannel channel = muxListener.verifyOperationChannelCreated(createSnapshot( WAVELET_ID_1, 0, NOSIG), Accessibility.READ_WRITE); MockOperationChannelListener channelListener = new MockOperationChannelListener(); channel.setListener(channelListener); return new ConnectedChannel(channel, channelListener); }
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 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); }
ObservableWaveletData update = createSnapshot(WAVELET_ID_1, 1, SIG1); try { viewListener.onSnapshot(WAVELET_ID_1, update, null, null);
ObservableWaveletData update = createSnapshot(WAVELET_ID_1, 1, SIG1); try { viewListener.onSnapshot(WAVELET_ID_1, update, null, null);
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 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 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 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 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(); }