use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class JobClientTests method cancelScheduleDeviceMethodSucceed.
@Test(timeout = TEST_TIMEOUT_MILLISECONDS)
@ContinuousIntegrationTest
@Ignore
public void cancelScheduleDeviceMethodSucceed() throws InterruptedException {
// Arrange
ExecutorService executor = Executors.newFixedThreadPool(MAX_NUMBER_JOBS);
DeviceTestManager deviceTestManger = devices.get(0);
final String deviceId = testDevice.getDeviceId();
final String queryCondition = "DeviceId IN ['" + deviceId + "']";
// 3 minutes in the future.
final Date future = new Date(new Date().getTime() + 180000L);
final ConcurrentMap<String, Exception> jobExceptions = new ConcurrentHashMap<>();
final ArrayList<String> jobIdsPending = new ArrayList<>();
// Act
for (int i = 0; i < MAX_NUMBER_JOBS; i++) {
final int index = i;
executor.submit(() -> {
String jobId = JOB_ID_NAME + UUID.randomUUID();
jobIdsPending.add(jobId);
try {
jobClient.scheduleDeviceMethod(jobId, queryCondition, DeviceEmulator.METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, PAYLOAD_STRING, (index % 2 == 0) ? future : new Date(), MAX_EXECUTION_TIME_IN_SECONDS);
JobStatus expectedJobStatus = JobStatus.completed;
if (index % 2 == 0) {
expectedJobStatus = JobStatus.cancelled;
// wait 1 seconds and cancel.
Thread.sleep(1000);
jobClient.cancelJob(jobId);
}
JobResult jobResult = jobClient.getJob(jobId);
while (jobResult.getJobStatus() != expectedJobStatus) {
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB_MILLISECONDS);
jobResult = jobClient.getJob(jobId);
}
log.info("Iothub confirmed {} {} for type {}", jobId, expectedJobStatus, JobType.scheduleDeviceMethod);
} catch (IotHubException | IOException | InterruptedException e) {
jobExceptions.put(jobId, e);
}
jobIdsPending.remove(jobId);
});
}
cleanupJobs(executor, jobIdsPending);
// asserts for the service side.
if (jobExceptions.size() != 0) {
for (Map.Entry<String, Exception> jobException : jobExceptions.entrySet()) {
log.error("{} threw", jobException.getKey(), jobException.getValue());
}
fail("Service throw an exception enqueuing jobs");
}
// asserts for the client side.
assertEquals(0, deviceTestManger.getStatusError());
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method deviceCreationWithDeviceScope.
@StandardTierHubOnlyTest
@Test
@ContinuousIntegrationTest
public void deviceCreationWithDeviceScope() throws IOException, InterruptedException, IotHubException, URISyntaxException {
// Arrange
this.testInstance = new RegistryManagerTestInstance();
String edge1Id = deviceIdPrefix + UUID.randomUUID().toString();
String edge2Id = deviceIdPrefix + UUID.randomUUID().toString();
String deviceId = this.testInstance.deviceId;
// -Create-//
Device edgeDevice1 = Device.createFromId(edge1Id, DeviceStatus.Enabled, null);
DeviceCapabilities capabilities = new DeviceCapabilities();
capabilities.setIotEdge(true);
edgeDevice1.setCapabilities(capabilities);
edgeDevice1 = Tools.addDeviceWithRetry(this.testInstance.registryManager, edgeDevice1);
Device edgeDevice2 = Device.createFromId(edge2Id, DeviceStatus.Enabled, null);
capabilities.setIotEdge(true);
edgeDevice2.setCapabilities(capabilities);
// set edge1 as parent
edgeDevice2.getParentScopes().add(edgeDevice1.getScope());
edgeDevice2 = Tools.addDeviceWithRetry(this.testInstance.registryManager, edgeDevice2);
Device leafDevice = Device.createFromId(deviceId, DeviceStatus.Enabled, null);
assertNotNull(edgeDevice1.getScope());
leafDevice.setScope(edgeDevice1.getScope());
Tools.addDeviceWithRetry(this.testInstance.registryManager, leafDevice);
// -Read-//
Device deviceRetrieved = this.testInstance.registryManager.getDevice(deviceId);
// -Delete-//
this.testInstance.registryManager.removeDevice(edge1Id);
this.testInstance.registryManager.removeDevice(edge2Id);
this.testInstance.registryManager.removeDevice(deviceId);
// Assert
assertEquals(buildExceptionMessage("Edge parent scope did not match parent's device scope", hostName), edgeDevice2.getParentScopes().get(0), edgeDevice1.getScope());
assertNotEquals(buildExceptionMessage("Child edge device scope should be it's own", hostName), edgeDevice2.getScope(), edgeDevice1.getScope());
assertEquals(buildExceptionMessage("Registered device Id is not correct", hostName), deviceId, leafDevice.getDeviceId());
assertEquals(buildExceptionMessage("Device scopes did not match", hostName), deviceRetrieved.getScope(), edgeDevice1.getScope());
assertEquals(buildExceptionMessage("Device's first parent scope did not match device scope", hostName), deviceRetrieved.getParentScopes().get(0), deviceRetrieved.getScope());
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method crud_module_e2e_X509_self_signed.
@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void crud_module_e2e_X509_self_signed() throws Exception {
// Arrange
RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
Device deviceSetup = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
Tools.addDeviceWithRetry(testInstance.registryManager, deviceSetup);
deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
// -Create-//
Module moduleAdded = Module.createModule(testInstance.deviceId, testInstance.moduleId, AuthenticationType.SELF_SIGNED);
moduleAdded.setThumbprintFinal(primaryThumbprint, secondaryThumbprint);
Tools.addModuleWithRetry(testInstance.registryManager, moduleAdded);
// -Read-//
Module moduleRetrieved = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
// -Update-//
Module moduleUpdated = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
moduleUpdated.setThumbprintFinal(primaryThumbprint2, secondaryThumbprint2);
moduleUpdated = testInstance.registryManager.updateModule(moduleUpdated);
// -Delete-//
testInstance.registryManager.removeModule(testInstance.deviceId, testInstance.moduleId);
// Assert
assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleAdded.getDeviceId());
assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleAdded.getId());
assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleRetrieved.getDeviceId());
assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleRetrieved.getId());
assertEquals(buildExceptionMessage("", hostName), AuthenticationType.SELF_SIGNED, moduleAdded.getAuthenticationType());
assertEquals(buildExceptionMessage("", hostName), AuthenticationType.SELF_SIGNED, moduleRetrieved.getAuthenticationType());
assertEquals(buildExceptionMessage("", hostName), primaryThumbprint, moduleAdded.getPrimaryThumbprint());
assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint, moduleAdded.getSecondaryThumbprint());
assertEquals(buildExceptionMessage("", hostName), primaryThumbprint, moduleRetrieved.getPrimaryThumbprint());
assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint, moduleRetrieved.getSecondaryThumbprint());
assertEquals(buildExceptionMessage("", hostName), primaryThumbprint2, moduleUpdated.getPrimaryThumbprint());
assertEquals(buildExceptionMessage("", hostName), secondaryThumbprint2, moduleUpdated.getSecondaryThumbprint());
assertTrue(buildExceptionMessage("", hostName), moduleWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId));
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method crud_module_e2e_X509_CA_signed.
@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void crud_module_e2e_X509_CA_signed() throws Exception {
// Arrange
RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
Device deviceSetup = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
Tools.addDeviceWithRetry(testInstance.registryManager, deviceSetup);
deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
// -Create-//
Module moduleAdded = Module.createModule(testInstance.deviceId, testInstance.moduleId, AuthenticationType.CERTIFICATE_AUTHORITY);
Tools.addModuleWithRetry(testInstance.registryManager, moduleAdded);
// -Read-//
Module moduleRetrieved = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
// -Delete-//
testInstance.registryManager.removeModule(testInstance.deviceId, testInstance.moduleId);
testInstance.registryManager.removeDevice(testInstance.deviceId);
// Assert
assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleAdded.getDeviceId());
assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleAdded.getId());
assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleRetrieved.getDeviceId());
assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleRetrieved.getId());
assertNull(buildExceptionMessage("", hostName), moduleAdded.getPrimaryThumbprint());
assertNull(buildExceptionMessage("", hostName), moduleAdded.getSecondaryThumbprint());
assertNull(buildExceptionMessage("", hostName), moduleRetrieved.getPrimaryThumbprint());
assertNull(buildExceptionMessage("", hostName), moduleRetrieved.getSecondaryThumbprint());
assertTrue(buildExceptionMessage("", hostName), moduleWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId));
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class QueryTwinTests method testQueryTwinWithContinuationToken.
@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void testQueryTwinWithContinuationToken() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, URISyntaxException, ModuleClientException {
addMultipleDevices(PAGE_SIZE + 1, false);
// Add same desired on multiple devices so that they can be queried
final String queryProperty = PROPERTY_KEY_QUERY + UUID.randomUUID().toString();
final String queryPropertyValue = PROPERTY_VALUE_QUERY + UUID.randomUUID().toString();
setDesiredProperties(queryProperty, queryPropertyValue, PAGE_SIZE + 1);
// Query multiple devices having same property
final String where = "is_defined(properties.desired." + queryProperty + ")";
SqlQuery sqlQuery;
if (this.testInstance.clientType == ClientType.MODULE_CLIENT) {
sqlQuery = SqlQuery.createSqlQuery("*", SqlQuery.FromType.MODULES, where, null);
} else {
sqlQuery = SqlQuery.createSqlQuery("*", SqlQuery.FromType.DEVICES, where, null);
}
// There is some propagation delay between when all the devices are created and have their twins set, and when
// they become queryable. This test assumes that eventually, the query result will have multiple pages. To
// avoid querying too soon, this test repeatedly queries until the continuation token is present in the return value
// as expected or until a timeout is hit.
String continuationToken = null;
Collection<DeviceTwinDevice> queriedDeviceTwinDeviceCollection = null;
long startTime = System.currentTimeMillis();
while (continuationToken == null) {
QueryCollection twinQueryCollection = testInstance.twinServiceClient.queryTwinCollection(sqlQuery.getQuery(), PAGE_SIZE);
// Run a query and save the continuation token for the second page of results
QueryCollectionResponse<DeviceTwinDevice> queryCollectionResponse = testInstance.twinServiceClient.next(twinQueryCollection);
queriedDeviceTwinDeviceCollection = queryCollectionResponse.getCollection();
continuationToken = queryCollectionResponse.getContinuationToken();
if (continuationToken == null) {
log.info("No continuation token detected yet, re-running the query");
Thread.sleep(200);
}
if (System.currentTimeMillis() - startTime > QUERY_TIMEOUT_MILLISECONDS) {
fail("Timed out waiting for query to return a continuation token");
}
}
// Re-run the same query using the saved continuation token. The results can be predicted since this test caused them
QueryOptions options = new QueryOptions();
options.setContinuationToken(continuationToken);
options.setPageSize(PAGE_SIZE);
QueryCollection twinQueryToReRun = testInstance.twinServiceClient.queryTwinCollection(sqlQuery.getQuery());
Collection<DeviceTwinDevice> continuedDeviceTwinDeviceQuery = testInstance.twinServiceClient.next(twinQueryToReRun, options).getCollection();
// Assert
assertEquals((long) PAGE_SIZE, queriedDeviceTwinDeviceCollection.size());
assertEquals(1, continuedDeviceTwinDeviceQuery.size());
// since order is not guaranteed, we cannot check that the third updated deviceTwinDevice is the third queried.
// Instead, all we can check is that each updated device twin identity is in either the initial query or the continued query.
ArrayList<String> expectedDeviceIds = new ArrayList<>();
for (int deviceTwinDeviceIndex = 0; deviceTwinDeviceIndex < PAGE_SIZE + 1; deviceTwinDeviceIndex++) {
expectedDeviceIds.add(testInstance.devicesUnderTest[deviceTwinDeviceIndex].sCDeviceForTwin.getDeviceId());
}
Collection<DeviceTwinDevice> allQueriedDeviceTwinDevices = new ArrayList<>(continuedDeviceTwinDeviceQuery);
continuedDeviceTwinDeviceQuery.addAll(queriedDeviceTwinDeviceCollection);
for (DeviceTwinDevice deviceTwinDevice : allQueriedDeviceTwinDevices) {
if (!expectedDeviceIds.contains(deviceTwinDevice.getDeviceId())) {
fail("Missing deviceTwinDevice: continuation token did not continue query where expected");
}
}
}
Aggregations