@Override public void consume(WaveletOperation op) { try { target.send(op); } catch (ChannelException e) { throw new RuntimeException("Send failed, channel is broken", e); } } }
/** * 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; }
/** * 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; }
/** * Create a wave, send Op which is unacked and expect unsaved data. */ public void testCreatingWave() throws ChannelException { // Connect to the server mux.open(muxListener, IdFilters.ALL_IDS); muxListener.verifyNoMoreInteractions(); OperationChannel channel = createOperationChannel(WAVELET_ID_1, USER_NAME); channel.send(createAddParticipantOp()); // Expect the delta channel to not be ready, so we expect an open call, but // no success on open and no submit call going through. assertEquals(1, waveViewService.opens.size()); assertEquals(0, waveViewService.submits.size()); muxListener.verifyNoMoreInteractions(); // We do expect unsaved data. assertUnsavedDataInfo(1, 1, 0, 0, 0); // Now bail out of the connection with an op pending, should close. mux.close(); assertEquals(1, fakeUnsavedDataListener.closeCalls); }
/** * Create a wave, send Op which is unacked and expect unsaved data. */ public void testCreatingWave() throws ChannelException { // Connect to the server mux.open(muxListener, IdFilters.ALL_IDS); muxListener.verifyNoMoreInteractions(); OperationChannel channel = createOperationChannel(WAVELET_ID_1, USER_NAME); channel.send(createAddParticipantOp()); // Expect the delta channel to not be ready, so we expect an open call, but // no success on open and no submit call going through. assertEquals(1, waveViewService.opens.size()); assertEquals(0, waveViewService.submits.size()); muxListener.verifyNoMoreInteractions(); // We do expect unsaved data. assertUnsavedDataInfo(1, 1, 0, 0, 0); // Now bail out of the connection with an op pending, should close. mux.close(); assertEquals(1, fakeUnsavedDataListener.closeCalls); }
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(); }
channel.send(createAddParticipantOp()); assertEquals(1, waveViewService.submits.size()); WaveViewService.SubmitCallback submitCallback1 = waveViewService.lastSubmit().callback; channel.send(createAddParticipantOp()); assertEquals(2, waveViewService.submits.size()); WaveViewService.SubmitCallback submitCallback2 = waveViewService.lastSubmit().callback;
channel.send(createAddParticipantOp()); assertEquals(1, waveViewService.submits.size()); WaveViewService.SubmitCallback submitCallback1 = waveViewService.lastSubmit().callback; channel.send(createAddParticipantOp()); assertEquals(2, waveViewService.submits.size()); WaveViewService.SubmitCallback submitCallback2 = waveViewService.lastSubmit().callback;
ch2.channel.send(op); fail("Expected a channel exception"); } catch (ChannelException expected) {
ch2.channel.send(op); fail("Expected a channel exception"); } catch (ChannelException expected) {
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(); }