use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class DeviceTest method constructor_sets_status_and_symmetrickey.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_28_001: [The constructor shall set the deviceId, status and symmetricKey.]
@Test
public void constructor_sets_status_and_symmetrickey() throws NoSuchAlgorithmException {
// Arrange
String deviceId = "xxx-device";
DeviceStatus expectedDeviceStatus = DeviceStatus.Disabled;
SymmetricKey expectedSymmetricKey = new SymmetricKey();
// Act
Device device = Deencapsulation.newInstance(Device.class, new Class[] { String.class, DeviceStatus.class, SymmetricKey.class }, deviceId, expectedDeviceStatus, expectedSymmetricKey);
// Assert
assertEquals(deviceId, device.getDeviceId());
assertEquals(expectedDeviceStatus, device.getStatus());
assertEquals(expectedSymmetricKey, device.getSymmetricKey());
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method disableDeviceAfterOpenBeforeRegister.
// If you register a disabled device to an active multiplexed connection, the other devices on the connection
// should not be affected nor should the multiplexed connection itself.
@ContinuousIntegrationTest
@Test
public void disableDeviceAfterOpenBeforeRegister() throws Exception {
testInstance.setup(DEVICE_MULTIPLEX_COUNT);
// Only register the soon-to-be-disabled device after opening the multiplexing client
testInstance.multiplexingClient.unregisterDeviceClient(testInstance.deviceClientArray.get(0));
ConnectionStatusChangeTracker multiplexedConnectionStatusChangeTracker = new ConnectionStatusChangeTracker();
testInstance.multiplexingClient.registerConnectionStatusChangeCallback(multiplexedConnectionStatusChangeTracker, null);
ConnectionStatusChangeTracker[] connectionStatusChangeTrackers = new ConnectionStatusChangeTracker[DEVICE_MULTIPLEX_COUNT];
for (int i = 0; i < DEVICE_MULTIPLEX_COUNT; i++) {
connectionStatusChangeTrackers[i] = new ConnectionStatusChangeTracker();
testInstance.deviceClientArray.get(i).registerConnectionStatusChangeCallback(connectionStatusChangeTrackers[i], null);
}
testInstance.multiplexingClient.open();
// Disable a device that will be on the multiplexed connection
Device deviceToDisable = registryManager.getDevice(testInstance.deviceIdentityArray.get(0).getDeviceId());
deviceToDisable.setStatus(DeviceStatus.Disabled);
registryManager.updateDevice(deviceToDisable);
try {
try {
testInstance.multiplexingClient.registerDeviceClient(testInstance.deviceClientArray.get(0));
fail("Registering a disabled device to an active multiplexing connection should have thrown an exception");
} catch (MultiplexingClientDeviceRegistrationAuthenticationException ex) {
assertTrue(ex.getRegistrationExceptions().containsKey(deviceToDisable.getDeviceId()));
}
// verify that the disabled device eventually loses its device session
long startTime = System.currentTimeMillis();
while (!connectionStatusChangeTrackers[0].wentDisconnectedRetrying) {
Thread.sleep(200);
if (System.currentTimeMillis() - startTime > FAULT_INJECTION_TIMEOUT_MILLIS) {
fail("Timed out waiting for the disabled device's client to report DISCONNECTED_RETRYING");
}
}
assertFalse("Device failed to be registered, but the multiplexing client still reports it as registered", testInstance.multiplexingClient.isDeviceRegistered(deviceToDisable.getDeviceId()));
for (int i = 1; i < DEVICE_MULTIPLEX_COUNT; i++) {
assertTrue("One device failed to be registered, but the other devices should still have been registered.", testInstance.multiplexingClient.isDeviceRegistered(testInstance.deviceClientArray.get(i).getConfig().getDeviceId()));
}
// Verify that the other devices on the multiplexed connection were unaffected
for (int i = 1; i < DEVICE_MULTIPLEX_COUNT; i++) {
assertFalse(connectionStatusChangeTrackers[i].wentDisconnectedRetrying);
assertTrue(connectionStatusChangeTrackers[i].isOpen);
}
// Verify that the multiplexed connection itself was unaffected
assertFalse(multiplexedConnectionStatusChangeTracker.wentDisconnectedRetrying);
assertTrue(multiplexedConnectionStatusChangeTracker.isOpen);
// Verify that the other devices can still send telemetry
testSendingMessagesFromMultiplexedClients(testInstance.deviceClientArray.subList(1, DEVICE_MULTIPLEX_COUNT));
testInstance.multiplexingClient.close();
} finally {
// re enable the device in case it gets recycled
deviceToDisable.setStatus(DeviceStatus.Enabled);
registryManager.updateDevice(deviceToDisable);
}
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method registrationsUnwindForMqttClient.
@Test
public void registrationsUnwindForMqttClient() throws Exception {
Device mqttDevice = Tools.getTestDevice(iotHubConnectionString, IotHubClientProtocol.MQTT, AuthenticationType.SAS, false).getDevice();
String deviceConnectionString = registryManager.getDeviceConnectionString(mqttDevice);
// MQTT clients should throw UnsupportedOperationException when registered
DeviceClient mqttDeviceClient = new DeviceClient(deviceConnectionString, IotHubClientProtocol.MQTT);
registrationsUnwindForUnsupportedOperationExceptions(mqttDeviceClient);
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method registrationsUnwindForX509Client.
@Test
public void registrationsUnwindForX509Client() throws Exception {
// Create a new device client that uses x509 auth, which should throw an UnsupportedOperationException
// since x509 auth isn't supported while multiplexing
Device x509Device = Tools.getTestDevice(iotHubConnectionString, IotHubClientProtocol.MQTT, AuthenticationType.SELF_SIGNED, false).getDevice();
String deviceConnectionString = registryManager.getDeviceConnectionString(x509Device);
DeviceClient x509DeviceClient = new DeviceClient(deviceConnectionString, testInstance.protocol, new IotHubSSLContext().getSSLContext());
registrationsUnwindForUnsupportedOperationExceptions(x509DeviceClient);
}
use of com.microsoft.azure.sdk.iot.service.Device in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method registrationsUnwindForAlreadyOpenClient.
@Test
public void registrationsUnwindForAlreadyOpenClient() throws Exception {
Device nonMultiplexedDevice = Tools.getTestDevice(iotHubConnectionString, testInstance.protocol, AuthenticationType.SAS, false).getDevice();
String deviceConnectionString = registryManager.getDeviceConnectionString(nonMultiplexedDevice);
DeviceClient nonMultiplexedDeviceClient = new DeviceClient(deviceConnectionString, testInstance.protocol);
// By opening the client once, this client can no longer be registered to a multiplexing client
nonMultiplexedDeviceClient.open();
registrationsUnwindForUnsupportedOperationExceptions(nonMultiplexedDeviceClient);
nonMultiplexedDeviceClient.closeNow();
}
Aggregations