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");
}
}
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();
}
}
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();
}
}
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);
}
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());
}
Aggregations