/** * 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(); }
/** * 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(); }
public void testNackTooOldIsRecoverable() throws ChannelException { final long initialVersion = 0; checkedConnectChannel(initialVersion); // Submit delta. final long submitVersion = 0; final byte[] signature = sig(1); final int clientOps = 1; final WaveletDelta clientDelta = buildDelta(submitVersion, clientOps); submitDeltaOnConnectedChannel(clientDelta); // Nack delta immediately with TOO_OLD. try { nackDeltaOnConnectedChannel(submitVersion, signature, "too old", ResponseCode.TOO_OLD); fail("Expected an exception"); } catch (ChannelException e) { assertEquals(Recoverable.RECOVERABLE, e.getRecoverable()); } }
/** * 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(); }
public void testNackTooOldIsRecoverable() throws ChannelException { final long initialVersion = 0; checkedConnectChannel(initialVersion); // Submit delta. final long submitVersion = 0; final byte[] signature = sig(1); final int clientOps = 1; final WaveletDelta clientDelta = buildDelta(submitVersion, clientOps); submitDeltaOnConnectedChannel(clientDelta); // Nack delta immediately with TOO_OLD. try { nackDeltaOnConnectedChannel(submitVersion, signature, "too old", ResponseCode.TOO_OLD); fail("Expected an exception"); } catch (ChannelException e) { assertEquals(Recoverable.RECOVERABLE, e.getRecoverable()); } }
/** * 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 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 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 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 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 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 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 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 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 sent down the channel is received and the acknowledgment * delivered. */ public void testSubmitDelta() 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); final int opsCommitted = 3; final String errorMsg2 = "SERVER_ERROR"; checkedConnectChannel(currentVersion); // Send delta1. submitDeltaOnConnectedChannel(delta1); // All ops are acked. receiver.expectAck(ops1, HashedVersion.of(currentVersion + ops1, signature1)); ackDeltaOnConnectedChannel(currentVersion + ops1, ops1, signature1); // Send delta2. submitDeltaOnConnectedChannel(delta2); // Nack with a randomly injected error, as if something just went wrong // server-side. receiver.expectNack(errorMsg2, currentVersion + ops1); nackDeltaOnConnectedChannel(currentVersion + ops1, signature1, errorMsg2, ResponseCode.INTERNAL_ERROR); // Close. closeChannel(); receiver.checkExpectationsSatisfied(); }
/** * 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 a delta sent down the channel is received and the acknowledgment * delivered. */ public void testSubmitDelta() 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); final int opsCommitted = 3; final String errorMsg2 = "SERVER_ERROR"; checkedConnectChannel(currentVersion); // Send delta1. submitDeltaOnConnectedChannel(delta1); // All ops are acked. receiver.expectAck(ops1, HashedVersion.of(currentVersion + ops1, signature1)); ackDeltaOnConnectedChannel(currentVersion + ops1, ops1, signature1); // Send delta2. submitDeltaOnConnectedChannel(delta2); // Nack with a randomly injected error, as if something just went wrong // server-side. receiver.expectNack(errorMsg2, currentVersion + ops1); nackDeltaOnConnectedChannel(currentVersion + ops1, signature1, errorMsg2, ResponseCode.INTERNAL_ERROR); // Close. closeChannel(); receiver.checkExpectationsSatisfied(); }
/** * 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(); }