예제 #1
0
        static string StartClients(string sctx, SynchronizedLogger logger, out DomainCommunicationProvider clientsNetworkProvider)
        {
            var configuration = Configuration.Create().WithMonitorsInProductionEnabled().WithVerbosityEnabled(2);
            var runtime       = PSharpRuntime.Create(configuration);
            var runtimeHost   = HostInfo.NewRuntimeHost(runtime);

            clientsNetworkProvider = new DomainCommunicationProvider(runtimeHost, "clients");
            runtimeHost.SetNetworkProvider(clientsNetworkProvider);
            runtimeHost.SetLogger(logger);

            var messages = new MessageCollection();

            messages.CollectionChanged += (sender, e) => logger.WriteLine(e.NewItems[0].ToString());
            var ctx = sctx.FromJson <DistributedStorageContext>();

            var synchronizable = Synchronizable.Empty();

            foreach (var storageNode in ctx.StorageNodes)
            {
                var waitIfHandledReplReq = logger.MachineActionHandledWait((machineId, _, actionName) => Equals(machineId, storageNode.Id) && actionName == "HandleReplReq");
                synchronizable = synchronizable.Then(waitIfHandledReplReq.Delay(10));
            }
            logger.ApplySynchronization(synchronizable);

            NewClients(runtimeHost, ctx, messages);
            logger.WaitForWriting(6000);
            return(ctx.ToJson());
        }
        public void Initializer_and_OnEnterInvoke_can_specify_to_the_same_place()
        {
            // Arrange
            var configuration = Configuration.Create().WithVerbosityEnabled(2);
            var runtime       = PSharpRuntime.Create(configuration);
            var runtimeHost   = HostInfo.NewRuntimeHost(runtime);

            var logger = new SynchronizedLogger(new InMemoryLogger());
            var waitIfEnteredInitialized1 = logger.MachineActionHandledWait((machineId, _, actionName) => machineId.Name.Contains("M1") && actionName == "EnterInitialized");
            var waitIfEnteredInitialized2 = logger.MachineActionHandledWait((machineId, _, actionName) => machineId.Name.Contains("M2") && actionName == "EnterInitialized");

            logger.ApplySynchronization(waitIfEnteredInitialized2.Then(waitIfEnteredInitialized1));
            runtimeHost.SetLogger(logger);


            // Act
            runtimeHost.New(MachineInterface.Sender <M1.ISender>().Bundler <M1.IBundler>().Receiver <M1.Receiver>());
            runtimeHost.New(MachineInterface.Sender <M2.ISender>().Bundler <M2.IBundler>().Receiver <M2.Receiver>());


            // Assert
            Assert.DoesNotThrow(() => logger.WaitForWriting(1000));
        }