protected void addMultipleDevices(int numberOfDevices) throws IOException, InterruptedException, IotHubException, NoSuchAlgorithmException, URISyntaxException, ModuleClientException { devicesUnderTest = new DeviceState[numberOfDevices]; for (int i = 0; i < numberOfDevices; i++) { devicesUnderTest[i] = new DeviceState(); String id = "java-device-twin-e2e-test-" + this.testInstance.protocol.toString() + UUID.randomUUID().toString(); devicesUnderTest[i].sCDeviceForRegistryManager = com.microsoft.azure.sdk.iot.service.Device.createFromId(id, null, null); devicesUnderTest[i].sCModuleForRegistryManager = com.microsoft.azure.sdk.iot.service.Module.createFromId(id, "module", null); devicesUnderTest[i].sCDeviceForRegistryManager = Tools.addDeviceWithRetry(registryManager, devicesUnderTest[i].sCDeviceForRegistryManager); devicesUnderTest[i].sCModuleForRegistryManager = Tools.addModuleWithRetry(registryManager, devicesUnderTest[i].sCModuleForRegistryManager); Thread.sleep(2000); setUpTwin(devicesUnderTest[i]); } }
public static String buildExceptionMessage(String baseMessage, Collection<InternalClient> clients) { String hostname = ""; String protocol = ""; Collection<String> deviceIds = new ArrayList<>(); Collection<String> moduleIds = new ArrayList<>(); for (InternalClient client : clients) { hostname = client.getConfig().getIotHubHostname(); protocol = client.getConfig().getProtocol().toString(); deviceIds.add(client.getConfig().getDeviceId()); if (client.getConfig().getModuleId() != null && !client.getConfig().getModuleId().isEmpty()) { moduleIds.add(client.getConfig().getModuleId()); } } return buildExceptionMessage( baseMessage, deviceIds, protocol, hostname, moduleIds); }
@Test public void tokenExpiredAfterOpenButBeforeSendHttp() throws InvalidKeyException, IOException, InterruptedException, URISyntaxException { if (testInstance.protocol != HTTPS || testInstance.authenticationType != SAS) { //This scenario only applies to HTTP since MQTT and AMQP allow expired sas tokens for 30 minutes after open // as long as token did not expire before open. X509 doesn't apply either return; } String soonToBeExpiredSASToken = generateSasTokenForIotDevice(hostName, testInstance.identity.getDeviceId(), testInstance.identity.getPrimaryKey(), SECONDS_FOR_SAS_TOKEN_TO_LIVE); DeviceClient client = new DeviceClient(soonToBeExpiredSASToken, testInstance.protocol); IotHubServicesCommon.openClientWithRetry(client); //Force the SAS token to expire before sending messages Thread.sleep(MILLISECONDS_TO_WAIT_FOR_TOKEN_TO_EXPIRE); IotHubServicesCommon.sendMessagesExpectingSASTokenExpiration(client, testInstance.protocol.toString(), 1, RETRY_MILLISECONDS, SEND_TIMEOUT_MILLISECONDS, testInstance.authenticationType); client.closeNow(); }
public static String buildExceptionMessage(String baseMessage, InternalClient client) { if (client == null || client.getConfig() == null) { throw new IllegalArgumentException("client and config must not be null"); } return buildExceptionMessage( baseMessage, client.getConfig().getDeviceId(), client.getConfig().getProtocol().toString(), client.getConfig().getIotHubHostname(), client.getConfig().getModuleId()); }
sendMessageToDevice(testInstance.identity.getDeviceId(), testInstance.protocol.toString()); sendMessageToModule(testInstance.identity.getDeviceId(), ((Module) testInstance.identity).getId(), testInstance.protocol.toString()); waitForMessageToBeReceived(messageReceived, testInstance.protocol.toString());
throw new IllegalArgumentException("optionName is unknown = " + optionName + " for " + this.deviceIO.getProtocol().toString());
public CorrelationDetailsLoggingAssert(InternalClient internalClient) { this(internalClient.getConfig().getIotHubHostname(), internalClient.getConfig().getDeviceId(), internalClient.getConfig().getProtocol().toString(), internalClient.getConfig().getModuleId()); }
public SendMessagesTestInstance(InternalClient client, IotHubClientProtocol protocol, BaseDevice identity, AuthenticationType authenticationType, ClientType clientType, String publicKeyCert, String privateKey, String x509Thumbprint) { this.client = client; this.protocol = protocol; this.identity = identity; this.authenticationType = authenticationType; this.clientType = clientType; this.publicKeyCert = publicKeyCert; this.privateKey = privateKey; this.x509Thumbprint = x509Thumbprint; String deviceId = ""; String moduleId = ""; if (identity instanceof Module) { deviceId = identity.getDeviceId(); moduleId = ((Module) identity).getId(); } else if (identity instanceof Device) { deviceId = identity.getDeviceId(); } this.correlationDetailsLoggingAssert = new CorrelationDetailsLoggingAssert(this.client.getConfig().getIotHubHostname(), deviceId, protocol.toString(), moduleId); } }
sendMessageToDevice(testInstance.identity.getDeviceId(), testInstance.protocol.toString()); sendMessageToModule(testInstance.identity.getDeviceId(), ((Module) testInstance.identity).getId(), testInstance.protocol.toString()); waitForMessageToBeReceived(messageReceived, testInstance.protocol.toString());