use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SingleTopicKafkaSpoutTest method shouldContinueWithSlowDoubleAcks.
@Test
public void shouldContinueWithSlowDoubleAcks() throws Exception {
try (SimulatedTime simulatedTime = new SimulatedTime()) {
int messageCount = 20;
initializeSpout(messageCount);
//play 1st tuple
ArgumentCaptor<Object> messageIdToDoubleAck = ArgumentCaptor.forClass(Object.class);
spout.nextTuple();
verify(collector).emit(anyObject(), anyObject(), messageIdToDoubleAck.capture());
spout.ack(messageIdToDoubleAck.getValue());
//Emit some more messages
IntStream.range(0, messageCount / 2).forEach(value -> {
spout.nextTuple();
});
spout.ack(messageIdToDoubleAck.getValue());
//Emit any remaining messages
IntStream.range(0, messageCount).forEach(value -> {
spout.nextTuple();
});
//Verify that all messages are emitted, ack all the messages
ArgumentCaptor<Object> messageIds = ArgumentCaptor.forClass(Object.class);
verify(collector, times(messageCount)).emit(eq(SingleTopicKafkaSpoutConfiguration.STREAM), anyObject(), messageIds.capture());
messageIds.getAllValues().iterator().forEachRemaining(spout::ack);
Time.advanceTime(commitOffsetPeriodMs + KafkaSpout.TIMER_DELAY_MS);
//Commit offsets
spout.nextTuple();
verifyAllMessagesCommitted(messageCount);
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SingleTopicKafkaSpoutTest method shouldReplayFirstTupleFailedOutOfOrder.
@Test
public void shouldReplayFirstTupleFailedOutOfOrder() throws Exception {
try (SimulatedTime simulatedTime = new SimulatedTime()) {
int messageCount = 10;
initializeSpout(messageCount);
//play 1st tuple
ArgumentCaptor<Object> messageIdToFail = ArgumentCaptor.forClass(Object.class);
spout.nextTuple();
verify(collector).emit(anyObject(), anyObject(), messageIdToFail.capture());
reset(collector);
//play 2nd tuple
ArgumentCaptor<Object> messageIdToAck = ArgumentCaptor.forClass(Object.class);
spout.nextTuple();
verify(collector).emit(anyObject(), anyObject(), messageIdToAck.capture());
reset(collector);
//ack 2nd tuple
spout.ack(messageIdToAck.getValue());
//fail 1st tuple
spout.fail(messageIdToFail.getValue());
//Emit all remaining messages. Failed tuples retry immediately with current configuration, so no need to wait.
IntStream.range(0, messageCount).forEach(value -> {
spout.nextTuple();
});
ArgumentCaptor<Object> remainingIds = ArgumentCaptor.forClass(Object.class);
//All messages except the first acked message should have been emitted
verify(collector, times(messageCount - 1)).emit(eq(SingleTopicKafkaSpoutConfiguration.STREAM), anyObject(), remainingIds.capture());
remainingIds.getAllValues().iterator().forEachRemaining(spout::ack);
Time.advanceTime(commitOffsetPeriodMs + KafkaSpout.TIMER_DELAY_MS);
//Commit offsets
spout.nextTuple();
verifyAllMessagesCommitted(messageCount);
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SingleTopicKafkaSpoutTest method shouldEmitAllMessages.
@Test
public void shouldEmitAllMessages() throws Exception {
try (SimulatedTime simulatedTime = new SimulatedTime()) {
int messageCount = 10;
initializeSpout(messageCount);
//Emit all messages and check that they are emitted. Ack the messages too
IntStream.range(0, messageCount).forEach(value -> {
spout.nextTuple();
ArgumentCaptor<Object> messageId = ArgumentCaptor.forClass(Object.class);
verify(collector).emit(eq(SingleTopicKafkaSpoutConfiguration.STREAM), eq(new Values(SingleTopicKafkaSpoutConfiguration.TOPIC, Integer.toString(value), Integer.toString(value))), messageId.capture());
spout.ack(messageId.getValue());
reset(collector);
});
Time.advanceTime(commitOffsetPeriodMs + KafkaSpout.TIMER_DELAY_MS);
//Commit offsets
spout.nextTuple();
verifyAllMessagesCommitted(messageCount);
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SlotTest method testRunningToEmpty.
@Test
public void testRunningToEmpty() throws Exception {
try (SimulatedTime t = new SimulatedTime(1010)) {
int port = 8080;
String cTopoId = "CURRENT";
List<ExecutorInfo> cExecList = mkExecutorInfoList(1, 2, 3, 4, 5);
LocalAssignment cAssignment = mkLocalAssignment(cTopoId, cExecList, mkWorkerResources(100.0, 100.0, 100.0));
Container cContainer = mock(Container.class);
LSWorkerHeartbeat chb = mkWorkerHB(cTopoId, port, cExecList, Time.currentTimeSecs());
when(cContainer.readHeartbeat()).thenReturn(chb);
when(cContainer.areAllProcessesDead()).thenReturn(false, true);
ILocalizer localizer = mock(ILocalizer.class);
ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
ISupervisor iSuper = mock(ISupervisor.class);
LocalState state = mock(LocalState.class);
StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
DynamicState dynamicState = new DynamicState(cAssignment, cContainer, null);
DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
assertEquals(MachineState.KILL, nextState.state);
verify(cContainer).kill();
verify(localizer, never()).requestDownloadBaseTopologyBlobs(null, port);
assertSame("pendingDownload not set properly", null, nextState.pendingDownload);
assertEquals(null, nextState.pendingLocalization);
assertTrue(Time.currentTimeMillis() > 1000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.KILL, nextState.state);
verify(cContainer).forceKill();
assertSame("pendingDownload not set properly", null, nextState.pendingDownload);
assertEquals(null, nextState.pendingLocalization);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.EMPTY, nextState.state);
verify(cContainer).cleanUp();
verify(localizer).releaseSlotFor(cAssignment, port);
assertEquals(null, nextState.container);
assertEquals(null, nextState.currentAssignment);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.EMPTY, nextState.state);
assertEquals(null, nextState.container);
assertEquals(null, nextState.currentAssignment);
assertTrue(Time.currentTimeMillis() > 3000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.EMPTY, nextState.state);
assertEquals(null, nextState.container);
assertEquals(null, nextState.currentAssignment);
assertTrue(Time.currentTimeMillis() > 3000);
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SlotTest method testEmptyToEmpty.
@Test
public void testEmptyToEmpty() throws Exception {
try (SimulatedTime t = new SimulatedTime(1010)) {
ILocalizer localizer = mock(ILocalizer.class);
LocalState state = mock(LocalState.class);
ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
ISupervisor iSuper = mock(ISupervisor.class);
StaticState staticState = new StaticState(localizer, 1000, 1000, 1000, 1000, containerLauncher, "localhost", 8080, iSuper, state);
DynamicState dynamicState = new DynamicState(null, null, null);
DynamicState nextState = Slot.handleEmpty(dynamicState, staticState);
assertEquals(MachineState.EMPTY, nextState.state);
assertTrue(Time.currentTimeMillis() > 1000);
}
}
Aggregations