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())); }
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); }
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())); }
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); }
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); }); }
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); }
public override void handleMonitorSide(MonitorInterface monitorInterface) { monitorInterface.recieveMeasurementList(this); }
public override void handleMonitorSide(MonitorInterface monitorInterface) { monitorInterface.receiveNewClient(this); }
public override void handleMonitorSide(MonitorInterface monitorInterface) { monitorInterface.recieveChat(this); }
//private static ManualResetEvent _allDone = new ManualResetEvent(false); static void Main(string[] args) { //ServiceBase[] ServicesToRun; //ServicesToRun = new ServiceBase[]{ // new ServiceKOIPM(args) //}; //ServiceBase.Run(ServicesToRun); try { CommClass.OStype = Convert.ToInt32(args[0].ToString()); } catch { CommClass.OStype = 0; } CommClass.OStype = 1; CommClass.SetPubPath(); Commonality.ConsoleManage.objectTime(); CommClass.CreateConfig(); //CommClass.CreateServListTable(); //CommClass.CreateServList(); //CommClass.ReadXML(CommClass.ServListPath, ref CommClass.DtServList); DataTable dt = new DataTable(); CommClass.ReadXML(CommClass.ConfigFilePath, ref dt); if (dt.Rows.Count != 0) { #region 读取KMS配置相关信息 //读取数据库连接 CommClass.DBCONN = dt.Rows[0]["DBCONN"].ToString(); //本地服务器ID CommClass.ID = dt.Rows[0]["ID"].ToString(); //本地服务IP地址 CommClass.IP = dt.Rows[0]["IP"].ToString(); //是否启用自动启动 CommClass.ISAUTOSTART = dt.Rows[0]["ISAUTOSTART"].ToString(); //本地服务端口号 try { CommClass.PORT = Convert.ToInt32(dt.Rows[0]["PORT"].ToString()); } catch { CommClass.PORT = 0; } //上级服务ID CommClass.UPID = dt.Rows[0]["UPID"].ToString(); //上级服务IP地址 CommClass.UPIP = dt.Rows[0]["UPIP"].ToString(); //上级服务端口号 try { CommClass.UPPORT = Convert.ToInt32(dt.Rows[0]["UPPORT"].ToString()); } catch { CommClass.UPPORT = 0; } //数据库连接字符串 CommClass.DBCONN = dt.Rows[0]["DBCONN"].ToString(); //是否连接上级服务{0:不连接;1:连接} CommClass.ISCONUP = dt.Rows[0]["ISCONUP"].ToString(); #endregion if (CommClass.ISCONUP == "0") { CommonFunction.GetServerList(); } else { ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectUpServ.HeartSocketobjectTime), null); ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectUpServ.Start), null);//连接上级服务器 } AsynTCPSocket listener = new AsynTCPSocket(CommClass.OStype.ToString()); listener.listenerAddress = CommClass.IP; listener.listenerPort = CommClass.PORT; listener.ReceiveEvent += new AsynchronousSocketListenerReceiveEvent(tcpServer_ReceiveEvent.ReceiveEvent); listener.ExceptionHandlingEvent += new AsynchronousServerExceptionHandlingEvent(tcpServer_ExceptionHandlingEvent.ReceiveEvent); listener.Start(); while (!listener.IsBound) { Thread.Sleep(500); } if (listener.IsBound) { Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor:SOCKET=" + CommClass.IP + ":" + CommClass.PORT.ToString() + " TCP服務啟動成功", ""); } else { Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor:SOCKET=" + CommClass.IP + ":" + CommClass.PORT.ToString() + " TCP服務啟動失敗", ""); } MonitorInterface.AlarmEvent += new ServMonitorAlarmHandlingEvent(ServMonitor_AlarmHandlingEvent.AlarmEvent); MonitorInterface.OptEvent += new ServMonitorOptHandlingEvent(ServMonitor_OptHandlingEvent.OptEvent); MonitorInterface MonInterface = new MonitorInterface(); MonInterface.Start(CommClass.OStype.ToString(), CommClass.ISAUTOSTART); } }
public override void handleMonitorSide(MonitorInterface monitorInterface) { monitorInterface.recievePacketSessions(this); }
public virtual void handleMonitorSide(MonitorInterface monitorInterface) { }
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>()); }