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); } } }
public void TestWoopsaClientSubscriptionToProperty() { bool isValueChanged = false; TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaClientProperty propertyVotes = root.Properties.ByName("Votes") as WoopsaClientProperty; WoopsaClientSubscription subscription = propertyVotes.Subscribe((sender, e) => { isValueChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); objectServer.Votes = 2; Stopwatch watch = new Stopwatch(); watch.Start(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(20))) { 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); } } }
public void TestWoopsaClientSubscriptionToProperty() { bool isVotesChanged = false; bool isStringValueChanged = false; TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer, TestingPort)) { using (WoopsaClient client = new WoopsaClient(TestingUrl)) { int newVotes = 0; string newStringValue = string.Empty; WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaClientProperty propertyVotes = root.Properties.ByName("Votes") as WoopsaClientProperty; WoopsaClientSubscription subscription = propertyVotes.Subscribe((sender, e) => { newVotes = e.Notification.Value; isVotesChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); WoopsaClientProperty propertyString = root.Properties.ByName("StringValue") as WoopsaClientProperty; WoopsaClientSubscription subscription2 = propertyString.Subscribe((sender, e) => { var t = client.ClientProtocol.Read("Votes"); newStringValue = e.Notification.Value; isStringValueChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); objectServer.Votes = 2; objectServer.StringValue = "Test"; Stopwatch watch = new Stopwatch(); watch.Start(); while ((!isVotesChanged || !isStringValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(20))) { Thread.Sleep(10); } if (isVotesChanged) { Console.WriteLine("Notification after {0} ms", watch.Elapsed.TotalMilliseconds); } else { Console.WriteLine("No notification received"); } subscription.Unsubscribe(); Assert.AreEqual(true, isVotesChanged); Assert.AreEqual(true, isStringValueChanged); Assert.AreEqual(2, newVotes); Assert.AreEqual("Test", newStringValue); } } }
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 TestWoopsaClientSubscriptionDisappearingProperty() { bool isValueChanged = false; MainClass objectServer = new MainClass(); InnerClass inner = new InnerClass(); objectServer.Inner = inner; using (WoopsaServer server = new WoopsaServer(objectServer, TestingPort)) { using (WoopsaClient client = new WoopsaClient(TestingUrl)) { WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaObject Inner = root.Items.ByName(nameof(MainClass.Inner)) as WoopsaObject; WoopsaClientProperty propertyInfo = Inner.Properties.ByName(nameof(InnerClass.Info)) as WoopsaClientProperty; WoopsaClientSubscription subscription = propertyInfo.Subscribe( (sender, e) => { isValueChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); inner.Info = "Test"; Stopwatch watch = new Stopwatch(); watch.Start(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(20))) { Thread.Sleep(10); } if (isValueChanged) { Console.WriteLine("Notification after {0} ms", watch.Elapsed.TotalMilliseconds); } else { Console.WriteLine("No notification received"); } isValueChanged = false; objectServer.Inner = new BaseInnerClass(); // objectServer.Inner = new object(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(20))) { Thread.Sleep(10); } subscription.Unsubscribe(); Assert.AreEqual(true, isValueChanged); } } }
public void TestWoopsaClientSubscriptionChannelNoRemoteSubscriptionService() { bool isValueChanged = false; WoopsaObject objectServer = new WoopsaObject(null, ""); int votes = 0; WoopsaProperty propertyVotes = new WoopsaProperty(objectServer, "Votes", WoopsaValueType.Integer, (p) => votes, (p, value) => { votes = value.ToInt32(); }); using (WoopsaServer server = new WoopsaServer((IWoopsaContainer)objectServer, TestingPort)) { using (WoopsaClient client = new WoopsaClient(TestingUrl)) { WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaClientSubscription subscription = root.Subscribe(nameof(TestObjectServer.Votes), (sender, e) => { isValueChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); votes = 2; Stopwatch watch = new Stopwatch(); watch.Start(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(2000))) { 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); } } }
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(); } }