// exposed for testing
        internal void WaitUntilInactive()
        {
            TestSyncMessage message = new TestSyncMessage();

            SubmitMessage(message);
            message.WaitForCompletion();
        }
Beispiel #2
0
        public void DoSyncSlaveSimpleTest()
        {
            using (SlaveManager currentSlaveManager = new SlaveManager()) {
                IIPCGUID slaveReceaverGUID = new IPCReceaverGUID(currentSlaveManager.LaunchSlave());
                // wait for slave is launched and ininialized;
                Thread.CurrentThread.Join(3000);
                using (BaseIPCDispatcher dispatcher = new BaseIPCDispatcher(slaveReceaverGUID)) {
                    TestSyncMessage test = new TestSyncMessage(dispatcher.Receaver);
                    test.StrIn   = "Hi Slave!";
                    test.TimeOut = SlaveResponces.SyncMessageSlaveDelay + 2000;
                    IPCDispatchResult dispatchResult = dispatcher.Dispatch(test);
                    Assert.IsTrue(dispatchResult == IPCDispatchResult.Success, "Unable to send message error because of the reason {0}", dispatchResult);
                    Assert.IsTrue(String.Equals(test.StrOut, SlaveResponces.TestSyncResponceString), "Time is up");
                }

                using (BaseIPCDispatcher dispatcher = new BaseIPCDispatcher(slaveReceaverGUID)) {
                    TestSyncMessage test = new TestSyncMessage(dispatcher.Receaver);
                    test.StrIn   = "Hi Slave!";
                    test.TimeOut = SlaveResponces.SyncMessageSlaveDelay - 2000;
                    IPCDispatchResult dispatchResult = dispatcher.Dispatch(test);
                    Assert.IsTrue(dispatchResult
                                  == IPCDispatchResult.Timeout, "Timeout is an expected but {0} is dispatch result", dispatchResult);
                }
            }
        }
        public void DoSyncSelfSimpleTest()
        {
            IIPCGUID receaverGUID = new IPCReceaverGUID();

            using (BaseIPCDispatcher dispatcher = new BaseIPCDispatcher(receaverGUID)) {
                TestSyncMessage test = new TestSyncMessage(receaverGUID);
                test.StrIn = TestMessageIn;
                Assert.IsTrue(dispatcher.Dispatch(test) == IPCDispatchResult.Success, "Unable to send message");
                Assert.IsTrue(TestMessageOut.Equals(test.StrOut), "Message is corrupted");
            }
        }
        public void OnReceaveMessage(object sender, ReceaveMessageEventArgs e)
        {
            TestSyncMessage testSyncMessage = e.Message as TestSyncMessage;
            IIPCReceaver    currentReceaver = sender as IIPCReceaver;

            if (currentReceaver != null && testSyncMessage != null)
            {
                Assert.IsTrue(currentReceaver.ReceaverID.Equals(testSyncMessage.SenderID), "Message receaved from wrong receaver");
                Assert.IsTrue(TestMessageIn.Equals(testSyncMessage.StrIn), "Message is corrupted");
                testSyncMessage.StrOut = TestMessageOut;
            }
        }
Beispiel #5
0
        public static void OnReceaveMessage(object sender, ReceaveMessageEventArgs e)
        {
            Console.WriteLine(String.Format("Receaved message of type - {0} from sender with id = {1}", e.Message.MessageType, e.Message.SenderID.Value));
            TestAsyncMessage testAsyncMessage = e.Message as TestAsyncMessage;

            if (testAsyncMessage != null)
            {
                Console.WriteLine("Preparing responce to the master..." + testAsyncMessage.GetType().FullName);
                TestAsyncMessage test = new TestAsyncMessage(new IPCReceaverGUID());
                test.StrData = SlaveResponces.TestAsyncResponceString;
                Console.WriteLine("Forward responce to the master...");
                ForwardResponce(test, testAsyncMessage.SenderID);
                return;
            }

            TestAsyncComplexMessage testComplexAsyncMessage = e.Message as TestAsyncComplexMessage;

            if (testComplexAsyncMessage != null)
            {
                Console.WriteLine("Preparing responce to the master..." + testComplexAsyncMessage.GetType().FullName);
                TestAsyncComplexMessage test = new TestAsyncComplexMessage(new IPCReceaverGUID(), SlaveResponces.ConstructComplexResponceTemplate());
                Console.WriteLine("Forward responce to the master...");
                ForwardResponce(test, testComplexAsyncMessage.SenderID);
                return;
            }

            TestSyncMessage testSyncMessage = e.Message as TestSyncMessage;

            if (testSyncMessage != null)
            {
                Console.WriteLine("Emulation of some processing");
                Thread.CurrentThread.Join(SlaveResponces.SyncMessageSlaveDelay);
                testSyncMessage.StrOut = SlaveResponces.TestSyncResponceString;
                Console.WriteLine("Continue work....");
            }
        }