Search in sources :

Example 16 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class TransportKeepAliveTests method testRegisterMultipleKeepAliveIntervals.

@Test
public void testRegisterMultipleKeepAliveIntervals() {
    TimeValue pingInterval1 = TimeValue.timeValueSeconds(randomLongBetween(1, 30));
    ConnectionProfile connectionProfile1 = new ConnectionProfile.Builder(defaultProfile).setPingInterval(pingInterval1).build();
    TimeValue pingInterval2 = TimeValue.timeValueSeconds(randomLongBetween(31, 60));
    ConnectionProfile connectionProfile2 = new ConnectionProfile.Builder(defaultProfile).setPingInterval(pingInterval2).build();
    assertEquals(0, threadPool.scheduledTasks.size());
    TcpChannel channel1 = new FakeTcpChannel();
    TcpChannel channel2 = new FakeTcpChannel();
    channel1.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
    channel2.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
    keepAlive.registerNodeConnection(Collections.singletonList(channel1), connectionProfile1);
    keepAlive.registerNodeConnection(Collections.singletonList(channel2), connectionProfile2);
    assertEquals(2, threadPool.scheduledTasks.size());
    Tuple<TimeValue, Runnable> taskTuple1 = threadPool.scheduledTasks.poll();
    Tuple<TimeValue, Runnable> taskTuple2 = threadPool.scheduledTasks.poll();
    assertEquals(pingInterval1, taskTuple1.v1());
    assertEquals(pingInterval2, taskTuple2.v1());
    Runnable keepAliveTask1 = taskTuple1.v2();
    Runnable keepAliveTask2 = taskTuple1.v2();
    assertEquals(0, threadPool.scheduledTasks.size());
    keepAliveTask1.run();
    assertEquals(1, threadPool.scheduledTasks.size());
    keepAliveTask2.run();
    assertEquals(2, threadPool.scheduledTasks.size());
}
Also used : TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 17 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class TransportKeepAliveTests method testOnlySendPingIfWeHaveNotWrittenAndReadSinceLastPing.

@Test
public void testOnlySendPingIfWeHaveNotWrittenAndReadSinceLastPing() {
    TimeValue pingInterval = TimeValue.timeValueSeconds(15);
    ConnectionProfile connectionProfile = new ConnectionProfile.Builder(defaultProfile).setPingInterval(pingInterval).build();
    TcpChannel channel1 = new FakeTcpChannel();
    TcpChannel channel2 = new FakeTcpChannel();
    channel1.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
    channel2.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
    keepAlive.registerNodeConnection(Arrays.asList(channel1, channel2), connectionProfile);
    Tuple<TimeValue, Runnable> taskTuple = threadPool.scheduledTasks.poll();
    taskTuple.v2().run();
    TcpChannel.ChannelStats stats = channel1.getChannelStats();
    stats.markAccessed(threadPool.relativeTimeInMillis() + (pingInterval.millis() / 2));
    taskTuple = threadPool.scheduledTasks.poll();
    taskTuple.v2().run();
    verify(pingSender, times(1)).apply(same(channel1), eq(expectedPingMessage), any());
    verify(pingSender, times(2)).apply(same(channel2), eq(expectedPingMessage), any());
}
Also used : TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 18 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class TransportKeepAliveTests method testRegisterNodeConnectionSchedulesKeepAlive.

@Test
public void testRegisterNodeConnectionSchedulesKeepAlive() {
    TimeValue pingInterval = TimeValue.timeValueSeconds(randomLongBetween(1, 60));
    ConnectionProfile connectionProfile = new ConnectionProfile.Builder(defaultProfile).setPingInterval(pingInterval).build();
    assertEquals(0, threadPool.scheduledTasks.size());
    TcpChannel channel1 = new FakeTcpChannel();
    TcpChannel channel2 = new FakeTcpChannel();
    channel1.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
    channel2.getChannelStats().markAccessed(threadPool.relativeTimeInMillis());
    keepAlive.registerNodeConnection(Arrays.asList(channel1, channel2), connectionProfile);
    assertEquals(1, threadPool.scheduledTasks.size());
    Tuple<TimeValue, Runnable> taskTuple = threadPool.scheduledTasks.poll();
    assertEquals(pingInterval, taskTuple.v1());
    Runnable keepAliveTask = taskTuple.v2();
    assertEquals(0, threadPool.scheduledTasks.size());
    keepAliveTask.run();
    verify(pingSender, times(1)).apply(same(channel1), eq(expectedPingMessage), any());
    verify(pingSender, times(1)).apply(same(channel2), eq(expectedPingMessage), any());
    // Test that the task has rescheduled itself
    assertEquals(1, threadPool.scheduledTasks.size());
    Tuple<TimeValue, Runnable> rescheduledTask = threadPool.scheduledTasks.poll();
    assertEquals(pingInterval, rescheduledTask.v1());
}
Also used : TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 19 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class InternalTestCluster method clearDisruptionScheme.

// synchronized to prevent concurrently modifying the cluster.
public synchronized void clearDisruptionScheme(boolean ensureHealthyCluster) {
    if (activeDisruptionScheme != null) {
        TimeValue expectedHealingTime = activeDisruptionScheme.expectedTimeToHeal();
        logger.info("Clearing active scheme {}, expected healing time {}", activeDisruptionScheme, expectedHealingTime);
        if (ensureHealthyCluster) {
            activeDisruptionScheme.removeAndEnsureHealthy(this);
        } else {
            activeDisruptionScheme.removeFromCluster(this);
        }
    }
    activeDisruptionScheme = null;
}
Also used : TimeValue(io.crate.common.unit.TimeValue)

Example 20 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class StreamInput method readTimeValue.

/**
 * Read a {@link TimeValue} from the stream
 */
public TimeValue readTimeValue() throws IOException {
    long duration = readZLong();
    TimeUnit timeUnit = BYTE_TIME_UNIT_MAP.get(readByte());
    return new TimeValue(duration, timeUnit);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) TimeValue(io.crate.common.unit.TimeValue)

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