private void checkExpectationsSatisfied() { deltaChannel.checkExpectationsSatisfied(); }
private WaveletDelta sendAndCheckRandomOp(OperationChannelImpl opChannel, long currentVersion, byte[] signature) throws ChannelException { WaveletDelta delta = UTIL.makeDelta(HashedVersion.of(currentVersion, signature), 0L, 1); deltaChannel.expectSend(delta); opChannel.send(new WaveletOperation[] {delta.get(0)}); return delta; }
/** * Connects the channel at the provided version. */ private void connectChannel(long version, byte[] signature) throws ChannelException { final HashedVersion signatureInfo = HashedVersion.of(version, signature); deltaChannel = new MockWaveletDeltaChannel(); cc = new ConcurrencyControl(ccLogger, signatureInfo); operationChannel = new OperationChannelImpl(opLogger, deltaChannel, cc, Accessibility.READ_WRITE); operationChannel.setListener(listener); operationChannel.onConnection(signatureInfo, signatureInfo); }
private WaveletDelta sendAndCheckRandomOp(OperationChannelImpl opChannel, long currentVersion, byte[] signature) throws ChannelException { WaveletDelta delta = UTIL.makeDelta(HashedVersion.of(currentVersion, signature), 0L, 1); deltaChannel.expectSend(delta); opChannel.send(new WaveletOperation[] {delta.get(0)}); return delta; }
/** * Connects the channel at the provided version. */ private void connectChannel(long version, byte[] signature) throws ChannelException { final HashedVersion signatureInfo = HashedVersion.of(version, signature); deltaChannel = new MockWaveletDeltaChannel(); cc = new ConcurrencyControl(ccLogger, signatureInfo); operationChannel = new OperationChannelImpl(opLogger, deltaChannel, cc, Accessibility.READ_WRITE); operationChannel.setListener(listener); operationChannel.onConnection(signatureInfo, signatureInfo); }
/** * Fails and reconnects the channel at the provided connection version and * current version. The channel is expected to provide a distinct version * matching the connect version. If expectRetransmission is not null expects * the channel to attempt to send that message on reconnection. */ private void reconnectChannel(long connectVersion, byte[] connectSignature, long currentVersion, byte[] currentSignature, WaveletDelta expectRetransmission) throws ChannelException { final HashedVersion connectHashedVersion = HashedVersion.of(connectVersion, connectSignature); final HashedVersion currentHashedVersion = HashedVersion.of(currentVersion, currentSignature); // Simulate failure elsewhere. operationChannel.reset(); // Check reconnect versions provided by the channel include the // version we'll reconnect at. List<HashedVersion> reconnectVersions = operationChannel.getReconnectVersions(); assertTrue(reconnectVersions.size() > 0); boolean matchedSignature = false; for (HashedVersion rcv : reconnectVersions) { if (connectVersion == rcv.getVersion() && connectSignature.equals(rcv.getHistoryHash())) { matchedSignature = true; } } assertTrue("No matching signature provided", matchedSignature); // Simulate reconnection reconnection message from delta channel. if (expectRetransmission != null) { deltaChannel.expectSend(expectRetransmission); } operationChannel.onConnection(connectHashedVersion, currentHashedVersion); }
public void testSendToInaccessibleChanneFails() throws ChannelException { final HashedVersion connectSig = HashedVersion.unsigned(0); deltaChannel = new MockWaveletDeltaChannel(); cc = new ConcurrencyControl(ccLogger, connectSig); operationChannel = new OperationChannelImpl(opLogger, deltaChannel, cc, Accessibility.READ_ONLY); operationChannel.setListener(listener); operationChannel.onConnection(connectSig, connectSig); try { sendAndCheckRandomOp(operationChannel, connectSig.getVersion(), connectSig.getHistoryHash()); fail("Expected a channel exception"); } catch (ChannelException expected) { } }
private void checkExpectationsSatisfied() { deltaChannel.checkExpectationsSatisfied(); }
/** * Fails and reconnects the channel at the provided connection version and * current version. The channel is expected to provide a distinct version * matching the connect version. If expectRetransmission is not null expects * the channel to attempt to send that message on reconnection. */ private void reconnectChannel(long connectVersion, byte[] connectSignature, long currentVersion, byte[] currentSignature, WaveletDelta expectRetransmission) throws ChannelException { final HashedVersion connectHashedVersion = HashedVersion.of(connectVersion, connectSignature); final HashedVersion currentHashedVersion = HashedVersion.of(currentVersion, currentSignature); // Simulate failure elsewhere. operationChannel.reset(); // Check reconnect versions provided by the channel include the // version we'll reconnect at. List<HashedVersion> reconnectVersions = operationChannel.getReconnectVersions(); assertTrue(reconnectVersions.size() > 0); boolean matchedSignature = false; for (HashedVersion rcv : reconnectVersions) { if (connectVersion == rcv.getVersion() && connectSignature.equals(rcv.getHistoryHash())) { matchedSignature = true; } } assertTrue("No matching signature provided", matchedSignature); // Simulate reconnection reconnection message from delta channel. if (expectRetransmission != null) { deltaChannel.expectSend(expectRetransmission); } operationChannel.onConnection(connectHashedVersion, currentHashedVersion); }
public void testSendToInaccessibleChanneFails() throws ChannelException { final HashedVersion connectSig = HashedVersion.unsigned(0); deltaChannel = new MockWaveletDeltaChannel(); cc = new ConcurrencyControl(ccLogger, connectSig); operationChannel = new OperationChannelImpl(opLogger, deltaChannel, cc, Accessibility.READ_ONLY); operationChannel.setListener(listener); operationChannel.onConnection(connectSig, connectSig); try { sendAndCheckRandomOp(operationChannel, connectSig.getVersion(), connectSig.getHistoryHash()); fail("Expected a channel exception"); } catch (ChannelException expected) { } }
/** * Check that the client sends the correct last known signatures. */ public void testReconnectWhereAnAckWasNotCommittedCanBeRecovered() throws Exception { final int initialVersion = 42; connectChannel(initialVersion, SIG1); // Send op and expect an Ack. byte[] signature43 = SIG2; byte[] signature44 = SIG3; sendAndCheckRandomOp(operationChannel, 42, SIG1); operationChannel.onAck(1, HashedVersion.of(43, signature43)); // Send another op and expect an Ack. WaveletDelta delta2 = sendAndCheckRandomOp(operationChannel, 43, signature43); operationChannel.onAck(1, HashedVersion.of(44, signature44)); // send commit for first Ack. operationChannel.onCommit(43); // Check that we reconnect, the server went down and has a LCV of 43. // Channel will resend delta2. reconnectChannel(43, signature43, 43, signature43, delta2); deltaChannel.checkExpectationsSatisfied(); checkExpectationsSatisfied(); }
deltaChannel.expectSend(delta3); operationChannel.onAck(1, HashedVersion.of(45, SIG5)); checkExpectationsSatisfied();
/** * Check that the client sends the correct last known signatures. */ public void testReconnectWhereAnAckWasNotCommittedCanBeRecovered() throws Exception { final int initialVersion = 42; connectChannel(initialVersion, SIG1); // Send op and expect an Ack. byte[] signature43 = SIG2; byte[] signature44 = SIG3; sendAndCheckRandomOp(operationChannel, 42, SIG1); operationChannel.onAck(1, HashedVersion.of(43, signature43)); // Send another op and expect an Ack. WaveletDelta delta2 = sendAndCheckRandomOp(operationChannel, 43, signature43); operationChannel.onAck(1, HashedVersion.of(44, signature44)); // send commit for first Ack. operationChannel.onCommit(43); // Check that we reconnect, the server went down and has a LCV of 43. // Channel will resend delta2. reconnectChannel(43, signature43, 43, signature43, delta2); deltaChannel.checkExpectationsSatisfied(); checkExpectationsSatisfied(); }
deltaChannel.expectSend(delta3); operationChannel.onAck(1, HashedVersion.of(45, SIG5)); checkExpectationsSatisfied();