use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportHandshakerTests method testHandshakeRequestFutureVersionsCompatibility.
@Test
public void testHandshakeRequestFutureVersionsCompatibility() throws IOException {
long reqId = randomLongBetween(1, 10);
handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), PlainActionFuture.newFuture());
verify(requestSender).sendRequest(node, channel, reqId, Version.CURRENT.minimumCompatibilityVersion());
TransportHandshaker.HandshakeRequest handshakeRequest = new TransportHandshaker.HandshakeRequest(Version.CURRENT);
BytesStreamOutput currentHandshakeBytes = new BytesStreamOutput();
handshakeRequest.writeTo(currentHandshakeBytes);
BytesStreamOutput lengthCheckingHandshake = new BytesStreamOutput();
BytesStreamOutput futureHandshake = new BytesStreamOutput();
TaskId.EMPTY_TASK_ID.writeTo(lengthCheckingHandshake);
TaskId.EMPTY_TASK_ID.writeTo(futureHandshake);
try (BytesStreamOutput internalMessage = new BytesStreamOutput()) {
Version.writeVersion(Version.CURRENT, internalMessage);
lengthCheckingHandshake.writeBytesReference(internalMessage.bytes());
internalMessage.write(new byte[1024]);
futureHandshake.writeBytesReference(internalMessage.bytes());
}
StreamInput futureHandshakeStream = futureHandshake.bytes().streamInput();
// We check that the handshake we serialize for this test equals the actual request.
// Otherwise, we need to update the test.
assertEquals(currentHandshakeBytes.bytes().length(), lengthCheckingHandshake.bytes().length());
assertEquals(1031, futureHandshakeStream.available());
final PlainActionFuture<TransportResponse> responseFuture = PlainActionFuture.newFuture();
final TestTransportChannel channel = new TestTransportChannel(responseFuture);
handshaker.handleHandshake(channel, reqId, futureHandshakeStream);
assertEquals(0, futureHandshakeStream.available());
TransportHandshaker.HandshakeResponse response = (TransportHandshaker.HandshakeResponse) responseFuture.actionGet();
assertEquals(Version.CURRENT, response.getResponseVersion());
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportHandshakerTests method testHandshakeError.
@Test
public void testHandshakeError() throws IOException {
PlainActionFuture<Version> versionFuture = PlainActionFuture.newFuture();
long reqId = randomLongBetween(1, 10);
handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), versionFuture);
verify(requestSender).sendRequest(node, channel, reqId, Version.CURRENT.minimumCompatibilityVersion());
assertFalse(versionFuture.isDone());
TransportResponseHandler<TransportHandshaker.HandshakeResponse> handler = handshaker.removeHandlerForHandshake(reqId);
handler.handleException(new TransportException("failed"));
assertTrue(versionFuture.isDone());
IllegalStateException ise = expectThrows(IllegalStateException.class, versionFuture::actionGet);
assertThat(ise.getMessage(), containsString("handshake failed"));
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportHandshakerTests method testSendRequestThrowsException.
@Test
public void testSendRequestThrowsException() throws IOException {
PlainActionFuture<Version> versionFuture = PlainActionFuture.newFuture();
long reqId = randomLongBetween(1, 10);
Version compatibilityVersion = Version.CURRENT.minimumCompatibilityVersion();
doThrow(new IOException("boom")).when(requestSender).sendRequest(node, channel, reqId, compatibilityVersion);
handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), versionFuture);
assertTrue(versionFuture.isDone());
ConnectTransportException cte = expectThrows(ConnectTransportException.class, versionFuture::actionGet);
assertThat(cte.getMessage(), containsString("failure to send internal:tcp/handshake"));
assertNull(handshaker.removeHandlerForHandshake(reqId));
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportHandshakerTests method testHandshakeRequestAndResponse.
@Test
public void testHandshakeRequestAndResponse() throws IOException {
PlainActionFuture<Version> versionFuture = PlainActionFuture.newFuture();
long reqId = randomLongBetween(1, 10);
handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), versionFuture);
verify(requestSender).sendRequest(node, channel, reqId, Version.CURRENT.minimumCompatibilityVersion());
assertFalse(versionFuture.isDone());
TransportHandshaker.HandshakeRequest handshakeRequest = new TransportHandshaker.HandshakeRequest(Version.CURRENT);
BytesStreamOutput bytesStreamOutput = new BytesStreamOutput();
handshakeRequest.writeTo(bytesStreamOutput);
StreamInput input = bytesStreamOutput.bytes().streamInput();
final PlainActionFuture<TransportResponse> responseFuture = PlainActionFuture.newFuture();
final TestTransportChannel channel = new TestTransportChannel(responseFuture);
handshaker.handleHandshake(channel, reqId, input);
TransportResponseHandler<TransportHandshaker.HandshakeResponse> handler = handshaker.removeHandlerForHandshake(reqId);
handler.handleResponse((TransportHandshaker.HandshakeResponse) responseFuture.actionGet());
assertTrue(versionFuture.isDone());
assertEquals(Version.CURRENT, versionFuture.actionGet());
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportKeepAliveTests method testClosingChannelUnregistersItFromKeepAlive.
@Test
public void testClosingChannelUnregistersItFromKeepAlive() {
TimeValue pingInterval1 = TimeValue.timeValueSeconds(randomLongBetween(1, 30));
ConnectionProfile connectionProfile = new ConnectionProfile.Builder(defaultProfile).setPingInterval(pingInterval1).build();
TcpChannel channel1 = new FakeTcpChannel();
TcpChannel channel2 = new FakeTcpChannel();
channel1.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
channel2.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
keepAlive.registerNodeConnection(Collections.singletonList(channel1), connectionProfile);
keepAlive.registerNodeConnection(Collections.singletonList(channel2), connectionProfile);
channel1.close();
Runnable task = threadPool.scheduledTasks.poll().v2();
task.run();
verify(pingSender, times(0)).apply(same(channel1), eq(expectedPingMessage), any());
verify(pingSender, times(1)).apply(same(channel2), eq(expectedPingMessage), any());
}
Aggregations