public synchronized void createNewReportedProperties(int maximumPropertiesToCreate) { for (int i = 0; i < maximumPropertiesToCreate; i++) { UUID randomUUID = UUID.randomUUID(); this.setReportedProp(new Property(PROPERTY_KEY + randomUUID, PROPERTY_VALUE + randomUUID)); } }
synchronized void createNewReportedProperties(int maximumPropertiesToCreate) { for( int i = 0; i < maximumPropertiesToCreate; i++) { UUID randomUUID = UUID.randomUUID(); this.setReportedProp(new Property(PROPERTY_KEY + randomUUID, PROPERTY_VALUE + randomUUID)); } }
private Set<Property> objectToPropSet(JsonObject props) { Set<Property> propSet = new HashSet<Property>(); for (String key : props.fieldNames()) { // TODO: we may need to make this function recursive. propSet.add(new Property(key, props.getMap().get(key))); } return propSet; }
propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE); deviceUnderTest.dCDeviceForTwin.propertyStateList[i] = propertyState; desiredPropertiesCB.put(propertyState.property, new com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<TwinPropertyCallBack, Object>(deviceUnderTest.dCOnProperty, propertyState));
propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE); deviceUnderTest.dCDeviceForTwin.propertyStateList[i] = propertyState; deviceUnderTest.dCDeviceForTwin.setDesiredPropertyCallback(propertyState.property, deviceUnderTest.dCDeviceForTwin, propertyState);
@Test public void testSubscribeToDesiredPropertiesWithVersion() throws IOException, InterruptedException, IotHubException { // arrange deviceUnderTest.sCDeviceForTwin.clearTwin(); deviceUnderTest.dCDeviceForTwin.getDesiredProp().clear(); Map<Property, Pair<TwinPropertyCallBack, Object>> desiredPropertiesCB = new HashMap<>(); for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) { PropertyState propertyState = new PropertyState(); propertyState.callBackTriggered = false; propertyState.propertyNewVersion = -1; propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE); deviceUnderTest.dCDeviceForTwin.propertyStateList[i] = propertyState; desiredPropertiesCB.put(propertyState.property, new com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<TwinPropertyCallBack, Object>(deviceUnderTest.dCOnProperty, propertyState)); } // act internalClient.subscribeToTwinDesiredProperties(desiredPropertiesCB); Thread.sleep(DELAY_BETWEEN_OPERATIONS); Set<com.microsoft.azure.sdk.iot.service.devicetwin.Pair> desiredProperties = new HashSet<>(); for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) { desiredProperties.add(new com.microsoft.azure.sdk.iot.service.devicetwin.Pair(PROPERTY_KEY + i, PROPERTY_VALUE_UPDATE + UUID.randomUUID())); } deviceUnderTest.sCDeviceForTwin.setDesiredProperties(desiredProperties); sCDeviceTwin.updateTwin(deviceUnderTest.sCDeviceForTwin); // assert waitAndVerifyTwinStatusBecomesSuccess(); waitAndVerifyDesiredPropertyCallback(PROPERTY_VALUE_UPDATE, true); }
put(new Property("HomeTemp(F)", null), new Pair<TwinPropertyCallBack, Object>(new onHomeTempChange(), null)); put(new Property("LivingRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("BedroomRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("HomeSecurityCamera", null), new Pair<TwinPropertyCallBack, Object>(new onCameraActivity(), null)); add(new Property("HomeTemp(F)", 70)); add(new Property("LivingRoomLights", LIGHTS.ON)); add(new Property("BedroomRoomLights", LIGHTS.OFF)); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.DETECTED_BURGLAR)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.SAFELY_WORKING)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("BedroomRoomLights", null)); }});
@Test public void testSubscribeToDesiredPropertiesSequentially() throws IOException, InterruptedException, IotHubException { // arrange deviceUnderTest.sCDeviceForTwin.clearTwin(); deviceUnderTest.dCDeviceForTwin.getDesiredProp().clear(); for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) { PropertyState propertyState = new PropertyState(); propertyState.callBackTriggered = false; propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE); deviceUnderTest.dCDeviceForTwin.propertyStateList[i] = propertyState; deviceUnderTest.dCDeviceForTwin.setDesiredPropertyCallback(propertyState.property, deviceUnderTest.dCDeviceForTwin, propertyState); } // act internalClient.subscribeToDesiredProperties(deviceUnderTest.dCDeviceForTwin.getDesiredProp()); Thread.sleep(DELAY_BETWEEN_OPERATIONS); for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) { Set<com.microsoft.azure.sdk.iot.service.devicetwin.Pair> desiredProperties = new HashSet<>(); desiredProperties.add(new com.microsoft.azure.sdk.iot.service.devicetwin.Pair(PROPERTY_KEY + i, PROPERTY_VALUE_UPDATE + UUID.randomUUID())); deviceUnderTest.sCDeviceForTwin.setDesiredProperties(desiredProperties); sCDeviceTwin.updateTwin(deviceUnderTest.sCDeviceForTwin); Thread.sleep(DELAY_BETWEEN_OPERATIONS); } // assert waitAndVerifyTwinStatusBecomesSuccess(); waitAndVerifyDesiredPropertyCallback(PROPERTY_VALUE_UPDATE, false); }
put(new Property("HomeTemp(F)", null), new Pair<TwinPropertyCallBack, Object>(new onHomeTempChange(), null)); put(new Property("LivingRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("BedroomRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("HomeSecurityCamera", null), new Pair<TwinPropertyCallBack, Object>(new onCameraActivity(), null)); add(new Property("HomeTemp(F)", 70)); add(new Property("LivingRoomLights", LIGHTS.ON)); add(new Property("BedroomRoomLights", LIGHTS.OFF)); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.DETECTED_BURGLAR)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.SAFELY_WORKING)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("BedroomRoomLights", null)); }});
private Property getProperty(TwinCollection twinCollection, String key, boolean isReported) { Object value = twinCollection.get(key); Integer propertyVersion = twinCollection.getVersionFinal(); TwinMetadata metadata = twinCollection.getTwinMetadataFinal(key); Date lastUpdated = null; Integer lastUpdatedVersion = null; if(metadata != null) { lastUpdated = metadata.getLastUpdated(); lastUpdatedVersion = metadata.getLastUpdatedVersion(); } return new Property( key, value, propertyVersion, isReported, lastUpdated, lastUpdatedVersion); }
propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE); deviceUnderTest.dCDeviceForTwin.propertyStateList[i] = propertyState; deviceUnderTest.dCDeviceForTwin.setDesiredPropertyCallback(propertyState.property, deviceUnderTest.dCDeviceForTwin, propertyState);
propertyState.property = new Property(PROPERTY_KEY + j, PROPERTY_VALUE); devicesUnderTest[i].dCDeviceForTwin.propertyStateList.add(propertyState); devicesUnderTest[i].dCDeviceForTwin.setDesiredPropertyCallback(propertyState.property, devicesUnderTest[i].dCDeviceForTwin, propertyState);
homeKit.setDesiredPropertyCallback(new Property("HomeTemp(F)", null), new onHomeTempChange(), null); homeKit.setDesiredPropertyCallback(new Property("LivingRoomLights", null), homeKit, null); homeKit.setDesiredPropertyCallback(new Property("BedroomRoomLights", null), homeKit, null); homeKit.setDesiredPropertyCallback(new Property("HomeSecurityCamera", null), new onCameraActivity(), null); homeKit.setReportedProp(new Property("HomeTemp(F)", 70)); homeKit.setReportedProp(new Property("LivingRoomLights", LIGHTS.ON)); homeKit.setReportedProp(new Property("BedroomRoomLights", LIGHTS.OFF)); homeKit.setReportedProp(new Property("HomeSecurityCamera", CAMERA.DETECTED_BURGLAR)); homeKit.setReportedProp(new Property("HomeSecurityCamera", CAMERA.SAFELY_WORKING)); homeKit.setReportedProp(new Property("BedroomRoomLights", null));