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(); }
/** * Test simple reconnect. */ public void testSimpleReconnect() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); // Now disconnect server-side, forcing a reconnect. reconnectChannel(10, SIG1); // No new messages. listener.checkOpsReceived(0); checkExpectationsSatisfied(); }
@Override public void tearDown() { listener.clear(); }
/** * Test simple reconnect. */ public void testSimpleReconnect() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); // Now disconnect server-side, forcing a reconnect. reconnectChannel(10, SIG1); // No new messages. listener.checkOpsReceived(0); checkExpectationsSatisfied(); }
@Override public void tearDown() { listener.clear(); }
/** * 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(); }
/** * Test a simple connect. */ public void testConnectSuccess() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); checkExpectationsSatisfied(); }
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); }
/** * Test simple NACK and onDelta. * Nack is not supposed to happen, so it should be death. */ public void testSimpleNackAndReceive() throws Exception { final int initialVersion = 42; connectChannel(initialVersion, SIG1); sendAndCheckRandomOp(operationChannel, initialVersion, SIG1); listener.clear(); try { operationChannel.onNack(ResponseCode.OK, null, 43); fail("Should have thrown ChannelException"); } catch (ChannelException expected) { } checkExpectationsSatisfied(); }
/** * Test receiving a simple delta that was committed. */ public void testSimpleReceive() throws ChannelException { final int initialVersion = 42; connectChannel(initialVersion, SIG1); operationChannel.onDelta(createRandomTransformedDelta(initialVersion, 1, SIG2)); listener.checkOpsReceived(1); listener.clear(); assertNotNull(operationChannel.receive()); listener.checkOpsReceived(0); // TODO(anorth): test OnCommit by mocking CC operationChannel.onCommit(initialVersion + 1); checkExpectationsSatisfied(); }
/** * Test a simple connect. */ public void testConnectSuccess() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); checkExpectationsSatisfied(); }
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); }
/** * Test simple NACK and onDelta. * Nack is not supposed to happen, so it should be death. */ public void testSimpleNackAndReceive() throws Exception { final int initialVersion = 42; connectChannel(initialVersion, SIG1); sendAndCheckRandomOp(operationChannel, initialVersion, SIG1); listener.clear(); try { operationChannel.onNack(ResponseCode.OK, null, 43); fail("Should have thrown ChannelException"); } catch (ChannelException expected) { } checkExpectationsSatisfied(); }
/** * Test receiving a simple delta that was committed. */ public void testSimpleReceive() throws ChannelException { final int initialVersion = 42; connectChannel(initialVersion, SIG1); operationChannel.onDelta(createRandomTransformedDelta(initialVersion, 1, SIG2)); listener.checkOpsReceived(1); listener.clear(); assertNotNull(operationChannel.receive()); listener.checkOpsReceived(0); // TODO(anorth): test OnCommit by mocking CC operationChannel.onCommit(initialVersion + 1); checkExpectationsSatisfied(); }
/** * Test a simple connect then successful disconnection. */ public void testConnectThenDisconnectSuccess() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); // Disconnect operationChannel.reset(); checkExpectationsSatisfied(); }
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); }
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()); }
/** * Test a simple connect then successful disconnection. */ public void testConnectThenDisconnectSuccess() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); // Disconnect operationChannel.reset(); checkExpectationsSatisfied(); }
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); }