/** * Tests that a delta submitted after a reset has sequence number 1. */ public void testSubmitAfterResetRestartsSequence() throws ChannelException { final long currentVersion = 57; final int ops1 = 7; final WaveletDelta delta1 = buildDelta(currentVersion, ops1); final byte[] signature1 = sig(1); final WaveletDelta delta2 = buildDelta(currentVersion + ops1, 2); checkedConnectChannel(currentVersion); // Send delta1. submitDeltaOnConnectedChannel(delta1); // All ops are acked. receiver.expectAck(ops1, HashedVersion.of(currentVersion + ops1, signature1)); ackDeltaOnConnectedChannel(currentVersion + ops1, ops1, signature1); deltaChannel.reset(receiver); checkedReconnectChannel(buildReconnect(currentVersion + ops1, signature1), currentVersion + ops1, signature1); // Send delta2. submitDeltaOnConnectedChannel(delta2); // Close. closeChannel(); receiver.checkExpectationsSatisfied(); }
/** * Tests that receiving an ack for a delta already received by this client * is detected as a server-side error. */ public void testAckForReceivedDeltaIsError() throws ChannelException { final long currentVersion = 57; final int ops1 = 7; final byte[] signature1 = sig(1); final WaveletDelta delta1 = buildDelta(currentVersion, ops1); checkedConnectChannel(currentVersion); // Send delta1. submitDeltaOnConnectedChannel(delta1); // Receive the delta (erroneously), but we can't detect it's an error yet. TransformedWaveletDelta serverDelta1 = buildServerDelta(currentVersion, ops1); receiver.expectDelta(serverDelta1); receiveUpdateOnConnectedChannel(serverDelta1); // Now receive the ack for the delta. Expect failure. try { ackDeltaOnConnectedChannel(currentVersion + ops1, ops1, signature1); fail("ChannelException expected"); } catch (ChannelException expected) { } receiver.checkExpectationsSatisfied(); }
/** * Tests that receiving an acknowledged delta submitted by this client is * detected as a server-side error. */ public void testReflectedSubmittedDeltaAfterAckIsError() throws ChannelException { final long currentVersion = 57; final int ops1 = 7; final byte[] signature1 = sig(1); final WaveletDelta delta1 = buildDelta(currentVersion, ops1); checkedConnectChannel(currentVersion); // Send delta1. submitDeltaOnConnectedChannel(delta1); // All ops are acked. receiver.expectAck(ops1, HashedVersion.of(currentVersion + ops1, signature1)); ackDeltaOnConnectedChannel(currentVersion + ops1, ops1, signature1); // Receive the delta (erroneously). Expect termination to be reported. try { receiveUpdateOnConnectedChannel(buildServerDelta(currentVersion, ops1)); fail("ChannelException expected"); } catch (ChannelException expected) { } receiver.checkExpectationsSatisfied(); }
/** * Tests that an ack received for a delta submitted before a channel * reconnects is dropped. */ public void testAckAfterReconnectIgnored() throws ChannelException { final long initialVersion = 57; final byte[] initialSignature = sig(4); checkedConnectChannel(initialVersion); // Submit delta. final int clientOps = 5; final WaveletDelta clientDelta = buildDelta(initialVersion, clientOps); submitDeltaOnConnectedChannel(clientDelta); // Reset channel. deltaChannel.reset(receiver); final List<TransformedWaveletDelta> reconnect = buildReconnect(initialVersion, initialSignature); checkedReconnectChannel(reconnect, 0, new byte[0]); // Acknowledge outstanding submit. final long versionAfterClient = initialVersion + clientOps; final byte[] ackedSignature = sig(1); // Don't expect the ack at the receiver. ackDeltaOnConnectedChannel(versionAfterClient, clientOps, ackedSignature); receiver.checkExpectationsSatisfied(); }
/** * Tests that the delta channel detects a gap in the op stream and * throws an exception. */ public void testMissingDeltaKillsChannel() throws ChannelException { final long initialVersion = 57; final byte[] signature = sig(1); final int ops = 7; final TransformedWaveletDelta delta1 = buildServerDelta(initialVersion, ops); checkedConnectChannel(initialVersion); // Receive and deliver delta. receiver.expectCommit(initialVersion); receiver.expectDelta(delta1); receiveUpdateOnConnectedChannel(delta1, initialVersion, signature); // Receive delta with a version number too high. final TransformedWaveletDelta delta2 = buildServerDelta(initialVersion + ops + 1, 1); try { receiveUpdateOnConnectedChannel(delta2, initialVersion, signature); fail("Expected a ChannelException"); } catch (ChannelException expected) { } receiver.checkExpectationsSatisfied(); }
/** * Tests that receiving an acknowledged delta submitted by this client is * detected as a server-side error. */ public void testReflectedSubmittedDeltaAfterAckIsError() throws ChannelException { final long currentVersion = 57; final int ops1 = 7; final byte[] signature1 = sig(1); final WaveletDelta delta1 = buildDelta(currentVersion, ops1); checkedConnectChannel(currentVersion); // Send delta1. submitDeltaOnConnectedChannel(delta1); // All ops are acked. receiver.expectAck(ops1, HashedVersion.of(currentVersion + ops1, signature1)); ackDeltaOnConnectedChannel(currentVersion + ops1, ops1, signature1); // Receive the delta (erroneously). Expect termination to be reported. try { receiveUpdateOnConnectedChannel(buildServerDelta(currentVersion, ops1)); fail("ChannelException expected"); } catch (ChannelException expected) { } receiver.checkExpectationsSatisfied(); }
/** * Tests that a delta (with commit version) received from the server is * delivered. */ public void testReceiveDelta() throws ChannelException { final long initialVersion = 57; final byte[] commitSig = sig(1); final TransformedWaveletDelta delta = buildServerDelta(initialVersion, 7); checkedConnectChannel(initialVersion); // Receive and deliver delta. receiver.expectCommit(initialVersion); receiver.expectDelta(delta); receiveUpdateOnConnectedChannel(delta, initialVersion, commitSig); // Close. closeChannel(); receiver.checkExpectationsSatisfied(); }
/** * Tests that a delta (with commit version) received from the server is * delivered. */ public void testReceiveDelta() throws ChannelException { final long initialVersion = 57; final byte[] commitSig = sig(1); final TransformedWaveletDelta delta = buildServerDelta(initialVersion, 7); checkedConnectChannel(initialVersion); // Receive and deliver delta. receiver.expectCommit(initialVersion); receiver.expectDelta(delta); receiveUpdateOnConnectedChannel(delta, initialVersion, commitSig); // Close. closeChannel(); receiver.checkExpectationsSatisfied(); }
/** * Tests that the last committed version sent with a reconnect initial delta is * delivered. */ public void testReconnectReceivesCommittedVersion() throws ChannelException { final long currentVersion = 57; final byte[] signature = sig(1); final long committedVersion = 50; final byte[] committedSignature = sig(2); final HashedVersion signedVersion = HashedVersion.of(currentVersion, signature); final List<TransformedWaveletDelta> reconnect = buildReconnect(currentVersion, signature); // Expect connection. receiver.expectConnection(signedVersion, signedVersion); receiver.expectCommit(committedVersion); reconnectChannel(reconnect, committedVersion, committedSignature); receiver.checkExpectationsSatisfied(); }
/** * Tests that the last committed version sent with a reconnect initial delta is * delivered. */ public void testReconnectReceivesCommittedVersion() throws ChannelException { final long currentVersion = 57; final byte[] signature = sig(1); final long committedVersion = 50; final byte[] committedSignature = sig(2); final HashedVersion signedVersion = HashedVersion.of(currentVersion, signature); final List<TransformedWaveletDelta> reconnect = buildReconnect(currentVersion, signature); // Expect connection. receiver.expectConnection(signedVersion, signedVersion); receiver.expectCommit(committedVersion); reconnectChannel(reconnect, committedVersion, committedSignature); receiver.checkExpectationsSatisfied(); }
/** * Tests that a last committed version sent with the connect message is * delivered. */ public void testConnectReceivesCommittedVersion() throws ChannelException { final long currentVersion = 57; final byte[] signature = sig(1); final long committedVersion = 50; final byte[] committedSignature = sig(2); final HashedVersion signedVersion = HashedVersion.of(currentVersion, signature); final ObservableWaveletData wavelet = buildSnapshot(currentVersion, signature); receiver.expectConnection(signedVersion, signedVersion); receiver.expectCommit(committedVersion); connectChannel(wavelet, committedVersion, committedSignature); receiver.checkExpectationsSatisfied(); }
/** * Tests that a last-committed-version message with no deltas is correctly * delivered. */ public void testReceiveLastCommittedVersion() throws ChannelException { final long initialVersion = 57; final long committedVersion = 50; final byte[] committedSignature = sig(1); checkedConnectChannel(initialVersion); receiver.expectCommit(committedVersion); receiveUpdateOnConnectedChannel(null, committedVersion, committedSignature); // Close. closeChannel(); receiver.checkExpectationsSatisfied(); }
/** * Tests that a last-committed-version message with no deltas is correctly * delivered. */ public void testReceiveLastCommittedVersion() throws ChannelException { final long initialVersion = 57; final long committedVersion = 50; final byte[] committedSignature = sig(1); checkedConnectChannel(initialVersion); receiver.expectCommit(committedVersion); receiveUpdateOnConnectedChannel(null, committedVersion, committedSignature); // Close. closeChannel(); receiver.checkExpectationsSatisfied(); }
/** * Tests that a last committed version sent with the connect message is * delivered. */ public void testConnectReceivesCommittedVersion() throws ChannelException { final long currentVersion = 57; final byte[] signature = sig(1); final long committedVersion = 50; final byte[] committedSignature = sig(2); final HashedVersion signedVersion = HashedVersion.of(currentVersion, signature); final ObservableWaveletData wavelet = buildSnapshot(currentVersion, signature); receiver.expectConnection(signedVersion, signedVersion); receiver.expectCommit(committedVersion); connectChannel(wavelet, committedVersion, committedSignature); receiver.checkExpectationsSatisfied(); }
/** * Connects the channel and checks expectations. * * @param currentVersion version at which to connect. */ private void checkedConnectChannel(long currentVersion) throws ChannelException { byte[] signature = sig(currentVersion); final HashedVersion signedVersion = HashedVersion.of(currentVersion, sig(currentVersion)); final ObservableWaveletData wavelet = buildSnapshot(currentVersion, signature); receiver.expectConnection(signedVersion, signedVersion); receiver.expectCommit(currentVersion); connectChannel(wavelet); receiver.checkExpectationsSatisfied(); }
/** * Connects the channel and checks expectations. * * @param currentVersion version at which to connect. */ private void checkedConnectChannel(long currentVersion) throws ChannelException { byte[] signature = sig(currentVersion); final HashedVersion signedVersion = HashedVersion.of(currentVersion, sig(currentVersion)); final ObservableWaveletData wavelet = buildSnapshot(currentVersion, signature); receiver.expectConnection(signedVersion, signedVersion); receiver.expectCommit(currentVersion); connectChannel(wavelet); receiver.checkExpectationsSatisfied(); }
/** * Tests that a channel with no receivers quietly drops messages. */ public void testChannelWithNoReceiverDropsMessages() throws ChannelException { final long initialVersion = 57; final byte[] signature = sig(1); final ObservableWaveletData wavelet = buildSnapshot(initialVersion, signature); final TransformedWaveletDelta delta = buildServerDelta(initialVersion, 3); deltaChannel.reset(null); // Clear receiver. connectChannel(wavelet); receiveUpdateOnConnectedChannel(delta, initialVersion, signature); receiver.checkExpectationsSatisfied(); }
/** * Tests that a channel with no receivers quietly drops messages. */ public void testChannelWithNoReceiverDropsMessages() throws ChannelException { final long initialVersion = 57; final byte[] signature = sig(1); final ObservableWaveletData wavelet = buildSnapshot(initialVersion, signature); final TransformedWaveletDelta delta = buildServerDelta(initialVersion, 3); deltaChannel.reset(null); // Clear receiver. connectChannel(wavelet); receiveUpdateOnConnectedChannel(delta, initialVersion, signature); receiver.checkExpectationsSatisfied(); }
/** * Tests that when the client terminates the channel the receiver * is not notified. */ public void testClientResetTerminatesSilently() throws ChannelException { checkedConnectChannel(57); deltaChannel.reset(null); receiver.checkExpectationsSatisfied(); }
/** * Tests that when the client terminates the channel the receiver * is not notified. */ public void testClientResetTerminatesSilently() throws ChannelException { checkedConnectChannel(57); deltaChannel.reset(null); receiver.checkExpectationsSatisfied(); }