Search in sources :

Example 71 with TimeValue

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());
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) TimeValue(io.crate.common.unit.TimeValue) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 72 with TimeValue

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"));
}
Also used : Version(org.elasticsearch.Version) TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 73 with TimeValue

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));
}
Also used : Version(org.elasticsearch.Version) IOException(java.io.IOException) TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 74 with TimeValue

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());
}
Also used : BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 75 with TimeValue

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());
}
Also used : TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Aggregations

TimeValue (io.crate.common.unit.TimeValue)75 Test (org.junit.Test)23 ClusterState (org.elasticsearch.cluster.ClusterState)20 IOException (java.io.IOException)17 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)12 ActionListener (org.elasticsearch.action.ActionListener)12 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)11 ArrayList (java.util.ArrayList)10 ThreadPool (org.elasticsearch.threadpool.ThreadPool)10 ElasticsearchException (org.elasticsearch.ElasticsearchException)9 Settings (org.elasticsearch.common.settings.Settings)9 Logger (org.apache.logging.log4j.Logger)8 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)8 ClusterService (org.elasticsearch.cluster.service.ClusterService)8 List (java.util.List)7 LogManager (org.apache.logging.log4j.LogManager)7 Version (org.elasticsearch.Version)7 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)6 ClusterStateObserver (org.elasticsearch.cluster.ClusterStateObserver)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6