// DeployConfigurationAsync builds a configuration that includes Edge Agent, Edge Hub, and // anything added by addConfig(). It deploys the config and waits for the edge device to // receive it and start up all the modules. public async Task <EdgeDeployment> DeployConfigurationAsync(Action <EdgeConfigBuilder> addConfig, CancellationToken token) { var builder = new EdgeConfigBuilder(this.deviceId); builder.AddRegistryCredentials(this.registries); builder.AddEdgeAgent(this.agentImage.OrDefault()) .WithEnvironment(new[] { ("RuntimeLogLevel", "debug") })
public async Task ModuleToModuleDirectMethod( [Values] Protocol protocol) { if (Platform.IsWindows() && (protocol == Protocol.AmqpWs || protocol == Protocol.MqttWs)) { Assert.Ignore("Module-to-module direct methods don't work over WebSocket on Windows"); } string agentImage = Context.Current.EdgeAgentImage.Expect(() => new ArgumentException()); string hubImage = Context.Current.EdgeHubImage.Expect(() => new ArgumentException()); string senderImage = Context.Current.MethodSenderImage.Expect(() => new ArgumentException()); string receiverImage = Context.Current.MethodReceiverImage.Expect(() => new ArgumentException()); bool optimizeForPerformance = Context.Current.OptimizeForPerformance; Option <Uri> proxy = Context.Current.Proxy; CancellationToken token = this.cts.Token; string name = $"module-to-module direct method ({protocol.ToString()})"; Log.Information("Running test '{Name}'", name); await Profiler.Run( async() => { var iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, proxy); EdgeDevice device = (await EdgeDevice.GetIdentityAsync( Context.Current.DeviceId, iotHub, token)).Expect(() => new Exception("Device should have already been created in setup fixture")); string methodSender = $"methodSender-{protocol.ToString()}"; string methodReceiver = $"methodReceiver-{protocol.ToString()}"; string clientTransport = protocol.ToTransportType().ToString(); var builder = new EdgeConfigBuilder(device.Id); foreach ((string address, string username, string password) in Context.Current.Registries) { builder.AddRegistryCredentials(address, username, password); } builder.AddEdgeAgent(agentImage).WithProxy(proxy); builder.AddEdgeHub(hubImage, optimizeForPerformance).WithProxy(proxy); builder.AddModule(methodSender, senderImage) .WithEnvironment( new[] { ("ClientTransportType", clientTransport), ("TargetModuleId", methodReceiver) });
public async Task TempSensor() { string agentImage = Context.Current.EdgeAgentImage.Expect(() => new ArgumentException()); string hubImage = Context.Current.EdgeHubImage.Expect(() => new ArgumentException()); string sensorImage = Context.Current.TempSensorImage.Expect(() => new ArgumentException()); bool optimizeForPerformance = Context.Current.OptimizeForPerformance; Option <Uri> proxy = Context.Current.Proxy; CancellationToken token = this.cts.Token; string name = "temp sensor"; Log.Information("Running test '{Name}'", name); await Profiler.Run( async() => { var iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, proxy); EdgeDevice device = (await EdgeDevice.GetIdentityAsync( Context.Current.DeviceId, iotHub, token)).Expect(() => new Exception("Device should have already been created in setup fixture")); var builder = new EdgeConfigBuilder(device.Id); foreach ((string address, string username, string password) in Context.Current.Registries) { builder.AddRegistryCredentials(address, username, password); } builder.AddEdgeAgent(agentImage).WithProxy(proxy); builder.AddEdgeHub(hubImage, optimizeForPerformance).WithProxy(proxy); builder.AddModule("tempSensor", sensorImage); await builder.Build().DeployAsync(iotHub, token); var hub = new EdgeModule("edgeHub", device.Id, iotHub); var sensor = new EdgeModule("tempSensor", device.Id, iotHub); await EdgeModule.WaitForStatusAsync( new[] { hub, sensor }, EdgeModuleStatus.Running, token); await sensor.WaitForEventsReceivedAsync(token); var sensorTwin = new ModuleTwin(sensor.Id, device.Id, iotHub); await sensorTwin.UpdateDesiredPropertiesAsync( new { properties = new { desired = new { SendData = true, SendInterval = 10 } } }, token); await sensorTwin.WaitForReportedPropertyUpdatesAsync( new { properties = new { reported = new { SendData = true, SendInterval = 10 } } }, token); }, "Completed test '{Name}'", name); }