Beispiel #1
0
        public void Test_PnJson_With_Multiple_Jobs_Expect_DifferentJobIds()
        {
            var legacyCliModelProviderMock = new Mock <ILegacyCliModelProvider>();
            var agentConfigProviderMock    = new Mock <IAgentConfigProvider>();
            var identityMock               = new Mock <IIdentity>();
            var newtonSoftJsonSerializer   = new NewtonSoftJsonSerializer();
            var jobSerializer              = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var publishedNodesJobConverter = new PublishedNodesJobConverter(TraceLogger.Create(), newtonSoftJsonSerializer);

            var legacyCliModel = new LegacyCliModel {
                PublishedNodesFile = "Engine/pn_assets.json"
            };

            legacyCliModelProviderMock.Setup(p => p.LegacyCliModel).Returns(legacyCliModel);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var converter = new LegacyJobOrchestrator(publishedNodesJobConverter, legacyCliModelProviderMock.Object, agentConfigProviderMock.Object, jobSerializer, TraceLogger.Create(), identityMock.Object);

            var job1 = converter.GetAvailableJobAsync(1.ToString(), new JobRequestModel()).GetAwaiter().GetResult();

            Assert.NotNull(job1);
            var job2 = converter.GetAvailableJobAsync(2.ToString(), new JobRequestModel()).GetAwaiter().GetResult();

            Assert.NotNull(job2);
            var job3 = converter.GetAvailableJobAsync(3.ToString(), new JobRequestModel()).GetAwaiter().GetResult();

            Assert.Null(job3);

            Assert.NotEqual(job1.Job.Id, job2.Job.Id);
        }
        public async Task GetAvailableJobAsyncMulithreading()
        {
            var legacyCliModelProviderMock = new Mock <ILegacyCliModelProvider>();
            var agentConfigProviderMock    = new Mock <IAgentConfigProvider>();
            var identityMock               = new Mock <IIdentity>();
            var newtonSoftJsonSerializer   = new NewtonSoftJsonSerializer();
            var jobSerializer              = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var publishedNodesJobConverter = new PublishedNodesJobConverter(TraceLogger.Create(), newtonSoftJsonSerializer);

            var legacyCliModel = new LegacyCliModel {
                PublishedNodesFile = "Engine/publishednodes.json"
            };

            legacyCliModelProviderMock.Setup(p => p.LegacyCliModel).Returns(legacyCliModel);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var converter = new LegacyJobOrchestrator(publishedNodesJobConverter, legacyCliModelProviderMock.Object, agentConfigProviderMock.Object, jobSerializer, TraceLogger.Create(), identityMock.Object);

            var tasks = new List <Task <JobProcessingInstructionModel> >();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(converter.GetAvailableJobAsync(i.ToString(), new JobRequestModel()));
            }

            await Task.WhenAll(tasks);

            Assert.Equal(2, tasks.Count(t => t.Result != null));
            var distinctConfigurations = tasks
                                         .Where(t => t.Result != null)
                                         .Select(t => t.Result.Job.JobConfiguration)
                                         .Distinct();

            Assert.Equal(2, distinctConfigurations.Count());
        }
Beispiel #3
0
        public async Task ClientNotInitializedTest()
        {
            var _clientAccessorMock = new Mock <IClientAccessor>();

            _clientAccessorMock.Setup(m => m.Client).Returns((IClient)null);

            IJsonSerializer _serializer = new NewtonSoftJsonSerializer();
            var             _config     = new Mock <IRuntimeStateReporterConfiguration>();

            _config.Setup(c => c.EnableRuntimeStateReporting).Returns(true);

            var _logger = TraceLogger.Create();

            var runtimeStateReporter = new RuntimeStateReporter(
                _clientAccessorMock.Object,
                _serializer,
                _config.Object,
                _logger
                );

            await runtimeStateReporter.SendRestartAnnouncement().ConfigureAwait(false);

            await FluentActions
            .Invoking(async() => await runtimeStateReporter.SendRestartAnnouncement().ConfigureAwait(false))
            .Should()
            .NotThrowAsync()
            .ConfigureAwait(false);
        }
Beispiel #4
0
        public async Task ReportingDisabledTest()
        {
            var _client             = new Mock <IClient>();
            var _clientAccessorMock = new Mock <IClientAccessor>();

            _clientAccessorMock.Setup(m => m.Client).Returns(_client.Object);

            IJsonSerializer _serializer = new NewtonSoftJsonSerializer();
            var             _config     = new Mock <IRuntimeStateReporterConfiguration>();

            // This will disable state reporting.
            _config.Setup(c => c.EnableRuntimeStateReporting).Returns(false);

            var _logger = TraceLogger.Create();

            var runtimeStateReporter = new RuntimeStateReporter(
                _clientAccessorMock.Object,
                _serializer,
                _config.Object,
                _logger
                );

            await FluentActions
            .Invoking(async() => await runtimeStateReporter.SendRestartAnnouncement().ConfigureAwait(false))
            .Should()
            .NotThrowAsync()
            .ConfigureAwait(false);

            _client.Verify(c => c.SendEventAsync(It.IsAny <string>(), It.IsAny <Message>()), Times.Never());
        }
        /// <summary>
        /// Constructor that initializes common resources used by tests.
        /// </summary>
        public StandaloneJobOrchestratorTests()
        {
            _agentConfigModel        = new AgentConfigModel();
            _agentConfigProviderMock = new Mock <IAgentConfigProvider>();
            _agentConfigProviderMock.Setup(p => p.Config).Returns(_agentConfigModel);

            _newtonSoftJsonSerializer    = new NewtonSoftJsonSerializer();
            _newtonSoftJsonSerializerRaw = new NewtonSoftJsonSerializerRaw();
            _publisherJobSerializer      = new PublisherJobSerializer(_newtonSoftJsonSerializer);
            _logger = TraceLogger.Create();

            var engineConfigMock  = new Mock <IEngineConfiguration>();
            var clientConfignMock = new Mock <IClientServicesConfig>();

            _publishedNodesJobConverter = new PublishedNodesJobConverter(_logger, _newtonSoftJsonSerializer,
                                                                         engineConfigMock.Object, clientConfignMock.Object);

            // Note that each test is responsible for setting content of _tempFile;
            Utils.CopyContent("Engine/empty_pn.json", _tempFile);
            _standaloneCliModel = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            _standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            _standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(_standaloneCliModel);

            _publishedNodesProvider = new PublishedNodesProvider(_standaloneCliModelProviderMock.Object, _logger);
        }
        public void Setup()
        {
            system = (ExtendedActorSystem)ActorSystem.Create("system");
            json   = new NewtonSoftJsonSerializer(system);
            var actorRef = system.ActorOf <Echo>();

            message = new Message(123, Guid.NewGuid().ToString("D"), actorRef);
        }
 /// <summary>
 /// Create node services tests
 /// </summary>
 public WriteScalarValueTests(Func <INodeServices <T> > services, T endpoint,
                              Func <T, string, Task <VariantValue> > readExpected)
 {
     _services     = services;
     _endpoint     = endpoint;
     _readExpected = readExpected;
     _serializer   = new NewtonSoftJsonSerializer();
 }
        public async Task UnpublishNodesOnExistingConfiguration(string publishedNodesFile)
        {
            var standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            var agentConfigProviderMock        = new Mock <IAgentConfigProvider>();
            var engineConfigMock         = new Mock <IEngineConfiguration>();
            var clientConfignMock        = new Mock <IClientServicesConfig>();
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();
            var jobSerializer            = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var logger = TraceLogger.Create();
            var publishedNodesJobConverter = new PublishedNodesJobConverter(logger, newtonSoftJsonSerializer,
                                                                            engineConfigMock.Object, clientConfignMock.Object);

            Utils.CopyContent(publishedNodesFile, _tempFile);
            var standaloneCliModel = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(standaloneCliModel);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var publishedNodesProvider = new PublishedNodesProvider(standaloneCliModelProviderMock.Object, logger);

            var orchestrator = new StandaloneJobOrchestrator(
                publishedNodesJobConverter,
                standaloneCliModelProviderMock.Object,
                agentConfigProviderMock.Object,
                jobSerializer,
                logger,
                publishedNodesProvider,
                newtonSoftJsonSerializer
                );

            string payload = Utils.GetFileContent(publishedNodesFile);
            var    unpublishNodesRequest = newtonSoftJsonSerializer.Deserialize <List <PublishedNodesEntryModel> >(payload);

            foreach (var request in unpublishNodesRequest)
            {
                await FluentActions
                .Invoking(async() => await orchestrator.UnpublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            var tasks = new List <Task <JobProcessingInstructionModel> >();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(orchestrator.GetAvailableJobAsync(i.ToString(), new JobRequestModel()));
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);

            tasks.Count(t => t.Result != null)
            .Should()
            .Be(0);
        }
Beispiel #9
0
        public void An_ActorRef_should_throw_an_exception_on_deserialize_if_no_system_in_scope()
        {
            var aref = ActorOf <BlackHoleActor>();

            var serializer = new NewtonSoftJsonSerializer(null);

            Intercept(() =>
            {
                var binary = serializer.ToBinary(aref);
                var bref   = serializer.FromBinary(binary, typeof(IActorRef));
            });
        }
Beispiel #10
0
        public SerializationBenchmarks()

        {
            var config = ConfigurationFactory.ParseString("akka.suppress-json-serializer-warning=true");
            var system = ActorSystem.Create("SerializationBenchmarks", config);

            MsgPackSerializer  = new MsgPackSerializer(system.AsInstanceOf <ExtendedActorSystem>());
            HyperionSerializer = new HyperionSerializer(
                system.AsInstanceOf <ExtendedActorSystem>(),
                new HyperionSerializerSettings(false, false, typeof(SimpleTypesProvider)));
            NewtonSoftJsonSerializer = new NewtonSoftJsonSerializer(system.AsInstanceOf <ExtendedActorSystem>());
        }
        public void SetUp()
        {
            theConverter = new ComplexTypeConverter(new ObjectConverter());
            theSerializer = new NewtonSoftJsonSerializer(new JsonSerializerSettings(), new JsonConverter[] { theConverter });

            theTarget = new ParentType
                            {
                                Name = "Test",
                                Child = new ComplexType { Key = "x", Value = "123" }
                            };

            theResult = theSerializer.Serialize(theTarget, true);
        }
Beispiel #12
0
        public void SetUp()
        {
            var locator         = new InMemoryServiceLocator();
            var objectConverter = new ObjectConverter(locator, new ConverterLibrary(new[] { new StatelessComplexTypeConverter() }));

            locator.Add <IObjectConverter>(objectConverter);

            var converter = new ComplexTypeConverter(objectConverter);

            theInput      = "{\"Name\":\"Test\",\"Child\":\"x:123\"}";
            theSerializer = new NewtonSoftJsonSerializer(new JsonSerializerSettings(), new[] { converter });

            theObject = theSerializer.Deserialize <ParentType>(theInput);
        }
Beispiel #13
0
        /// <summary>
        /// publish nodes from publishedNodesFile
        /// </summary>
        private async Task <PublisherMethodsController> publishNodeAsync(string publishedNodesFile)
        {
            var standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            var agentConfigProviderMock        = new Mock <IAgentConfigProvider>();
            var identityMock             = new Mock <IIdentity>();
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();
            var jobSerializer            = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var logger            = TraceLogger.Create();
            var engineConfigMock  = new Mock <IEngineConfiguration>();
            var clientConfignMock = new Mock <IClientServicesConfig>();

            var publishedNodesJobConverter = new PublishedNodesJobConverter(logger, newtonSoftJsonSerializer,
                                                                            engineConfigMock.Object, clientConfignMock.Object);

            Utils.CopyContent("Engine/empty_pn.json", _tempFile);
            var standaloneCli = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(standaloneCli);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());
            var publishedNodesProvider = new PublishedNodesProvider(standaloneCliModelProviderMock.Object, logger);

            var orchestrator = new StandaloneJobOrchestrator(
                publishedNodesJobConverter,
                standaloneCliModelProviderMock.Object,
                agentConfigProviderMock.Object,
                jobSerializer,
                logger,
                publishedNodesProvider,
                newtonSoftJsonSerializer
                );

            var methodsController = new PublisherMethodsController(orchestrator);

            using var publishPayloads = new StreamReader(publishedNodesFile);
            var publishNodesRequest = newtonSoftJsonSerializer.Deserialize <List <PublishNodesEndpointApiModel> >(
                await publishPayloads.ReadToEndAsync().ConfigureAwait(false));

            foreach (var request in publishNodesRequest)
            {
                await FluentActions
                .Invoking(async() => await methodsController.PublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }
            return(methodsController);
        }
Beispiel #14
0
        public async Task ReportingTest()
        {
            var receivedParameters = new List <Tuple <string, Message> >();

            var _client = new Mock <IClient>();

            _client
            .Setup(c => c.SendEventAsync(It.IsAny <string>(), It.IsAny <Message>()))
            .Callback <string, Message>((outputName, message) => receivedParameters.Add(Tuple.Create(outputName, message)))
            .Returns(Task.CompletedTask);

            var _clientAccessorMock = new Mock <IClientAccessor>();

            _clientAccessorMock.Setup(m => m.Client).Returns(_client.Object);

            IJsonSerializer _serializer = new NewtonSoftJsonSerializer();
            var             _config     = new Mock <IRuntimeStateReporterConfiguration>();

            _config.Setup(c => c.EnableRuntimeStateReporting).Returns(true);

            var _logger = TraceLogger.Create();

            var runtimeStateReporter = new RuntimeStateReporter(
                _clientAccessorMock.Object,
                _serializer,
                _config.Object,
                _logger
                );

            await FluentActions
            .Invoking(async() => await runtimeStateReporter.SendRestartAnnouncement().ConfigureAwait(false))
            .Should()
            .NotThrowAsync()
            .ConfigureAwait(false);

            _client.Verify(c => c.SendEventAsync(It.IsAny <string>(), It.IsAny <Message>()), Times.Once());

            Assert.Equal(1, receivedParameters.Count);
            Assert.Equal("runtimeinfo", receivedParameters[0].Item1);

            var message = receivedParameters[0].Item2;

            Assert.Equal("application/json", message.ContentType);
            Assert.Equal("utf-8", message.ContentEncoding);

            var body = Encoding.UTF8.GetString(message.GetBytes());

            Assert.Equal("{\"MessageType\":\"restartAnnouncement\",\"MessageVersion\":1}", body);
        }
Beispiel #15
0
        public void SetUp()
        {
            theConverter  = new ComplexTypeConverter(new ObjectConverter());
            theSerializer = new NewtonSoftJsonSerializer(new JsonSerializerSettings(), new JsonConverter[] { theConverter });

            theTarget = new ParentType
            {
                Name  = "Test",
                Child = new ComplexType {
                    Key = "x", Value = "123"
                }
            };

            theResult = theSerializer.Serialize(theTarget);
        }
Beispiel #16
0
        /// <summary>
        /// Dump all documents using sql
        /// </summary>
        public static async Task DumpCollectionAsync(CliOptions options)
        {
            var collection = await GetDocsAsync(options);

            var queryable  = collection.OpenSqlClient();
            var serializer = new NewtonSoftJsonSerializer();
            var feed       = queryable.Query <dynamic>("select * from root");

            while (feed.HasMore())
            {
                var result = await feed.ReadAsync();

                foreach (var item in result)
                {
                    Console.WriteLine(serializer.SerializePretty(item));
                }
            }
        }
Beispiel #17
0
        public void round_trip_with_camel_casing()
        {
            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            var serializer = new NewtonSoftJsonSerializer(settings, new JsonConverter[0]);
            var json       = serializer.Serialize(new Target {
                Name = "Jeremy"
            });

            json.ShouldBe("{\"name\":\"Jeremy\"}");

            var target2 = serializer.Deserialize <Target>(json);

            target2.Name.ShouldBe("Jeremy");
        }
Beispiel #18
0
        public async Task DmApiGetDiagnosticInfoTest(string publishedNodesFile)
        {
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();

            //publish nodes
            var methodsController = await publishNodeAsync(publishedNodesFile);

            var response = await FluentActions
                           .Invoking(async() => await methodsController
                                     .GetDiagnosticInfoAsync().ConfigureAwait(false))
                           .Should()
                           .NotThrowAsync()
                           .ConfigureAwait(false);

            response.Subject
            .Should()
            .NotBeNull();
        }
Beispiel #19
0
        public void UseSecurityDeserializationTest()
        {
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();

            var modelJson = @"
{
    ""EndpointUrl"": ""opc.tcp://*****:*****@"
{
    ""EndpointUrl"": ""opc.tcp://*****:*****@"
{
    ""EndpointUrl"": ""opc.tcp://localhost:50002"",
    ""UseSecurity"": true,
    ""OpcNodes"": [
        { ""Identifier"": ""ns=0;i=2261"" }
    ]
}
";

            model = newtonSoftJsonSerializer.Deserialize <PublishedNodesEntryModel>(modelJson);
            Assert.True(model.UseSecurity);
        }
Beispiel #20
0
        public void UseSecuritySerializationTest()
        {
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();

            var model = new PublishedNodesEntryModel {
                EndpointUrl = new Uri("opc.tcp://localhost:50000"),
                OpcNodes    = new List <OpcNodeModel> {
                    new OpcNodeModel {
                        Id = "i=2258"
                    }
                }
            };

            var modeJson = newtonSoftJsonSerializer.SerializeToString(model);

            Assert.Contains("\"UseSecurity\":false", modeJson);

            model = new PublishedNodesEntryModel {
                EndpointUrl = new Uri("opc.tcp://localhost:50000"),
                UseSecurity = false,
                OpcNodes    = new List <OpcNodeModel> {
                    new OpcNodeModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"UseSecurity\":false", modeJson);

            model = new PublishedNodesEntryModel {
                EndpointUrl = new Uri("opc.tcp://localhost:50000"),
                UseSecurity = true,
                OpcNodes    = new List <OpcNodeModel> {
                    new OpcNodeModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"UseSecurity\":true", modeJson);
        }
Beispiel #21
0
        public void OpcAuthenticationModeSerializationTest()
        {
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();

            var model = new PublishedNodesEntryModel {
                EndpointUrl = new Uri("opc.tcp://localhost:50000"),
                OpcNodes    = new List <OpcNodeModel> {
                    new OpcNodeModel {
                        Id = "i=2258"
                    }
                }
            };

            var modeJson = newtonSoftJsonSerializer.SerializeToString(model);

            Assert.Contains("\"OpcAuthenticationMode\":\"anonymous\"", modeJson);

            model = new PublishedNodesEntryModel {
                EndpointUrl           = new Uri("opc.tcp://localhost:50000"),
                OpcAuthenticationMode = OpcAuthenticationMode.Anonymous,
                OpcNodes = new List <OpcNodeModel> {
                    new OpcNodeModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"OpcAuthenticationMode\":\"anonymous\"", modeJson);

            model = new PublishedNodesEntryModel {
                EndpointUrl           = new Uri("opc.tcp://localhost:50000"),
                OpcAuthenticationMode = OpcAuthenticationMode.UsernamePassword,
                OpcNodes = new List <OpcNodeModel> {
                    new OpcNodeModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"OpcAuthenticationMode\":\"usernamePassword\"", modeJson);
        }
Beispiel #22
0
        public void OpcAuthenticationModeDeserializationTest()
        {
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();

            var modelJson = @"
{
    ""EndpointUrl"": ""opc.tcp://*****:*****@"
{
    ""EndpointUrl"": ""opc.tcp://*****:*****@"
{
    ""EndpointUrl"": ""opc.tcp://localhost:50002"",
    ""OpcAuthenticationMode"": ""usernamePassword"",
    ""OpcNodes"": [
        { ""Identifier"": ""ns=0;i=2261"" }
    ]
}
";

            model = newtonSoftJsonSerializer.Deserialize <PublishedNodesEntryModel>(modelJson);
            Assert.Equal(OpcAuthenticationMode.UsernamePassword, model.OpcAuthenticationMode);
        }
Beispiel #23
0
        /// <summary>
        /// Ping continously
        /// </summary>
        private static async Task PingAsync(IIoTHubConfig config, ILogger logger, string deviceId,
                                            string moduleId, CancellationToken ct)
        {
            var serializer = new NewtonSoftJsonSerializer();
            var client     = new IoTHubTwinMethodClient(CreateClient(config, logger), logger);

            logger.Information("Starting echo thread");
            var found = false;

            for (var index = 0; !ct.IsCancellationRequested; index++)
            {
                try {
                    var message = serializer.SerializePretty(new {
                        Index   = index,
                        Started = DateTime.UtcNow
                    });
                    logger.Debug("Sending ECHO {Index}... ", index);
                    var result = await client.CallMethodAsync(deviceId, moduleId,
                                                              "Echo_V1", message, null, ct);

                    found = true;
                    try {
                        var returned = serializer.Parse(result);
                        logger.Debug("... received back ECHO {Index} - took {Passed}.",
                                     returned["Index"], DateTime.UtcNow - ((DateTime)returned["Started"]));
                    }
                    catch (Exception e) {
                        logger.Error(e, "Bad result for ECHO {Index}: {result} ",
                                     index, result);
                    }
                }
                catch (Exception ex) {
                    if (!found && (ex is ResourceNotFoundException))
                    {
                        logger.Debug("Waiting for module to connect...");
                        continue; // Initial startup ...
                    }
                    logger.Information(ex, "Failed to send ECHO {Index}.", index);
                }
            }
            logger.Information("Echo thread completed");
        }
Beispiel #24
0
        public void JsonSerializer_should_be_able_to_serialize_Ack()
        {
            var serializer = new NewtonSoftJsonSerializer((ExtendedActorSystem)Sys);

            var nacks = new List <SeqNo>();

            for (var i = 100; i < 200; ++i)
            {
                nacks.Add(new SeqNo(i));
            }

            var message         = new Ack(new SeqNo(666), nacks);
            var serializedBytes = serializer.ToBinary(message);
            var deserialized    = (Ack)serializer.FromBinary(serializedBytes, typeof(Ack));

            deserialized.CumulativeAck.RawValue.ShouldBe(666);
            deserialized.Nacks.Count.ShouldBe(100);
            var seqNos = deserialized.Nacks.Select(ack => (int)ack.RawValue);

            seqNos.ShouldOnlyContainInOrder(Enumerable.Range(100, 100).ToArray());
        }
Beispiel #25
0
 /// <summary>
 /// Test model export and import
 /// </summary>
 private static async Task TestOpcUaModelWriterAsync(EndpointModel endpoint)
 {
     using (var logger = StackLogger.Create(ConsoleLogger.Create())) {
         var filename = "model.zip";
         using (var server = new ServerWrapper(endpoint, logger)) {
             using (var client = new ClientServices(logger.Logger, new TestClientServicesConfig())) {
                 Console.WriteLine($"Reading into {filename}...");
                 using (var stream = new FileStream(filename, FileMode.Create)) {
                     using (var zipped = new DeflateStream(stream, CompressionLevel.Optimal))
                         using (var browser = new BrowseStreamEncoder(client, endpoint, zipped,
                                                                      ContentMimeType.UaJson, null, logger.Logger, null)) {
                             await browser.EncodeAsync(CancellationToken.None);
                         }
                 }
             }
         }
         GC.Collect();
         GC.WaitForPendingFinalizers();
         var             serializer = new NewtonSoftJsonSerializer();
         IDatabaseServer database   = new MemoryDatabase(logger.Logger, serializer);
         for (var i = 0; ; i++)
         {
             Console.WriteLine($"{i}: Writing from {filename}...");
             var sw = Stopwatch.StartNew();
             using (var file = File.Open(filename, FileMode.OpenOrCreate)) {
                 using (var unzipped = new DeflateStream(file, CompressionMode.Decompress)) {
                     // TODO
                     // var writer = new SourceStreamImporter(new ItemContainerFactory(database),
                     //     new VariantEncoderFactory(), logger.Logger);
                     // await writer.ImportAsync(unzipped, Path.GetFullPath(filename + i),
                     //     ContentMimeType.UaJson, null, CancellationToken.None);
                 }
             }
             var elapsed = sw.Elapsed;
             Console.WriteLine($"{i}: Writing took {elapsed}.");
         }
     }
 }
Beispiel #26
0
        public async Task DmApiPublishUnpublishNodesTest(string publishedNodesFile)
        {
            var standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            var agentConfigProviderMock        = new Mock <IAgentConfigProvider>();
            var identityMock             = new Mock <IIdentity>();
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();
            var jobSerializer            = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var logger            = TraceLogger.Create();
            var engineConfigMock  = new Mock <IEngineConfiguration>();
            var clientConfignMock = new Mock <IClientServicesConfig>();

            var publishedNodesJobConverter = new PublishedNodesJobConverter(logger, newtonSoftJsonSerializer,
                                                                            engineConfigMock.Object, clientConfignMock.Object);

            Utils.CopyContent("Engine/empty_pn.json", _tempFile);
            var standaloneCli = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(standaloneCli);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var publishedNodesProvider = new PublishedNodesProvider(standaloneCliModelProviderMock.Object, logger);

            var orchestrator = new StandaloneJobOrchestrator(
                publishedNodesJobConverter,
                standaloneCliModelProviderMock.Object,
                agentConfigProviderMock.Object,
                jobSerializer,
                logger,
                publishedNodesProvider,
                newtonSoftJsonSerializer
                );

            var methodsController = new PublisherMethodsController(orchestrator);

            using var publishPayloads = new StreamReader(publishedNodesFile);
            var publishNodesRequest = newtonSoftJsonSerializer.Deserialize <List <PublishNodesEndpointApiModel> >(
                await publishPayloads.ReadToEndAsync().ConfigureAwait(false));

            foreach (var request in publishNodesRequest)
            {
                var initialNode = request.OpcNodes.First();
                for (int i = 0; i < 10000; i++)
                {
                    request.OpcNodes.Add(new PublishedNodeApiModel {
                        Id                        = initialNode.Id + i.ToString(),
                        DataSetFieldId            = initialNode.DataSetFieldId,
                        DisplayName               = initialNode.DisplayName,
                        ExpandedNodeId            = initialNode.ExpandedNodeId,
                        HeartbeatIntervalTimespan = initialNode.HeartbeatIntervalTimespan,
                        OpcPublishingInterval     = initialNode.OpcPublishingInterval,
                        OpcSamplingInterval       = initialNode.OpcSamplingInterval,
                        QueueSize                 = initialNode.QueueSize,
                        // ToDo: Implement mechanism for SkipFirst.
                        SkipFirst = initialNode.SkipFirst,
                    });
                }

                await FluentActions
                .Invoking(async() => await methodsController.PublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            var tasks = new List <Task <JobProcessingInstructionModel> >();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(orchestrator.GetAvailableJobAsync(i.ToString(), new JobRequestModel()));
            }

            tasks.Where(t => t.Result != null)
            .Select(t => t.Result.Job.JobConfiguration)
            .Distinct().Count()
            .Should()
            .Be(2);

            foreach (var request in publishNodesRequest)
            {
                await FluentActions
                .Invoking(async() => await methodsController
                          .UnpublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            tasks = new List <Task <JobProcessingInstructionModel> >();
            for (var i = 0; i < 10; i++)
            {
                tasks.Add(orchestrator.GetAvailableJobAsync(i.ToString(), new JobRequestModel()));
            }

            tasks.Where(t => t.Result != null).Count()
            .Should()
            .Be(0);
        }
Beispiel #27
0
        public async Task DmApiGetConfiguredEndpointsTest(string publishedNodesFile)
        {
            var standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            var agentConfigProviderMock        = new Mock <IAgentConfigProvider>();
            var identityMock             = new Mock <IIdentity>();
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();
            var jobSerializer            = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var logger            = TraceLogger.Create();
            var engineConfigMock  = new Mock <IEngineConfiguration>();
            var clientConfignMock = new Mock <IClientServicesConfig>();

            var publishedNodesJobConverter = new PublishedNodesJobConverter(logger, newtonSoftJsonSerializer,
                                                                            engineConfigMock.Object, clientConfignMock.Object);

            Utils.CopyContent("Engine/empty_pn.json", _tempFile);
            var standaloneCli = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(standaloneCli);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var publishedNodesProvider = new PublishedNodesProvider(standaloneCliModelProviderMock.Object, logger);

            var orchestrator = new StandaloneJobOrchestrator(
                publishedNodesJobConverter,
                standaloneCliModelProviderMock.Object,
                agentConfigProviderMock.Object,
                jobSerializer,
                logger,
                publishedNodesProvider,
                newtonSoftJsonSerializer
                );

            var methodsController = new PublisherMethodsController(orchestrator);

            using var publishPayloads = new StreamReader(publishedNodesFile);
            var publishNodesRequests = newtonSoftJsonSerializer.Deserialize <List <PublishNodesEndpointApiModel> >
                                           (await publishPayloads.ReadToEndAsync().ConfigureAwait(false));

            // Check that GetConfiguredEndpointsAsync returns empty list
            var endpoints = await FluentActions
                            .Invoking(async() => await methodsController
                                      .GetConfiguredEndpointsAsync().ConfigureAwait(false))
                            .Should()
                            .NotThrowAsync()
                            .ConfigureAwait(false);

            endpoints.Subject.Endpoints.Count.Should().Be(0);

            // Publish nodes
            foreach (var request in publishNodesRequests)
            {
                await FluentActions
                .Invoking(async() => await methodsController
                          .PublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            // Check configured endpoints count
            endpoints = await FluentActions
                        .Invoking(async() => await methodsController
                                  .GetConfiguredEndpointsAsync().ConfigureAwait(false))
                        .Should()
                        .NotThrowAsync()
                        .ConfigureAwait(false);

            endpoints.Subject.Endpoints.Count.Should().Be(5);
            endpoints.Subject.Endpoints[0].Tag.Should().Be("Tag_Leaf0_10000_3085991c-b85c-4311-9bfb-a916da952234");
            endpoints.Subject.Endpoints[1].Tag.Should().Be("Tag_Leaf1_10000_2e4fc28f-ffa2-4532-9f22-378d47bbee5d");
            endpoints.Subject.Endpoints[2].Tag.Should().Be("Tag_Leaf2_10000_3085991c-b85c-4311-9bfb-a916da952234");
            endpoints.Subject.Endpoints[3].Tag.Should().Be("Tag_Leaf3_10000_2e4fc28f-ffa2-4532-9f22-378d47bbee5d");
            endpoints.Subject.Endpoints[4].Tag.Should().BeNull();

            var endpointsHash = endpoints.Subject.Endpoints.Select(e => e.GetHashCode()).ToList();

            Assert.True(endpointsHash.Distinct().Count() == endpointsHash.Count());
        }
Beispiel #28
0
 /// <summary>
 /// Expand short Google url to original url (This method use google api)
 /// </summary>
 /// <param name="shortUrl">Short Google url</param>
 /// <returns>An orginal url</returns>
 public static string ExpandShortGoogleUrl(string shortUrl)
 {
     try
     {
         // make request
         string provider = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=" + shortUrl;
         var request = WebRequest.Create(provider);
         var res = request.GetResponse();
         string responeData;
         GoogleUrlResponse result;
         // read respone data and deserialize
         using (var reader = new StreamReader(res.GetResponseStream()))
         {
             responeData = reader.ReadToEnd();
             //var deserializer = new JavaScriptSerializer();
             //result = deserializer.Deserialize<GoogleUrlResponse>(responeData);
             ISerializer serializer = new NewtonSoftJsonSerializer();
             result = serializer.Deserialize<GoogleUrlResponse>(responeData);
         }
         if (result != null)
         {
             return result.LongUrl;
         }
         return shortUrl;
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
 }
        public async Task NoAcksOrHandlerNotifications()
        {
            // Arrange
            var serializer = new NewtonSoftJsonSerializer();
            var logger     = new NullLogger <SocketIoClient>();
            var opts       = new SocketIoClientOptions(
                serializer,
                logger,
                Encoding.UTF8
                );
            var client = new SocketIoClient(opts);

            client.Events.OnConnect.Subscribe(
                args => Log($"[1] Connected: {args}"));
            client.Events.OnPacket.Subscribe(packet =>
            {
                Log($"[1] Received packet: {packet}");
            });
            string clientId1 = null;

            client.Events.OnHandshake.Subscribe(res =>
            {
                clientId1 = res.Sid;
            });
            // Act
            await client.OpenAsync(new Uri("http://localhost:3300"));

            var data1 = new Payload()
            {
                Id   = 42,
                Name = "Douglas Adams"
            };
            var data2 = new Payload()
            {
                Id   = 86,
                Name = "Carl Sagan"
            };

            while (clientId1 is null)
            {
                Thread.Sleep(50);
            }

            client.On("/consume")
            .Subscribe(message =>
            {
                Log($"Received notification: {message.EventName}, data: {message.Data}");
            });

            Log($"- subscribe to 'test' topic {clientId1} -");
            client.Emit("/subscribe", new SubscribeRequest(
                            clientId1,
                            "test",
                            0,
                            10,
                            0
                            )
                        ).Subscribe(ack =>
            {
                Log($"subscribe ack: {ack}");
            });


            Log("- about to publish - ");
            client.Emit("/publish", new PublishRequest
            {
                Topic   = "test",
                Channel = 1,
                Message = JsonConvert.SerializeObject(data1)
            }
                        ).Subscribe(ack =>
            {
                Log($"publish ack: {JsonConvert.SerializeObject(ack)}");
            });

            client.Emit("/publish", new PublishRequest
            {
                Topic   = "test",
                Channel = 1,
                Message = JsonConvert.SerializeObject(data1)
            }
                        ).Subscribe(ack =>
            {
                Log($"publish ack: {JsonConvert.SerializeObject(ack)}");
            });

            // Assert
            Log("- waiting for 2s just in case -");
            await Task.Delay(2000);

            Log("- test ends -");
        }
Beispiel #30
0
 private static string MakeGoogleShortenUrl(string url)
 {
     // http://gempixel.com/demo/simplephp
     // http://www.bipinjoshi.net/articles/09bf16f8-ad91-4638-8fce-f2e286f6fe1d.aspx
     // http://www.jarloo.com/google-url-shortening/
     // http://www.aspdotnet-suresh.com/2013/02/create-google-short-urls-in-javascript.html
     // http://www.fluxbytes.com/csharp/shortening-a-url-using-bit-bitly-api-in-c/
     try
     {
         // check url is existing ?
         if (UrlIsExists(url))
         {
             // Make request
             //string encondingUrl = HttpUtility.UrlEncode(url);
             var request = WebRequest.Create("https://www.googleapis.com/urlshortener/v1/url");
             request.Method = "POST";
             request.ContentType = "application/json";
             string postData = "{\"longUrl\":\"" + url + "\"}";
             using (var writer = new StreamWriter(request.GetRequestStream()))
             {
                 writer.Write(postData);
             }
             // Get respone
             var respone = request.GetResponse();
             GoogleUrlResponse result;
             using (var reader = new StreamReader(respone.GetResponseStream()))
             {
                 // read data is returned from server and deserialize it.
                 string responeData = reader.ReadToEnd();
                 ISerializer serializer = new NewtonSoftJsonSerializer();
                 result = serializer.Deserialize<GoogleUrlResponse>(responeData);
             }
             if (result != null)
             {
                 return result.Id;
             }
         }
         return url;
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
 }
Beispiel #31
0
        public async Task DmApiPublishNodesToJobTest(string publishedNodesFile)
        {
            var standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            var agentConfigProviderMock        = new Mock <IAgentConfigProvider>();
            var identityMock             = new Mock <IIdentity>();
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();
            var jobSerializer            = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var logger            = TraceLogger.Create();
            var engineConfigMock  = new Mock <IEngineConfiguration>();
            var clientConfignMock = new Mock <IClientServicesConfig>();

            var publishedNodesJobConverter = new PublishedNodesJobConverter(logger, newtonSoftJsonSerializer,
                                                                            engineConfigMock.Object, clientConfignMock.Object);

            Utils.CopyContent("Engine/empty_pn.json", _tempFile);
            var standaloneCli = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(standaloneCli);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var publishedNodesProvider = new PublishedNodesProvider(standaloneCliModelProviderMock.Object, logger);

            var orchestrator = new StandaloneJobOrchestrator(
                publishedNodesJobConverter,
                standaloneCliModelProviderMock.Object,
                agentConfigProviderMock.Object,
                jobSerializer,
                logger,
                publishedNodesProvider,
                newtonSoftJsonSerializer
                );

            var methodsController = new PublisherMethodsController(orchestrator);

            using var publishPayloads = new StreamReader(publishedNodesFile);
            var publishNodesRequests = newtonSoftJsonSerializer.Deserialize <List <PublishNodesEndpointApiModel> >
                                           (await publishPayloads.ReadToEndAsync().ConfigureAwait(false));

            foreach (var request in publishNodesRequests)
            {
                await FluentActions
                .Invoking(async() => await methodsController
                          .PublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            var tasks = new List <Task <JobProcessingInstructionModel> >();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(orchestrator.GetAvailableJobAsync(i.ToString(), new JobRequestModel()));
            }

            var job = tasks.Where(t => t.Result != null)
                      .Select(t => t.Result.Job)
                      .Distinct();

            job.Count()
            .Should()
            .Be(2);

            var jobModel = jobSerializer.DeserializeJobConfiguration(
                job.First().JobConfiguration, job.First().JobConfigurationType) as WriterGroupJobModel;

            jobModel.WriterGroup.DataSetWriters.Count.Should().Be(4);
            foreach (var datasetWriter in jobModel.WriterGroup.DataSetWriters)
            {
                datasetWriter.DataSet.DataSetSource.Connection.Endpoint.Url
                .Should()
                .Be(publishNodesRequests.First().EndpointUrl);
                datasetWriter.DataSet.DataSetSource.Connection.Endpoint.SecurityMode
                .Should()
                .Be(publishNodesRequests.First().UseSecurity ? SecurityMode.Best : SecurityMode.None);

                datasetWriter.DataSet.DataSetSource.Connection.User.
                IsSameAs(new CredentialModel {
                    Type = publishNodesRequests.First().OpcAuthenticationMode == AuthenticationMode.Anonymous ?
                           CredentialType.None :
                           CredentialType.UserName,
                    Value = newtonSoftJsonSerializer.FromObject(
                        new {
                        user     = publishNodesRequests.First().UserName,
                        password = publishNodesRequests.First().Password,
                    })
                })
                .Should()
                .BeTrue();
            }
        }
        public async Task PublishNodesStressTest()
        {
            var standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            var agentConfigProviderMock        = new Mock <IAgentConfigProvider>();
            var engineConfigMock         = new Mock <IEngineConfiguration>();
            var clientConfignMock        = new Mock <IClientServicesConfig>();
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();
            var jobSerializer            = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var logger = TraceLogger.Create();
            var publishedNodesJobConverter = new PublishedNodesJobConverter(logger, newtonSoftJsonSerializer,
                                                                            engineConfigMock.Object, clientConfignMock.Object);

            using (var fileStream = new FileStream(_tempFile, FileMode.Open, FileAccess.Write)) {
                fileStream.Write(Encoding.UTF8.GetBytes("[]"));
            }

            var standaloneCliModel = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(standaloneCliModel);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var publishedNodesProvider = new PublishedNodesProvider(standaloneCliModelProviderMock.Object, logger);

            var orchestrator = new StandaloneJobOrchestrator(
                publishedNodesJobConverter,
                standaloneCliModelProviderMock.Object,
                agentConfigProviderMock.Object,
                jobSerializer,
                logger,
                publishedNodesProvider,
                newtonSoftJsonSerializer
                );

            var numberOfEndpoints = 100;
            var numberOfNodes     = 1000;

            var payload = new List <PublishedNodesEntryModel>();

            for (int endpointIndex = 0; endpointIndex < numberOfEndpoints; ++endpointIndex)
            {
                var model = new PublishedNodesEntryModel {
                    EndpointUrl = new Uri($"opc.tcp://server{endpointIndex}:49580"),
                };

                model.OpcNodes = new List <OpcNodeModel>();
                for (var nodeIndex = 0; nodeIndex < numberOfNodes; ++nodeIndex)
                {
                    model.OpcNodes.Add(new OpcNodeModel {
                        Id = $"ns=2;s=Node-Server-{nodeIndex}",
                    });
                }

                payload.Add(model);
            }

            // Publish all nodes.
            foreach (var request in payload)
            {
                await FluentActions
                .Invoking(async() => await orchestrator.PublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            async Task CheckEndpointsAndNodes(
                int expectedNumberOfEndpoints,
                int expectedNumberOfNodes
                )
            {
                var tasks = new List <Task <JobProcessingInstructionModel> >();

                for (var i = 0; i < expectedNumberOfEndpoints + 1; i++)
                {
                    tasks.Add(orchestrator.GetAvailableJobAsync(i.ToString(), new JobRequestModel()));
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);

                tasks.Count(t => t.Result != null)
                .Should()
                .Be(expectedNumberOfEndpoints);

                var distinctConfigurations = tasks
                                             .Where(t => t.Result != null)
                                             .Select(t => t.Result.Job.JobConfiguration)
                                             .Distinct();

                distinctConfigurations.Count()
                .Should()
                .Be(expectedNumberOfEndpoints);

                var writerGroups = tasks
                                   .Where(t => t.Result != null)
                                   .Select(t => jobSerializer.DeserializeJobConfiguration(
                                               t.Result.Job.JobConfiguration, t.Result.Job.JobConfigurationType) as WriterGroupJobModel);

                writerGroups.Select(
                    jobModel => jobModel.WriterGroup.DataSetWriters
                    .Select(writer => writer.DataSet.DataSetSource.PublishedVariables.PublishedData.Count())
                    .Sum()
                    ).Count(v => v == expectedNumberOfNodes)
                .Should()
                .Be(expectedNumberOfEndpoints);
            }

            // Check
            await CheckEndpointsAndNodes(numberOfEndpoints, numberOfNodes).ConfigureAwait(false);

            // Publish one more node for each endpoint.
            var payloadDiff = new List <PublishedNodesEntryModel>();

            for (int endpointIndex = 0; endpointIndex < numberOfEndpoints; ++endpointIndex)
            {
                var model = new PublishedNodesEntryModel {
                    EndpointUrl = new Uri($"opc.tcp://server{endpointIndex}:49580"),
                    OpcNodes    = new List <OpcNodeModel> {
                        new OpcNodeModel {
                            Id = $"ns=2;s=Node-Server-{numberOfNodes}",
                        }
                    }
                };

                payloadDiff.Add(model);
            }

            foreach (var request in payloadDiff)
            {
                await FluentActions
                .Invoking(async() => await orchestrator.PublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            // Check
            await CheckEndpointsAndNodes(numberOfEndpoints, numberOfNodes + 1).ConfigureAwait(false);

            // Unpublish new nodes for each endpoint.
            foreach (var request in payloadDiff)
            {
                await FluentActions
                .Invoking(async() => await orchestrator.UnpublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .NotThrowAsync()
                .ConfigureAwait(false);
            }

            // Check
            await CheckEndpointsAndNodes(numberOfEndpoints, numberOfNodes).ConfigureAwait(false);
        }
        public async Task UnpublishNodesOnNonExistingConfiguration(string existingConfig, string newConfig)
        {
            var standaloneCliModelProviderMock = new Mock <IStandaloneCliModelProvider>();
            var agentConfigProviderMock        = new Mock <IAgentConfigProvider>();
            var engineConfigMock         = new Mock <IEngineConfiguration>();
            var clientConfignMock        = new Mock <IClientServicesConfig>();
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();
            var jobSerializer            = new PublisherJobSerializer(newtonSoftJsonSerializer);
            var logger = TraceLogger.Create();
            var publishedNodesJobConverter = new PublishedNodesJobConverter(logger, newtonSoftJsonSerializer,
                                                                            engineConfigMock.Object, clientConfignMock.Object);

            Utils.CopyContent(existingConfig, _tempFile);
            var standaloneCliModel = new StandaloneCliModel {
                PublishedNodesFile       = _tempFile,
                PublishedNodesSchemaFile = "Storage/publishednodesschema.json"
            };

            standaloneCliModelProviderMock.Setup(p => p.StandaloneCliModel).Returns(standaloneCliModel);
            agentConfigProviderMock.Setup(p => p.Config).Returns(new AgentConfigModel());

            var publishedNodesProvider = new PublishedNodesProvider(standaloneCliModelProviderMock.Object, logger);

            var orchestrator = new StandaloneJobOrchestrator(
                publishedNodesJobConverter,
                standaloneCliModelProviderMock.Object,
                agentConfigProviderMock.Object,
                jobSerializer,
                logger,
                publishedNodesProvider,
                newtonSoftJsonSerializer
                );

            string payload = Utils.GetFileContent(newConfig);
            var    unpublishNodesRequest = newtonSoftJsonSerializer.Deserialize <List <PublishedNodesEntryModel> >(payload);

            foreach (var request in unpublishNodesRequest)
            {
                await FluentActions
                .Invoking(async() => await orchestrator.UnpublishNodesAsync(request).ConfigureAwait(false))
                .Should()
                .ThrowAsync <MethodCallStatusException>()
                .WithMessage($"{{\"Message\":\"Response 404 Endpoint not found: {request.EndpointUrl}\",\"Details\":{{}}}}")
                .ConfigureAwait(false);
            }

            var tasks = new List <Task <JobProcessingInstructionModel> >();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(orchestrator.GetAvailableJobAsync(i.ToString(), new JobRequestModel()));
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);

            tasks.Count(t => t.Result != null)
            .Should()
            .Be(2);

            var distinctConfigurations = tasks
                                         .Where(t => t.Result != null)
                                         .Select(t => t.Result.Job.JobConfiguration)
                                         .Distinct();

            distinctConfigurations.Count()
            .Should()
            .Be(2);
        }