Search in sources :

Example 16 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.

the class MqttDeviceTwinTest method receiveSetsVersionOnResTopic.

/*
    **Tests_SRS_MQTTDEVICETWIN_25_041: [**If the topic is of type response topic then this method shall parse further to look for version which if found is set by calling setVersion**]**
     */
@Test
public void receiveSetsVersionOnResTopic(@Mocked final Mqtt mockMqtt) throws IOException {
    final byte[] actualPayload = "GetTwinResponseDataContainingDesiredAndReportedPropertiesDocument".getBytes();
    final String expectedTopic = "$iothub/twin/res/" + "201" + "/?$rid=" + mockReqId + "&$version=" + mockVersion;
    DeviceTwinMessage receivedMessage = null;
    try {
        //arrange
        MqttDeviceTwin testTwin = new MqttDeviceTwin();
        String insertTopic = expectedTopic;
        ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
        testMap.put(insertTopic, actualPayload);
        Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
        Map<String, DeviceOperations> requestMap = new HashMap<>();
        requestMap.put(mockReqId, DEVICE_OPERATION_TWIN_GET_REQUEST);
        Deencapsulation.setField(testTwin, "requestMap", requestMap);
        //act
        receivedMessage = (DeviceTwinMessage) testTwin.receive();
    } finally {
        //assert
        assertNotNull(receivedMessage);
        assertTrue(receivedMessage.getMessageType() == MessageType.DeviceTwin);
        assertTrue(receivedMessage.getDeviceOperationType() == DEVICE_OPERATION_TWIN_GET_RESPONSE);
        assertTrue(receivedMessage.getRequestId().equals(mockReqId));
        assertTrue(receivedMessage.getStatus().equals("201"));
        assertTrue(receivedMessage.getVersion().equals(mockVersion));
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) HashMap(java.util.HashMap) DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Example 17 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.

the class MqttDeviceTwinTest method receiveParsesResponseTopicForUpdateReportedPropertiesSucceeds.

@Test
public void receiveParsesResponseTopicForUpdateReportedPropertiesSucceeds(@Mocked final Mqtt mockMqtt) throws IOException {
    final byte[] actualPayload = "".getBytes();
    /*
            The following does not work
            final byte[] actualPayload = null;
         */
    final String expectedTopic = "$iothub/twin/res/" + "200" + "/?$rid=" + mockReqId + "&$version=" + mockVersion;
    DeviceTwinMessage receivedMessage = null;
    try {
        //arrange
        MqttDeviceTwin testTwin = new MqttDeviceTwin();
        String insertTopic = expectedTopic;
        ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
        testMap.put(insertTopic, actualPayload);
        Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
        Map<String, DeviceOperations> requestMap = new HashMap<>();
        requestMap.put(mockReqId, DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST);
        Deencapsulation.setField(testTwin, "requestMap", requestMap);
        //act
        receivedMessage = (DeviceTwinMessage) testTwin.receive();
    } finally {
        //assert
        assertNotNull(receivedMessage);
        assertTrue(receivedMessage.getMessageType() == MessageType.DeviceTwin);
        assertTrue(receivedMessage.getDeviceOperationType() == DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE);
        assertTrue(receivedMessage.getStatus().equals("200"));
        assertTrue(receivedMessage.getRequestId().equals(mockReqId));
        assertTrue(receivedMessage.getVersion().equals(mockVersion));
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) HashMap(java.util.HashMap) DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Example 18 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.

the class MqttDeviceTwinTest method parsePayloadRemovesTopicIfFound.

/*
    **Tests_SRS_MQTTDEVICETWIN_25_013: [**If the topic is found in the message queue then parsePayload shall delete it from the queue.**]**
     */
@Test
public void parsePayloadRemovesTopicIfFound(@Mocked final Mqtt mockMqtt) throws IOException {
    //arrange
    MqttDeviceTwin testTwin = new MqttDeviceTwin();
    String insertTopic = "$iothub/twin/" + anyString;
    final byte[] insertMessage = { 0x61, 0x62, 0x63 };
    ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
    testMap.put(insertTopic, insertMessage);
    Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
    //act
    byte[] parsedPayload = Deencapsulation.invoke(testTwin, "parsePayload", insertTopic);
    //assert
    ConcurrentSkipListMap<String, byte[]> retrieveTestMap = Deencapsulation.getField(mockMqtt, "allReceivedMessages");
    assertFalse(retrieveTestMap.containsKey(insertTopic));
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Example 19 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.

the class MqttMessagingTest method parsePayloadShallThrowIOExceptionIfTopicIsNotFound.

/*
    **Tests_SRS_MqttMessaging_25_012: [**If the topic is non-null and received messagesqueue could not locate the payload then this method shall throw IOException**]**
     */
@Test(expected = IOException.class)
public void parsePayloadShallThrowIOExceptionIfTopicIsNotFound(@Mocked final Mqtt mockMqtt) throws IOException {
    MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
    ;
    final String insertTopic_actual = "$iothub/twin/PATCH/properties/desired/#";
    final String insertTopic_messaging = "devices/" + clientId + "/messages/devicebound/abc";
    final byte[] insertMessage = { 0x61, 0x62, 0x63 };
    ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
    testMap.put(insertTopic_actual, insertMessage);
    Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
    byte[] retrieveMessage = Deencapsulation.invoke(testMqttMessaging, "parsePayload", insertTopic_messaging);
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) Test(org.junit.Test)

Example 20 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class HttpMonitorIT method callTestMatchingTextInResponse.

public void callTestMatchingTextInResponse(boolean preferIPv6) throws UnknownHostException {
    if (m_runTests == false)
        return;
    PollStatus status = null;
    ServiceMonitor monitor = new HttpMonitor();
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTP");
    final int port = JUnitHttpServerExecutionListener.getPort();
    if (port > 0) {
        m.put("port", String.valueOf(port));
    } else {
        throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
    }
    m.put("retry", "0");
    m.put("timeout", "500");
    m.put("response", "100-499");
    m.put("verbose", "true");
    m.put("host-name", "localhost");
    m.put("url", "/");
    m.put("response-text", "opennmsrulz");
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertNotNull(status.getReason());
    m.put("response-text", "written by monkeys");
    MockUtil.println("\nliteral text check: \"written by monkeys\"");
    monitor = new HttpMonitor();
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
    m.put("response-text", "~.*[Tt]est HTTP [Ss]erver.*");
    MockUtil.println("\nregex check: \".*[Tt]est HTTP [Ss]erver.*\"");
    monitor = new HttpMonitor();
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService)

Aggregations

ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)183 Test (org.junit.Test)66 PollStatus (org.opennms.netmgt.poller.PollStatus)32 MonitoredService (org.opennms.netmgt.poller.MonitoredService)31 Map (java.util.Map)30 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)25 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)23 HashMap (java.util.HashMap)21 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)17 NavigableMap (java.util.NavigableMap)14 Set (java.util.Set)12 Iterator (java.util.Iterator)11 NavigableSet (java.util.NavigableSet)11 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)11 IOException (java.io.IOException)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ArrayList (java.util.ArrayList)9 BitSet (java.util.BitSet)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)8