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 }
private void checkOpenFinished() { muxListener.verifyOpenFinished(); }
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(); }
private OperationChannel checkSendClobberingSnapshot(ViewChannel.Listener viewListener, OperationChannel channelToClobber, ObservableWaveletData snapshotUpdate, HashedVersion committed) throws ChannelException { viewListener.onSnapshot(WAVELET_ID_1, snapshotUpdate, committed, null); muxListener.verifyOperationChannelRemoved(channelToClobber); return muxListener.verifyOperationChannelCreated(snapshotUpdate, Accessibility.READ_WRITE); }
muxListener.verifyNoMoreInteractions(); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setChannelId(CHANNEL_ID)); FakeWaveViewServiceUpdate update = new FakeWaveViewServiceUpdate() .setLastCommittedVersion(HashedVersion.unsigned(0)); openCallback.onUpdate(update); OperationChannel channel = muxListener.verifyOperationChannelCreated( update.getWaveletSnapshot(), Accessibility.READ_WRITE); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setMarker(false)); muxListener.verifyOpenFinished();
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); }
@Override public void setUp() { ViewChannelImpl.setMaxViewChannelsPerWave(Integer.MAX_VALUE); viewFactory = new MockViewChannel.Factory(); UnsavedDataListenerFactory fakeListenerFactory = new UnsavedDataListenerFactory() { @Override public UnsavedDataListener create(WaveletId waveletId) { return null; } @Override public void destroy(WaveletId waveletId) { } }; mux = new OperationChannelMultiplexerImpl(WAVE_ID, viewFactory, DATA_FACTORY, LOGGERS, fakeListenerFactory, new ImmediateExcecutionScheduler(), FakeHashedVersionFactory.INSTANCE, null); muxListener = new MockMuxListener(); }
muxListener.verifyNoMoreInteractions(); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setChannelId(CHANNEL_ID)); FakeWaveViewServiceUpdate update = new FakeWaveViewServiceUpdate() .setLastCommittedVersion(HashedVersion.unsigned(0)); openCallback.onUpdate(update); OperationChannel channel = muxListener.verifyOperationChannelCreated( update.getWaveletSnapshot(), Accessibility.READ_WRITE); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setMarker(false)); muxListener.verifyOpenFinished();
private OperationChannel checkSendClobberingSnapshot(ViewChannel.Listener viewListener, OperationChannel channelToClobber, ObservableWaveletData snapshotUpdate, HashedVersion committed) throws ChannelException { viewListener.onSnapshot(WAVELET_ID_1, snapshotUpdate, committed, null); muxListener.verifyOperationChannelRemoved(channelToClobber); return muxListener.verifyOperationChannelCreated(snapshotUpdate, Accessibility.READ_WRITE); }
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); }
@Override public void setUp() { ViewChannelImpl.setMaxViewChannelsPerWave(Integer.MAX_VALUE); viewFactory = new MockViewChannel.Factory(); UnsavedDataListenerFactory fakeListenerFactory = new UnsavedDataListenerFactory() { @Override public UnsavedDataListener create(WaveletId waveletId) { return null; } @Override public void destroy(WaveletId waveletId) { } }; mux = new OperationChannelMultiplexerImpl(WAVE_ID, viewFactory, DATA_FACTORY, LOGGERS, fakeListenerFactory, new ImmediateExcecutionScheduler(), FakeHashedVersionFactory.INSTANCE); muxListener = new MockMuxListener(); }
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 }
muxListener.verifyNoMoreInteractions(); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setChannelId(CHANNEL_ID)); FakeWaveViewServiceUpdate update = new FakeWaveViewServiceUpdate() .setLastCommittedVersion(HashedVersion.unsigned(0)); openCallback.onUpdate(update); OperationChannel channel = muxListener.verifyOperationChannelCreated( update.getWaveletSnapshot(), Accessibility.READ_WRITE); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setMarker(false)); muxListener.verifyOpenFinished();
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(); }
private OperationChannel createOperationChannel(WaveletId waveletId, ParticipantId address) { mux.createOperationChannel(waveletId, address); return muxListener.verifyOperationChannelCreated( DATA_FACTORY.create( new EmptyWaveletSnapshot(WAVE_ID, waveletId, address, HashedVersion.unsigned(0), 1273307837000L /* arbitrary time */)), Accessibility.READ_WRITE); }
@Override protected void setUp() { ViewChannelImpl.setMaxViewChannelsPerWave(Integer.MAX_VALUE); waveViewService = new MockWaveViewService(); viewFactory = ViewChannelImpl.factory(waveViewService, logger); fakeUnsavedDataListener = new FakeUnsavedDataListener(); mux = new OperationChannelMultiplexerImpl(WAVE_ID, viewFactory, DATA_FACTORY, LOGGERS, new UnsavedDataListenerFactory() { public UnsavedDataListener create(WaveletId dummy) { return fakeUnsavedDataListener; } public void destroy(WaveletId waveletId) { } }, new ImmediateExcecutionScheduler(), FakeHashedVersionFactory.INSTANCE, null); muxListener = new MockMuxListener(); }
private void checkOpenFinished() { muxListener.verifyOpenFinished(); }
/** * 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); }
muxListener.verifyNoMoreInteractions(); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setChannelId(CHANNEL_ID)); FakeWaveViewServiceUpdate update = new FakeWaveViewServiceUpdate() .setLastCommittedVersion(HashedVersion.unsigned(0)); openCallback.onUpdate(update); OperationChannel channel = muxListener.verifyOperationChannelCreated( update.getWaveletSnapshot(), Accessibility.READ_WRITE); openCallback.onUpdate(new FakeWaveViewServiceUpdate().setMarker(false)); muxListener.verifyOpenFinished();
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); }