use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest 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);
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class GetTwinTests method testGetDeviceTwinWithProxy.
@Test
@StandardTierHubOnlyTest
public void testGetDeviceTwinWithProxy() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, ModuleClientException, URISyntaxException {
if (testInstance.protocol != IotHubClientProtocol.MQTT || testInstance.authenticationType != AuthenticationType.SAS || testInstance.clientType != ClientType.DEVICE_CLIENT) {
// when the device is using MQTT with SAS auth
return;
}
super.setUpNewDeviceAndModule();
String testProxyHostname = "127.0.0.1";
int testProxyPort = 8892;
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(testProxyPort).start();
try {
Proxy serviceSideProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
ProxyOptions proxyOptions = new ProxyOptions(serviceSideProxy);
DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().proxyOptions(proxyOptions).build();
testInstance.twinServiceClient = DeviceTwin.createFromConnectionString(iotHubConnectionString, options);
super.testGetDeviceTwin();
} finally {
proxyServer.stop();
}
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class QueryTwinTests method testQueryTwinWithConnectionString.
@Test
@StandardTierHubOnlyTest
public void testQueryTwinWithConnectionString() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, URISyntaxException, ModuleClientException {
testInstance.twinServiceClient = new DeviceTwin(iotHubConnectionString);
testQueryTwin();
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class QueryTwinTests method rawQueryTokenRenewalWithAzureSasCredential.
@Test
@StandardTierHubOnlyTest
public void rawQueryTokenRenewalWithAzureSasCredential() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, URISyntaxException, ModuleClientException {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential sasCredential = new AzureSasCredential(serviceSasToken.toString());
testInstance.twinServiceClient = new DeviceTwin(iotHubConnectionStringObj.getHostName(), sasCredential);
// test that the service client can query before the shared access signature expires
testRawQueryTwin();
// deliberately expire the SAS token to provoke a 401 to ensure that the registry manager is using the shared
// access signature that is set here.
sasCredential.update(SasTokenTools.makeSasTokenExpired(serviceSasToken.toString()));
try {
testRawQueryTwin();
fail("Expected query call to throw unauthorized exception since an expired SAS token was used, but no exception was thrown");
} catch (IotHubUnathorizedException e) {
log.debug("IotHubUnauthorizedException was thrown as expected, continuing test");
}
// Renew the expired shared access signature
serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
sasCredential.update(serviceSasToken.toString());
// test that the service client can query after renewing the shared access signature expires
testRawQueryTwin();
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class QueryTwinTests method queryCollectionCanReturnEmptyQueryResults.
@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void queryCollectionCanReturnEmptyQueryResults() throws IOException, IotHubException {
String fullQuery = "select * from devices where deviceId='nonexistantdevice'";
DeviceTwin twinClient = new DeviceTwin(iotHubConnectionString, DeviceTwinClientOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
QueryCollection twinQuery = twinClient.queryTwinCollection(fullQuery);
QueryOptions options = new QueryOptions();
QueryCollectionResponse<DeviceTwinDevice> response = twinClient.next(twinQuery, options);
assertNull(response.getContinuationToken());
assertTrue(response.getCollection().isEmpty());
}
Aggregations