Search in sources :

Example 71 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EventCorrelatingOutputCollectorTest method testResetTimeout.

@Test
public void testResetTimeout() throws Exception {
    setupExpectationsForTuple();
    setupExpectationsForTopologyContextNoEmit();
    EventCorrelatingOutputCollector sut = getSystemUnderTest();
    Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(PARENT_STREAMLINE_EVENT), TASK_0, Utils.DEFAULT_STREAM_ID);
    sut.resetTimeout(anchor);
    new Verifications() {

        {
            mockedOutputCollector.resetTimeout(anchor);
            times = 1;
        }
    };
}
Also used : Values(org.apache.storm.tuple.Values) Verifications(mockit.Verifications) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 72 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EventCorrelatingOutputCollectorTest method testFail.

@Test
public void testFail() throws Exception {
    setupExpectationsForTuple();
    setupExpectationsForTopologyContextNoEmit();
    EventCorrelatingOutputCollector sut = getSystemUnderTest();
    Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(PARENT_STREAMLINE_EVENT), TASK_0, Utils.DEFAULT_STREAM_ID);
    sut.fail(anchor);
    new Verifications() {

        {
            mockedOutputCollector.fail(anchor);
            times = 1;
        }
    };
}
Also used : Values(org.apache.storm.tuple.Values) Verifications(mockit.Verifications) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 73 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EventCorrelatingOutputCollectorTest method emitDirectWithAnchor.

@Test
public void emitDirectWithAnchor() throws Exception {
    setupExpectationsForTuple();
    setupExpectationsForTopologyContextEmit();
    setupExpectationsForEventCorrelationInjector();
    EventCorrelatingOutputCollector sut = getSystemUnderTest();
    StreamlineEvent parentEvent = eventCorrelationInjector.injectCorrelationInformation(PARENT_STREAMLINE_EVENT, Collections.emptyList(), TEST_COMPONENT_NAME_FOR_STORM);
    Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(parentEvent), TASK_0, Utils.DEFAULT_STREAM_ID);
    int testTaskId = TASK_1;
    String testStreamId = "testStreamId";
    final List<Tuple> anchors = Collections.singletonList(anchor);
    final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
    // int taskId, String streamId, Tuple anchor, List<Object> anchor
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, testStreamId, anchor, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, testStreamId, anchor, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, testStreamId, anchor, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
    // int taskId, Collection<Tuple> anchors, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, anchors, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, anchors, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, anchors, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
    // int taskId, Tuple anchor, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, anchor, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, anchor, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, anchor, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
    // int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, testStreamId, anchors, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, testStreamId, anchors, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, testStreamId, anchors, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
}
Also used : Expectations(mockit.Expectations) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) Verifications(mockit.Verifications) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 74 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class StreamsShellBoltTest method testStreamsShellBoltTest.

@Test
public void testStreamsShellBoltTest() throws Exception {
    setUpExpectations();
    copyFiles(readFile("/splitsentence.py"), new File("/tmp/splitsentence.py"));
    copyFiles(readFile("/streamline.py"), new File("/tmp/streamline.py"));
    String command = "python splitsentence.py";
    StreamsShellBolt streamsShellBolt = new StreamsShellBolt(command, 60000);
    streamsShellBolt = streamsShellBolt.withOutputStreams(Arrays.asList("stream1"));
    streamsShellBolt.prepare(new HashMap(), mockContext, mockCollector);
    streamsShellBolt.execute(getNextTuple(1));
    new Verifications() {

        {
            String streamId;
            Tuple anchor;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
            Assert.assertEquals("stream", streamId);
            Assert.assertEquals(4, tuples.size());
            Map<String, Object> fieldsAndValues = ((StreamlineEvent) tuples.get(0).get(0));
            Assert.assertEquals("THIS", fieldsAndValues.get("word"));
            fieldsAndValues = ((StreamlineEvent) tuples.get(1).get(0));
            Assert.assertEquals("IS", fieldsAndValues.get("word"));
            fieldsAndValues = ((StreamlineEvent) tuples.get(2).get(0));
            Assert.assertEquals("RANDOM", fieldsAndValues.get("word"));
            fieldsAndValues = ((StreamlineEvent) tuples.get(3).get(0));
            Assert.assertEquals("SENTENCE1", fieldsAndValues.get("word"));
        }
    };
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Verifications(mockit.Verifications) File(java.io.File) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 75 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testOverwriteExistingStreamingEngineMappingViaSetServicesToClusterInNamespace.

@Test
public void testOverwriteExistingStreamingEngineMappingViaSetServicesToClusterInNamespace() throws Exception {
    Long testNamespaceId = 1L;
    Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
    Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
    new Expectations() {

        {
            environmentService.getNamespace(testNamespaceId);
            result = testNamespace;
            environmentService.listServiceClusterMapping(testNamespaceId);
            result = existingMappings;
        }
    };
    namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, new ArrayList<>(existingMappings), securityContext);
    new Verifications() {

        {
            catalogService.listTopologies();
            times = 0;
            topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
            times = 0;
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = existingMappings.size();
            environmentService.addOrUpdateServiceClusterMapping(withAny(new NamespaceServiceClusterMap()));
            times = existingMappings.size();
        }
    };
}
Also used : Expectations(mockit.Expectations) Topology(com.hortonworks.streamline.streams.catalog.Topology) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Aggregations

Verifications (mockit.Verifications)329 Test (org.junit.Test)326 NonStrictExpectations (mockit.NonStrictExpectations)163 Expectations (mockit.Expectations)52 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)34 Tuple (org.apache.storm.tuple.Tuple)28 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)24 AmqpResponseVerification (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification)22 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)21 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)21 ArrayList (java.util.ArrayList)21 List (java.util.List)21 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)20 FileUploadNotificationReceiver (com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver)18 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)17 HashMap (java.util.HashMap)16 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)14 IOException (java.io.IOException)14 Values (org.apache.storm.tuple.Values)14 SaslListenerImpl (com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl)13