@Override public void consume(WaveletOperation op) { try { target.send(op); } catch (ChannelException e) { throw new RuntimeException("Send failed, channel is broken", e); } } }
/** * Registers a listener on an operation channel that sucks out operations as * soon as they appear, sending them to a target sink. * * @param channel channel from which operations are to be pulled * @param sink sink to which operations are to be pushed */ public static void start(OperationChannel channel, FlushingOperationSink<WaveletOperation> sink) { channel.setListener(new OperationSucker(channel, sink)); }
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(); }
private static void checkReceiveDelta(ViewChannel.Listener viewListener, OperationChannel opChannel, MockOperationChannelListener opChannelListener, WaveletId waveletId, long version, int numOps, byte[] signature) throws ChannelException { // Receive delta from view channel, expect ops on op channel. final List<TransformedWaveletDelta> update = createServerDeltaList(version, numOps, signature); viewListener.onUpdate(waveletId, update, null, null); opChannelListener.checkOpsReceived(1); opChannelListener.clear(); for (int i = 0; i < numOps; ++i) { assertNotNull(opChannel.receive()); } assertNull(opChannel.receive()); }
/** * @return the debug string of cc stack */ public String getCcDebugString() { return channel.getDebugString(); }
final Stacklet stacklet = channels.get(wavelet); stacklet.reset(); knownWavelets.put(wavelet, stacklet.getOperationChannel().getReconnectVersions());
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(); }
private static void checkReceiveDelta(ViewChannel.Listener viewListener, OperationChannel opChannel, MockOperationChannelListener opChannelListener, WaveletId waveletId, long version, int numOps, byte[] signature) throws ChannelException { // Receive delta from view channel, expect ops on op channel. final List<TransformedWaveletDelta> update = createServerDeltaList(version, numOps, signature); viewListener.onUpdate(waveletId, update, null, null); opChannelListener.checkOpsReceived(1); opChannelListener.clear(); for (int i = 0; i < numOps; ++i) { assertNotNull(opChannel.receive()); } assertNull(opChannel.receive()); }
/** * 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; }
private ConnectedChannel expectConnectedChannel(ObservableWaveletData knownSnapshot, Accessibility accessibility) { OperationChannel channel = muxListener.verifyOperationChannelCreated(knownSnapshot, accessibility); MockOperationChannelListener listener = new MockOperationChannelListener(); channel.setListener(listener); return new ConnectedChannel(channel, listener); }
/** * 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(); }
/** * 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; }
private ConnectedChannel expectConnectedChannel(ObservableWaveletData knownSnapshot, Accessibility accessibility) { OperationChannel channel = muxListener.verifyOperationChannelCreated(knownSnapshot, accessibility); MockOperationChannelListener listener = new MockOperationChannelListener(); channel.setListener(listener); return new ConnectedChannel(channel, listener); }
/** * 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(); }
/** * 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 testMuxCloseClosesAllUnsavedDataUpdaters() { mux.open(muxListener, IdFilters.ALL_IDS); MockOperationChannelListener listener1 = new MockOperationChannelListener(); MockOperationChannelListener listener2 = new MockOperationChannelListener(); OperationChannel ch1 = createOperationChannel(WAVELET_ID_1, USER_NAME); OperationChannel ch2 = createOperationChannel(WAVELET_ID_2, USER_NAME); ch1.setListener(listener1); ch2.setListener(listener2); mux.close(); assertEquals(2, 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 testMuxCloseClosesAllUnsavedDataUpdaters() { mux.open(muxListener, IdFilters.ALL_IDS); MockOperationChannelListener listener1 = new MockOperationChannelListener(); MockOperationChannelListener listener2 = new MockOperationChannelListener(); OperationChannel ch1 = createOperationChannel(WAVELET_ID_1, USER_NAME); OperationChannel ch2 = createOperationChannel(WAVELET_ID_2, USER_NAME); ch1.setListener(listener1); ch2.setListener(listener2); mux.close(); assertEquals(2, 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(); }