Search in sources :

Example 1 with SimulatedTime

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);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 2 with SimulatedTime

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);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 3 with SimulatedTime

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);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) Values(org.apache.storm.tuple.Values) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 4 with SimulatedTime

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);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) ISupervisor(org.apache.storm.scheduler.ISupervisor) LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) ILocalizer(org.apache.storm.localizer.ILocalizer) LocalAssignment(org.apache.storm.generated.LocalAssignment) DynamicState(org.apache.storm.daemon.supervisor.Slot.DynamicState) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Example 5 with SimulatedTime

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);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) ILocalizer(org.apache.storm.localizer.ILocalizer) DynamicState(org.apache.storm.daemon.supervisor.Slot.DynamicState) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) LocalState(org.apache.storm.utils.LocalState) ISupervisor(org.apache.storm.scheduler.ISupervisor) Test(org.junit.Test)

Aggregations

SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)22 Test (org.junit.Test)22 TreeMap (java.util.TreeMap)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)6 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)6 ILocalizer (org.apache.storm.localizer.ILocalizer)6 ISupervisor (org.apache.storm.scheduler.ISupervisor)6 LocalState (org.apache.storm.utils.LocalState)6 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)5 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)5 LocalAssignment (org.apache.storm.generated.LocalAssignment)5 LogLevel (org.apache.storm.generated.LogLevel)5 Matchers.anyObject (org.mockito.Matchers.anyObject)4 LogConfig (org.apache.storm.generated.LogConfig)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 TopicPartition (org.apache.kafka.common.TopicPartition)1