/** * Test a simple connect then successful disconnection. */ public void testConnectThenDisconnectSuccess() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); // Disconnect operationChannel.reset(); checkExpectationsSatisfied(); }
/** * Test a simple connect then successful disconnection. */ public void testConnectThenDisconnectSuccess() throws ChannelException { connectChannel(10, SIG1); listener.checkOpsReceived(0); // Disconnect operationChannel.reset(); checkExpectationsSatisfied(); }
/** * Tests reconnection where the server does not provide a matching * signature. Expect failure. */ public void testReconnectionFailure() throws ChannelException { final int initialVersion = 42; final byte[] initialSignature = SIG1; connectChannel(initialVersion, initialSignature); // Simulate failure operationChannel.reset(); // Server presents unknown reconnect version final HashedVersion reconnectVersion = HashedVersion.of(66, SIG2); try { operationChannel.onConnection(reconnectVersion, reconnectVersion); fail("Should have thrown ChannelException"); } catch (ChannelException expected) { } }
/** * Tests reconnection where the server does not provide a matching * signature. Expect failure. */ public void testReconnectionFailure() throws ChannelException { final int initialVersion = 42; final byte[] initialSignature = SIG1; connectChannel(initialVersion, initialSignature); // Simulate failure operationChannel.reset(); // Server presents unknown reconnect version final HashedVersion reconnectVersion = HashedVersion.of(66, SIG2); try { operationChannel.onConnection(reconnectVersion, reconnectVersion); fail("Should have thrown ChannelException"); } catch (ChannelException expected) { } }
/** * 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); }
/** * 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); }