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());
}
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());
}
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());
}
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;
}
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);
}
Aggregations