Search in sources :

Example 6 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class SendMessagesIT method SendMessagesOverAmqps_multithreaded.

@Test
public void SendMessagesOverAmqps_multithreaded() throws URISyntaxException, IOException, InterruptedException {
    List<Thread> threads = new ArrayList<>(deviceListAmqps.length);
    CountDownLatch cdl = new CountDownLatch(deviceListAmqps.length);
    Integer count = 0;
    for (Device deviceAmqps : deviceListAmqps) {
        Thread thread = new Thread(new TestDevice(deviceAmqps, IotHubClientProtocol.AMQPS, NUM_CONNECTIONS_PER_DEVICE, NUM_MESSAGES_PER_CONNECTION, NUM_KEYS_PER_MESSAGE, SEND_TIMEOUT_MILLISECONDS, cdl));
        thread.start();
        threads.add(thread);
        count++;
    }
    cdl.await();
    if (!succeed.get()) {
        Assert.fail("Sending message over AMQP protocol in parallel failed");
    }
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class DeviceManagerSample method AddDevice.

private static void AddDevice() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Device device = Device.createFromId(SampleUtils.deviceId, null, null);
    try {
        device = registryManager.addDevice(device);
        System.out.println("Device created: " + device.getDeviceId());
        System.out.println("Device key: " + device.getPrimaryKey());
    } catch (IotHubException iote) {
        iote.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 8 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class DeviceManagerSample method UpdateDevice.

private static void UpdateDevice() throws Exception {
    String primaryKey = "[New primary key goes here]";
    String secondaryKey = "[New secondary key goes here]";
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Device device = Device.createFromId(SampleUtils.deviceId, null, null);
    device.getSymmetricKey().setPrimaryKey(primaryKey);
    device.getSymmetricKey().setSecondaryKey(secondaryKey);
    try {
        device = registryManager.updateDevice(device);
        System.out.println("Device updated: " + device.getDeviceId());
        System.out.println("Device primary key: " + device.getPrimaryKey());
        System.out.println("Device secondary key: " + device.getSecondaryKey());
    } catch (IotHubException iote) {
        iote.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 9 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class DeviceTest method createFromId_good_case.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_003: [The constructor shall create a new instance of Device using the given deviceId and return with it]
@Test
public void createFromId_good_case() throws NoSuchAlgorithmException {
    // Arrange
    String deviceId = "xxx-device";
    new Expectations() {

        {
            Deencapsulation.newInstance(Device.class, deviceId, DeviceStatus.class, SymmetricKey.class);
        }
    };
    // Act
    Device device = Device.createFromId(deviceId, null, null);
    // Assert
    assertNotEquals(device, null);
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) Expectations(mockit.Expectations) Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Example 10 with Device

use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.

the class DeviceTest method constructor_initialize_properties.

// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_006: [The constructor shall initialize all properties to default value]
@Test
public void constructor_initialize_properties() throws NoSuchAlgorithmException {
    // Arrange
    String utcTimeDefault = "0001-01-01T00:00:00";
    String deviceId = "xxx-device";
    // Act
    Device device = Deencapsulation.newInstance(Device.class, deviceId, DeviceStatus.class, SymmetricKey.class);
    // Assert
    assertNotEquals(null, device);
    assertNotEquals(device.getSymmetricKey(), null);
    assertEquals("xxx-device", device.getDeviceId());
    assertEquals("", device.getGenerationId());
    assertEquals("", device.geteTag());
    assertEquals(DeviceStatus.Enabled, device.getStatus());
    assertEquals("", device.getStatusReason());
    assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
    assertEquals(DeviceConnectionState.Disconnected, device.getConnectionState());
    assertEquals(utcTimeDefault, device.getStatusUpdatedTime());
    assertEquals(utcTimeDefault, device.getConnectionStateUpdatedTime());
    assertEquals(utcTimeDefault, device.getLastActivityTime());
    assertEquals(0, device.getCloudToDeviceMessageCount());
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Test(org.junit.Test)

Aggregations

Device (com.microsoft.azure.sdk.iot.service.Device)11 Test (org.junit.Test)8 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 IOException (java.io.IOException)3 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)2 NonStrictExpectations (mockit.NonStrictExpectations)2 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Expectations (mockit.Expectations)1