public void TestWoopsaClientSubscriptionChannelServerStartAfter()
        {
            bool             isValueChanged = false;
            TestObjectServer objectServer   = new TestObjectServer();

            using (WoopsaClient client = new WoopsaClient(TestingUrl))
            {
                WoopsaUnboundClientObject root         = client.CreateUnboundRoot("");
                WoopsaClientSubscription  subscription = root.Subscribe(nameof(TestObjectServer.Votes),
                                                                        (sender, e) => { isValueChanged = true; },
                                                                        TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20));
                using (WoopsaServer server = new WoopsaServer(objectServer, TestingPort))
                {
                    objectServer.Votes = 2;
                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(2)))
                    {
                        Thread.Sleep(10);
                    }
                    if (isValueChanged)
                    {
                        Console.WriteLine("Notification after {0} ms", watch.Elapsed.TotalMilliseconds);
                    }
                    else
                    {
                        Console.WriteLine("No notification received");
                    }
                    subscription.Unsubscribe();
                    Assert.AreEqual(true, isValueChanged);
                }
            }
        }
Beispiel #2
0
        public void TestWoopsaIsLastCommunicationSuccessful()
        {
            bool             isSuccessfull = false;
            TestObjectServer objectServer  = new TestObjectServer();

            using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa"))
            {
                WoopsaUnboundClientObject root         = client.CreateUnboundRoot("root");
                WoopsaClientSubscription  subscription = root.Subscribe(nameof(TestObjectServer.Votes),
                                                                        (sender, e) => {  },
                                                                        TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20));
                client.ClientProtocol.IsLastCommunicationSuccessfulChange +=
                    (sender, e) =>
                {
                    isSuccessfull = client.ClientProtocol.IsLastCommunicationSuccessful;
                };
                Stopwatch watch = new Stopwatch();
                using (WoopsaServer server = new WoopsaServer(objectServer))
                {
                    watch.Restart();
                    while ((!isSuccessfull) && (watch.Elapsed < TimeSpan.FromSeconds(20)))
                    {
                        Thread.Sleep(10);
                    }
                    if (isSuccessfull)
                    {
                        Console.WriteLine("Sucessful after {0} ms", watch.Elapsed.TotalMilliseconds);
                    }
                    else
                    {
                        Console.WriteLine("No successful communication");
                    }
                    Assert.IsTrue(isSuccessfull);
                }
                watch.Restart();
                while ((isSuccessfull) && (watch.Elapsed < TimeSpan.FromSeconds(20)))
                {
                    Thread.Sleep(10);
                }
                if (!isSuccessfull)
                {
                    Console.WriteLine("Communication loss detected after {0} ms", watch.Elapsed.TotalMilliseconds);
                }
                else
                {
                    Console.WriteLine("No communication loss detection");
                }
                Assert.IsFalse(isSuccessfull);
                subscription.Unsubscribe();
            }
        }
        public void TestWoopsaProtocolUnboundClient()
        {
            TestObjectServer objectServer = new TestObjectServer();

            using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa"))
            {
                WoopsaUnboundClientObject root         = client.CreateUnboundRoot("root");
                WoopsaProperty            propertyVote = root.GetProperty("Votes", WoopsaValueType.Integer, false);
                using (WoopsaServer server = new WoopsaServer(objectServer))
                {
                    propertyVote.Value = new WoopsaValue(123);
                    Assert.AreEqual(objectServer.Votes, 123);
                    var result = propertyVote.Value;
                    Assert.AreEqual(result.ToInt64(), 123);
                }
            }
        }
        public void TestWoopsaIsLastCommunicationSuccessful()
        {
            bool             isSuccessfull = false;
            int              counter       = 0;
            TestObjectServer objectServer  = new TestObjectServer();

            using (WoopsaClient client = new WoopsaClient(TestingUrl))
            {
                Assert.IsFalse(client.ClientProtocol.IsLastCommunicationSuccessful);

                client.ClientProtocol.IsLastCommunicationSuccessfulChange +=
                    (sender, e) =>
                {
                    isSuccessfull = client.ClientProtocol.IsLastCommunicationSuccessful;
                    counter++;
                };
                // Initial & unsuccessful
                try
                {
                    client.ClientProtocol.Read("Not existing");
                }
                catch
                { }
                Assert.IsFalse(isSuccessfull);
                Assert.AreEqual(1, counter);


                WoopsaUnboundClientObject root         = client.CreateUnboundRoot("root");
                WoopsaClientSubscription  subscription = root.Subscribe(nameof(TestObjectServer.Votes),
                                                                        (sender, e) => {  },
                                                                        TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20));

                Stopwatch watch = new Stopwatch();
                using (WoopsaServer server = new WoopsaServer(objectServer, TestingPort))
                {
                    watch.Restart();
                    while ((!isSuccessfull) && (watch.Elapsed < TimeSpan.FromSeconds(20)))
                    {
                        Thread.Sleep(10);
                    }
                    if (isSuccessfull)
                    {
                        Console.WriteLine("Sucessful after {0} ms", watch.Elapsed.TotalMilliseconds);
                    }
                    else
                    {
                        Console.WriteLine("No successful communication");
                    }
                    Assert.IsTrue(isSuccessfull);
                }
                watch.Restart();
                while ((isSuccessfull) && (watch.Elapsed < TimeSpan.FromSeconds(20)))
                {
                    Thread.Sleep(10);
                }
                if (!isSuccessfull)
                {
                    Console.WriteLine("Communication loss detected after {0} ms", watch.Elapsed.TotalMilliseconds);
                }
                else
                {
                    Console.WriteLine("No communication loss detection");
                }
                Assert.IsFalse(isSuccessfull);
                subscription.Unsubscribe();
            }
        }