Search in sources :

Example 76 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testChangeMappingOfStreamingEngineViaSetServicesToClusterInNamespace.

@Test
public void testChangeMappingOfStreamingEngineViaSetServicesToClusterInNamespace() throws Exception {
    Long testNamespaceId = 1L;
    Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
    Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
    setupExpectationForSimulatingTopologyIsRunning(testNamespaceId, testNamespace, existingMappings);
    List<NamespaceServiceClusterMap> mappingsToApply = existingMappings.stream().filter(m -> !m.getServiceName().equals(TEST_STREAMING_ENGINE)).collect(toList());
    // change the mapping of streaming engine to cluster id 2
    mappingsToApply.add(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 2L));
    try {
        namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            // request fails before removing existing mappings
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = 0;
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Expectations(mockit.Expectations) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) RunWith(org.junit.runner.RunWith) SecurityContext(javax.ws.rs.core.SecurityContext) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) Lists(com.google.common.collect.Lists) JMockit(mockit.integration.junit4.JMockit) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Tested(mockit.Tested) TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) Collection(java.util.Collection) Test(org.junit.Test) IOException(java.io.IOException) NoopAuthorizer(com.hortonworks.streamline.streams.security.impl.NoopAuthorizer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) Injectable(mockit.Injectable) Assert(org.junit.Assert) Verifications(mockit.Verifications) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 77 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testMappingMultipleStreamingEngineViaSetServicesToClusterInNamespace.

@Test
public void testMappingMultipleStreamingEngineViaSetServicesToClusterInNamespace() 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;
        }
    };
    List<NamespaceServiceClusterMap> mappingsToApply = Lists.newArrayList(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 2L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 1L), new NamespaceServiceClusterMap(testNamespaceId, "KAFKA", 1L));
    try {
        namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            catalogService.listTopologies();
            times = 0;
            topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
            times = 0;
            // request fails before removing existing mappings
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = 0;
        }
    };
}
Also used : Expectations(mockit.Expectations) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) 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)

Example 78 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testOverwriteSameStreamingEngineMappingViaMapServiceToClusterInNamespace.

@Test
public void testOverwriteSameStreamingEngineMappingViaMapServiceToClusterInNamespace() 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;
        }
    };
    NamespaceServiceClusterMap existingStreamingEngineMapping = existingMappings.stream().filter(m -> m.getServiceName().equals(TEST_STREAMING_ENGINE)).findAny().get();
    namespaceCatalogResource.mapServiceToClusterInNamespace(testNamespaceId, existingStreamingEngineMapping, securityContext);
    new Verifications() {

        {
            environmentService.addOrUpdateServiceClusterMapping(withAny(new NamespaceServiceClusterMap()));
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 79 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testMappingMultipleTimeSeriesDBViaSetServicesToClusterInNamespace.

@Test
public void testMappingMultipleTimeSeriesDBViaSetServicesToClusterInNamespace() 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;
        }
    };
    List<NamespaceServiceClusterMap> mappingsToApply = Lists.newArrayList(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 2L), new NamespaceServiceClusterMap(testNamespaceId, "KAFKA", 1L));
    try {
        namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            catalogService.listTopologies();
            times = 0;
            topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
            times = 0;
            // request fails before removing existing mappings
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = 0;
        }
    };
}
Also used : Expectations(mockit.Expectations) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) 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)

Example 80 with Verifications

use of mockit.Verifications in project streamline by hortonworks.

the class EventLoggingSpoutOutputCollectorTest method emit.

@Test
public void emit() throws Exception {
    String testStreamId = "testStreamId";
    final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
    String messageId = "testMessageId";
    List<Integer> expectedTasks = Lists.newArrayList(TASK_1, TASK_2);
    Set<String> expectedStormComponents = Sets.newHashSet(TEST_TARGET_COMPONENT_FOR_TASK_1, TEST_TARGET_COMPONENT_FOR_TASK_2);
    setupExpectationsForTopologyContextEmit();
    sut = new EventLoggingSpoutOutputCollector(mockedTopologyContext, mockedOutputCollector, mockedEventLogger);
    // String streamId, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emit(testStreamId, tuple);
            this.result = expectedTasks;
        }
    };
    List<Integer> tasks = sut.emit(testStreamId, tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            mockedOutputCollector.emit(testStreamId, tuple);
        }
    };
    verifyEventsAreWrittenProperly(INPUT_STREAMLINE_EVENT, expectedStormComponents);
    // List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emit(tuple);
            result = expectedTasks;
        }
    };
    tasks = sut.emit(tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            mockedOutputCollector.emit(tuple);
        }
    };
    verifyEventsAreWrittenProperly(INPUT_STREAMLINE_EVENT, expectedStormComponents);
    // String streamId, List<Object> tuple, Object messageId
    new Expectations() {

        {
            mockedOutputCollector.emit(testStreamId, tuple, messageId);
            result = expectedTasks;
        }
    };
    tasks = sut.emit(testStreamId, tuple, messageId);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            mockedOutputCollector.emit(testStreamId, tuple, messageId);
        }
    };
    verifyEventsAreWrittenProperly(INPUT_STREAMLINE_EVENT, expectedStormComponents);
    // List<Object> tuple, Object messageId
    new Expectations() {

        {
            mockedOutputCollector.emit(tuple, messageId);
            result = expectedTasks;
        }
    };
    tasks = sut.emit(tuple, messageId);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            mockedOutputCollector.emit(tuple, messageId);
        }
    };
    verifyEventsAreWrittenProperly(INPUT_STREAMLINE_EVENT, expectedStormComponents);
}
Also used : Expectations(mockit.Expectations) Values(org.apache.storm.tuple.Values) Verifications(mockit.Verifications) 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