コード例 #1
0
        public void Monitor_should_not_notify_safety_bug_if_it_is_not_existing()
        {
            // Arrange
            var configuration = Configuration.Create().WithMonitorsInProductionEnabled();
            var runtime       = PSharpRuntime.Create(configuration);
            var runtimeHost   = HostInfo.NewRuntimeHost(runtime);
            var safetyMonitor = runtimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());


            // Act
            var messages = new MessageCollection();

            safetyMonitor.Configure(new ConfigureSafetyMonitor(messages));

            var storageNodeId   = runtime.NewMachine(typeof(StorageNode));
            var storageNodeMock = new Mock <IStorageNodeSender>();

            storageNodeMock.SetupGet(_ => _.Id).Returns(storageNodeId);
            safetyMonitor.Handshake(new HandshakeSafetyMonitor(new[] { storageNodeMock.Object }));

            safetyMonitor.LogUpdated(new LogUpdated(storageNodeMock.Object, 42));


            // Assert
            Assert.DoesNotThrow(() => safetyMonitor.Ack(new Ack()));
        }
コード例 #2
0
        public void Monitor_should_notify_safety_bug_if_it_is_existing()
        {
            // Arrange
            var configuration = Configuration.Create().WithMonitorsInProductionEnabled();
            var runtime       = PSharpRuntime.Create(configuration);
            var runtimeHost   = HostInfo.NewRuntimeHost(runtime);
            var safetyMonitor = runtimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());


            // Act
            var messages = new MessageCollection();

            safetyMonitor.Configure(new ConfigureSafetyMonitor(messages));

            var storageNodeId   = runtime.NewMachine(typeof(StorageNode));
            var storageNodeMock = new Mock <IStorageNodeSender>();

            storageNodeMock.SetupGet(_ => _.Id).Returns(storageNodeId);
            safetyMonitor.Handshake(new HandshakeSafetyMonitor(new[] { storageNodeMock.Object }));


            // Assert
            var expectedExType = typeof(PSharpRuntime).Assembly.GetTypes().First(_ => _.FullName == "Microsoft.PSharp.AssertionFailureException");

            Assert.Throws(expectedExType, () => safetyMonitor.Ack(new Ack()));
        }
コード例 #3
0
        public void Context_should_return_same_Monitor_if_it_is_in_remote_and_single_application()
        {
            // Arrange
            var expected  = default(int);
            var actual    = default(int);
            var parameter = default(string);

            // Act
            {
                var configuration = Configuration.Create().WithMonitorsInProductionEnabled();
                var runtime       = PSharpRuntime.Create(configuration);
                var runtimeHost   = HostInfo.NewRuntimeHost(runtime);

                var ctx = runtimeHost.New <DistributedStorageContext>();
                ctx.SafetyMonitor = runtimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());
                expected          = RuntimeHelpers.GetHashCode(ctx.SafetyMonitor);
                parameter         = ctx.ToJson();
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            {
                var ctx = parameter.FromJson <DistributedStorageContext>();
                actual = RuntimeHelpers.GetHashCode(ctx.SafetyMonitor);
            }


            // Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        public void Context_should_return_same_Monitor_if_it_is_in_local_and_single_application()
        {
            // Arrange
            var ctx      = default(DistributedStorageContext);
            var expected = default(int);
            var actual   = default(int);

            // Act
            {
                var configuration = Configuration.Create().WithMonitorsInProductionEnabled();
                var runtime       = PSharpRuntime.Create(configuration);
                var runtimeHost   = HostInfo.NewRuntimeHost(runtime);

                ctx = runtimeHost.New <DistributedStorageContext>();
                ctx.SafetyMonitor = runtimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());
                expected          = RuntimeHelpers.GetHashCode(ctx.SafetyMonitor);
            }

            {
                actual = RuntimeHelpers.GetHashCode(ctx.SafetyMonitor);
            }


            // Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void Monitor_can_be_created_faster_than_the_first_time()
        {
            AppDomain.CurrentDomain.RunAtIsolatedDomain(() =>
            {
                // Arrange
                var configuration = Configuration.Create().WithMonitorsInProductionEnabled();
                var runtime       = PSharpRuntime.Create(configuration);
                var runtimeHost   = HostInfo.NewRuntimeHost(runtime);


                // Act
                var sw1 = Stopwatch.StartNew();
                runtimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());
                var elapsed1 = sw1.ElapsedTicks;

                var sw10 = Stopwatch.StartNew();
                for (var i = 0; i < 10; i++)
                {
                    runtimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());
                }
                var elapsed10 = sw10.ElapsedTicks;


                // Assert
                Assert.Less(elapsed10, elapsed1 / 10);
            });
        }
コード例 #6
0
        public void Context_should_not_return_same_Monitor_if_it_is_in_remote_and_multi_application()
        {
            // Arrange
            var expected        = default(int);
            var actual          = default(int);
            var expected_Assign = new MarshalByRefAction <int>(i => expected = i);
            var actual_Assign   = new MarshalByRefAction <int>(i => actual = i);

            // Act
            AppDomain.CurrentDomain.RunAtIsolatedDomain((expected_Assign_, actual_Assign_) =>
            {
                var configuration = Configuration.Create().WithMonitorsInProductionEnabled();
                var runtime       = PSharpRuntime.Create(configuration);
                var runtimeHost   = HostInfo.NewRuntimeHost(runtime);
                using (var networkProvider = new DomainCommunicationProvider(runtimeHost, "monitors"))
                {
                    var parameter = default(string);
                    {
                        runtimeHost.SetNetworkProvider(networkProvider);

                        var ctx           = runtimeHost.New <DistributedStorageContext>();
                        ctx.SafetyMonitor = runtimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());
                        ctx.SafetyMonitor.Configure(new ConfigureSafetyMonitor(new MessageCollection()));
                        expected_Assign_.Invoke(RuntimeHelpers.GetHashCode(ctx.SafetyMonitor));
                        parameter = ctx.ToJson();
                    }

                    AppDomain.CurrentDomain.RunAtIsolatedDomain((actual_Assign__, parameter_) =>
                    {
                        var ctx = parameter_.FromJson <DistributedStorageContext>();
                        actual_Assign__.Invoke(RuntimeHelpers.GetHashCode(ctx.SafetyMonitor));
                        ctx.SafetyMonitor.Handshake(new HandshakeSafetyMonitor(new IStorageNodeSender[0]));
                    }, actual_Assign_, parameter);
                }
            }, expected_Assign, actual_Assign);


            // Assert
            Assert.AreNotEqual(expected, actual);
        }
コード例 #7
0
 public void NewMonitors(DistributedStorageContext ctx, MessageCollection messages)
 {
     ctx.SafetyMonitor = RuntimeHost.New(MonitorInterface.Sender <ISafetyMonitorSender>().Bundler <ISafetyMonitorBundler>().Receiver <SafetyMonitorReceiver>());
     ctx.SafetyMonitor.Configure(new ConfigureSafetyMonitor(messages));
     ctx.LivenessMonitor = RuntimeHost.New(MonitorInterface.Sender <ILivenessMonitorSender>().Bundler <ILivenessMonitorBundler>().Receiver <LivenessMonitorReceiver>());
 }