use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class JobClientTests method mixScheduleInFutureSucceed.
@Test(timeout = TEST_TIMEOUT_MILLISECONDS)
@ContinuousIntegrationTest
@Ignore
public void mixScheduleInFutureSucceed() 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 + "']";
// 10 seconds in the future.
final Date future = new Date(new Date().getTime() + 10000L);
final ConcurrentMap<String, Exception> jobExceptions = new ConcurrentHashMap<>();
final ConcurrentMap<String, JobResult> jobResults = new ConcurrentHashMap<>();
final ConcurrentMap<String, Integer> twinExpectedTemperature = new ConcurrentHashMap<>();
final ArrayList<String> jobIdsPending = new ArrayList<>();
// Act
for (int i = 0; i < MAX_NUMBER_JOBS; i++) {
final int index = i;
final int jobTemperature = (newTemperature++);
executor.submit(() -> {
String jobId = JOB_ID_NAME + UUID.randomUUID();
jobIdsPending.add(jobId);
try {
if (index % 2 == 0) {
jobClient.scheduleDeviceMethod(jobId, queryCondition, DeviceEmulator.METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, PAYLOAD_STRING, future, MAX_EXECUTION_TIME_IN_SECONDS);
} else {
DeviceTwinDevice deviceTwinDevice = new DeviceTwinDevice(deviceId);
Set<Pair> testDesProp = new HashSet<>();
testDesProp.add(new Pair(STANDARD_PROPERTY_HOMETEMP, jobTemperature));
deviceTwinDevice.setDesiredProperties(testDesProp);
twinExpectedTemperature.put(jobId, jobTemperature);
jobClient.scheduleUpdateTwin(jobId, queryCondition, deviceTwinDevice, new Date(), MAX_EXECUTION_TIME_IN_SECONDS);
}
JobResult jobResult = jobClient.getJob(jobId);
while (jobResult.getJobStatus() != JobStatus.completed) {
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB_MILLISECONDS);
jobResult = jobClient.getJob(jobId);
}
jobResult = queryDeviceJobResult(jobId, ((index % 2 == 0) ? JobType.scheduleDeviceMethod : JobType.scheduleUpdateTwin), JobStatus.completed);
jobResults.put(jobId, jobResult);
} catch (IotHubException | IOException | InterruptedException e) {
jobExceptions.put(jobId, e);
}
jobIdsPending.remove(jobId);
});
}
cleanupJobs(executor, jobIdsPending);
// wait until identity receive the twin change
ConcurrentMap<String, ConcurrentLinkedQueue<Object>> changes = deviceTestManger.getTwinChanges();
int timeout = 0;
while (changes.size() == 0) {
if ((timeout += MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB_MILLISECONDS) >= TEST_TIMEOUT_MILLISECONDS) {
fail("Device didn't receive the twin change");
}
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB_MILLISECONDS);
changes = deviceTestManger.getTwinChanges();
}
// 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");
}
assertEquals("Missing job result", MAX_NUMBER_JOBS, jobResults.size());
ConcurrentLinkedQueue<Object> temperatures = changes.get(STANDARD_PROPERTY_HOMETEMP);
assertNotNull("There is no " + STANDARD_PROPERTY_HOMETEMP + " in the device changes", temperatures);
for (Map.Entry<String, JobResult> job : jobResults.entrySet()) {
JobResult jobResult = job.getValue();
String jobId = jobResult.getJobId();
assertNotNull(jobResult);
if (jobResult.getJobType() == JobType.scheduleDeviceMethod) {
MethodResult methodResult = jobResult.getOutcomeResult();
assertNotNull("Device method didn't return any outcome", methodResult);
assertEquals(200L, (long) methodResult.getStatus());
assertEquals(DeviceEmulator.METHOD_LOOPBACK + ":" + PAYLOAD_STRING, methodResult.getPayload());
} else {
String temperature = twinExpectedTemperature.get(jobId) + ".0";
assertTrue("Device do not change " + STANDARD_PROPERTY_HOMETEMP + " to " + temperature, temperatures.contains(temperature));
}
}
// 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 getDeviceStatisticsTest.
// TODO what is this testing?
@Test
@ContinuousIntegrationTest
public void getDeviceStatisticsTest() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
Tools.getStatisticsWithRetry(registryManager);
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class ServiceClientTests method serviceClientValidatesRemoteCertificateWhenSendingTelemetry.
// The IoT Hub instance we use for this test is currently offline, so this test cannot be run
@Ignore
@Test
@ContinuousIntegrationTest
public void serviceClientValidatesRemoteCertificateWhenSendingTelemetry() throws IOException {
boolean expectedExceptionWasCaught = false;
ServiceClient serviceClient = ServiceClient.createFromConnectionString(invalidCertificateServerConnectionString, testInstance.protocol);
try {
serviceClient.open();
// don't need a real device Id since the request is sent to a fake service
serviceClient.send("some deviceId", new Message("some message"));
} catch (IOException e) {
expectedExceptionWasCaught = true;
} catch (Exception e) {
fail(buildExceptionMessage("Expected IOException, but received: " + Tools.getStackTraceFromThrowable(e), hostName));
}
assertTrue(buildExceptionMessage("Expected an exception due to service presenting invalid certificate", hostName), expectedExceptionWasCaught);
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class SendMessagesTests method tokenExpiredAfterOpenButBeforeSendHttp.
@Test
@ContinuousIntegrationTest
public void tokenExpiredAfterOpenButBeforeSendHttp() throws Exception {
final long SECONDS_FOR_SAS_TOKEN_TO_LIVE = 3;
final long MILLISECONDS_TO_WAIT_FOR_TOKEN_TO_EXPIRE = 5000;
if (testInstance.protocol != HTTPS || testInstance.authenticationType != SAS || testInstance.useHttpProxy) {
// as long as token did not expire before open. X509 doesn't apply either
return;
}
this.testInstance.setup();
String soonToBeExpiredSASToken = generateSasTokenForIotDevice(hostName, testInstance.identity.getDeviceId(), ((TestDeviceIdentity) testInstance.identity).getDevice().getPrimaryKey(), SECONDS_FOR_SAS_TOKEN_TO_LIVE);
DeviceClient client = new DeviceClient(soonToBeExpiredSASToken, testInstance.protocol);
client.open();
// 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();
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest in project azure-iot-sdk-java by Azure.
the class DeviceTwinWithVersionTests method testUpdateReportedPropertiesWithLowerVersionFailed.
@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void testUpdateReportedPropertiesWithLowerVersionFailed() throws IOException, InterruptedException, URISyntaxException, IotHubException {
// arrange
createDevice(testInstance.protocol);
testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(PROPERTIES);
// Create the first version of the reported properties.
testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(PROPERTIES);
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
testInstance.deviceTwinWithVersionTestDevice.deviceClient.getDeviceTwin();
long startTime = System.currentTimeMillis();
while (!testInstance.deviceTwinWithVersionTestDevice.expectedProperties.isEmpty()) {
if (System.currentTimeMillis() - startTime > EXPECTED_PROPERTIES_MAX_WAIT_MILLISECONDS) {
fail(buildExceptionMessage("Timed out waiting for expected property change", testInstance.deviceTwinWithVersionTestDevice.deviceClient));
}
Thread.sleep(BREATHE_TIME);
if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.IOTHUB_FAILURE) {
throw new IOException("IoTHub send Http error code");
}
if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.BAD_ANSWER) {
throw new IOException(testInstance.deviceTwinWithVersionTestDevice.exception);
}
}
assertEquals(buildExceptionMessage("Expected 2, but reported properties version was " + testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion, testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion);
// New values for the reported properties
final Set<Property> newValues = new HashSet<Property>() {
{
add(new Property(PROPERTY_KEY_1, "newValue1"));
add(new Property(PROPERTY_KEY_2, "newValue2"));
}
};
testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(newValues);
testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion = null;
testInstance.deviceTwinWithVersionTestDevice.receivedProperties = new HashSet<>();
// act
testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(newValues, 1);
// assert
// test device client
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
while ((testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus != STATUS.BAD_ANSWER) && (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus != STATUS.IOTHUB_FAILURE)) {
Thread.sleep(BREATHE_TIME);
}
testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(PROPERTIES);
testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion = null;
testInstance.deviceTwinWithVersionTestDevice.receivedProperties = new HashSet<>();
testInstance.deviceTwinWithVersionTestDevice.deviceClient.getDeviceTwin();
startTime = System.currentTimeMillis();
while (!testInstance.deviceTwinWithVersionTestDevice.expectedProperties.isEmpty()) {
if (System.currentTimeMillis() - startTime > EXPECTED_PROPERTIES_MAX_WAIT_MILLISECONDS) {
fail(buildExceptionMessage("Timed out waiting for expected property change", testInstance.deviceTwinWithVersionTestDevice.deviceClient));
}
Thread.sleep(BREATHE_TIME);
if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.BAD_ANSWER) {
throw new IOException(testInstance.deviceTwinWithVersionTestDevice.exception);
}
}
assertEquals(buildExceptionMessage("Expected 2, but reported properties version was " + testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion, testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion);
// test service client
DeviceTwinDevice deviceOnServiceClient = new DeviceTwinDevice(testInstance.deviceTwinWithVersionTestDevice.deviceId);
testInstance.twinServiceClient.getTwin(deviceOnServiceClient);
assertEquals(buildExceptionMessage("Expected reported properties version 2 but was " + deviceOnServiceClient.getReportedPropertiesVersion(), testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) deviceOnServiceClient.getReportedPropertiesVersion());
Set<Pair> reported = deviceOnServiceClient.getReportedProperties();
assertSetEquals(PROPERTIES, reported);
}
Aggregations