public void Test_Snapshot_Behind_Stream_EmptyCache() { var cache = new DefaultLastValueCache <int, MockMessage>(); var subscriber = new MockTopicSubscriber(); var snapshotClient = new MockSnapshotClient { Data = new[] { new MockMessage { Data = new byte[] { 1, 11 } }, new MockMessage { Data = new byte[] { 2, 22 } }, new MockMessage { Data = new byte[] { 3, 33 } } } }; var subscription = new TopicSubscription <MockMessage> { Topic = "", Deserializer = m => new MockMessage { Data = m }, MessageHandler = m => Debug.WriteLine("[{0},{1}]", m.Data[0], m.Data[1]) }; var synchronizer = new TopicSynchronizer <int, MockMessage, IList <MockMessage> >( subscriber, subscription, cache, s => snapshotClient, (newValue, cachedValue) => newValue.Data[1] > cachedValue.Data[1], m => m.Data[1] >= 10, m => m.Data[0], x => x); Assert.IsTrue(cache.IsEmpty); Task.Run(() => { for (byte i = 50; i < 250; i++) { subscriber.InvokeSubscriptionAccessor("", new byte[] { 1, i }); Thread.Sleep(10); } }); synchronizer.Init(); Assert.AreEqual(3, cache.Count); subscriber.InvokeSubscriptionAccessor("", new byte[] { 1, 10 }); Assert.AreEqual(3, cache.Count); Assert.IsTrue(cache[1].Data[1] >= 50); subscriber.InvokeSubscriptionAccessor("", new byte[] { 1, 9 }); Assert.IsTrue(cache[1].Data[1] >= 50); }
public void Test_All_Methods() { ILastValueCache<int, int> cache = new DefaultLastValueCache<int, int>(); int value; Assert.IsFalse(cache.TryGetValue(111, out value)); cache.UpdateValue(111, 999); Assert.IsTrue(cache.TryGetValue(111, out value)); Assert.AreEqual(999, value); Assert.AreEqual(999, cache[111]); }
public void Test_All_Methods() { ILastValueCache <int, int> cache = new DefaultLastValueCache <int, int>(); int value; Assert.IsFalse(cache.TryGetValue(111, out value)); cache.UpdateValue(111, 999); Assert.IsTrue(cache.TryGetValue(111, out value)); Assert.AreEqual(999, value); Assert.AreEqual(999, cache[111]); }
private static void Main(string[] args) { var knownTypes = new Dictionary <Type, TypeConfig>(); knownTypes.Add(typeof(MyMessage), new TypeConfig { Serializer = new WireSerializer(), Comparer = new DefaultComparer <MyMessage>(), KeyExtractor = new DefaultKeyExtractor <MyMessage>(x => x.Key) }); var topics = new Dictionary <string, Type>(); topics.Add("topic1", typeof(MyMessage)); int counter = 0; var cache = new DefaultLastValueCache <object>(topics.Keys, (topic, key, value) => { Console.Title = $"Received: {Interlocked.Increment(ref counter)}"; //Console.WriteLine($"Client Cache Updated. Topic:{topic} Key:{key} Value:{value} ClientTime:{DateTime.Now:hh:mm:ss.fff}"); }); using (new Subscriber(new[] { "tcp://localhost" }, 6669, 6668, knownTypes, topics, cache, (t, c, n) => Debug.WriteLine($"Gap in message id. Current:{c} New:{n}"))) { while (Console.ReadKey().Key != ConsoleKey.Escape) { } } //using (var snapshotClient = new SnapshotClient(TimeSpan.FromSeconds(30), "tcp://localhost:6668")) //{ // snapshotClient.Connect(); // NetMQMessage snapshot; // if (snapshotClient.TryGetSnapshot("A", out snapshot)) // Console.WriteLine(snapshot.Last.ConvertToString()); //} //new Simple().Run("tcp://localhost:6669"); //var client = new ReliableClient(new[] { "tcp://localhost:6669" }, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), m => // { // Console.WriteLine($"Message received. Topic: {m.First.ConvertToString()}, Message: {m.Last.ConvertToString()}"); // }, (x, m) => Console.WriteLine($"Error in message handler. Exception {x} Message {m}"), // null); //client.Subscribe("topic1"); }