Пример #1
0
        public void TestClientDisconnectRaisesDisconnectedEventOnQueryHandle()
        {
            ICacheEntryEvent <int, int> lastEvt = null;
            var qry = new ContinuousQueryClient <int, int>(
                new DelegateListener <int, int>(e => lastEvt = e));

            var client = GetClient();
            var cache  = client.GetOrCreateCache <int, int>(TestUtils.TestName);
            var handle = cache.QueryContinuous(qry);

            ContinuousQueryClientDisconnectedEventArgs disconnectedEventArgs = null;

            handle.Disconnected += (sender, args) =>
            {
                disconnectedEventArgs = args;

                // ReSharper disable once AccessToDisposedClosure (disposed state does not matter)
                Assert.AreEqual(handle, sender);
            };

            cache[1] = 1;
            TestUtils.WaitForTrueCondition(() => lastEvt != null);

            client.Dispose();

            // Assert: disconnected event has been raised.
            TestUtils.WaitForTrueCondition(() => disconnectedEventArgs != null);
            Assert.IsNotNull(disconnectedEventArgs.Exception);

            StringAssert.StartsWith("Cannot access a disposed object", disconnectedEventArgs.Exception.Message);

            // Multiple dispose is allowed.
            handle.Dispose();
            handle.Dispose();
        }
        /** <inheritDoc /> */
        public bool Evaluate(IBinaryStream stream)
        {
            // ReSharper disable once InconsistentlySynchronizedField
            ICacheEntryEvent <TK, TV> evt = CQU.ReadEvent <TK, TV>(stream, _ignite.Marshaller, _keepBinary);

            return(_filter.Evaluate(evt));
        }
Пример #3
0
        public void TestContinuousQueryWithFilterReceivesOnlyMatchingEvents()
        {
            var cache = Client.GetOrCreateCache <int, int>(TestUtils.TestName);

            ICacheEntryEvent <int, int> lastEvt = null;
            var listener = new DelegateListener <int, int>(e => lastEvt = e);

            var qry = new ContinuousQueryClient <int, int>(listener)
            {
                Filter = new OddKeyFilter()
            };

            using (cache.QueryContinuous(qry))
            {
                cache.Put(0, 0);
                TestUtils.WaitForTrueCondition(() => OddKeyFilter.LastKey == 0);
                Assert.IsNull(lastEvt);

                cache.Put(5, 5);
                TestUtils.WaitForTrueCondition(() => OddKeyFilter.LastKey == 5);
                TestUtils.WaitForTrueCondition(() => lastEvt != null);
                Assert.IsNotNull(lastEvt);
                Assert.AreEqual(5, lastEvt.Key);

                cache.Put(8, 8);
                TestUtils.WaitForTrueCondition(() => OddKeyFilter.LastKey == 8);
                Assert.AreEqual(5, lastEvt.Key);
            }
        }
Пример #4
0
        /** <inheritdoc /> */
        public bool Evaluate(IBinaryStream stream)
        {
            Debug.Assert(_filter != null, "Evaluate should not be called if filter is not set.");

            ICacheEntryEvent <TK, TV> evt = CQU.ReadEvent <TK, TV>(stream, _marsh, _keepBinary);

            return(_filter.Evaluate(evt));
        }
Пример #5
0
 public bool Evaluate(ICacheEntryEvent <int, string> e)
 {
     if (e.Key == 1)
     {
         return(false);
     }
     Console.WriteLine("the value for key {0} was updated from {1} to {2}", e.Key, e.OldValue, e.Value);
     return(true);
 }
Пример #6
0
        public bool Evaluate(ICacheEntryEvent <ITAGFileBufferQueueKey, TAGFileBufferQueueItem> evt)
        {
            // Add the keys for the given events into the Project/Asset mapping buckets ready for a processing context
            // to acquire them
            handler.Add(evt.Key);

            // Advise the caller this item is not filtered [as have already dealt with it so no further
            // processing of the item is required.
            return(false);
        }
            /** <inheritDoc /> */
            public bool Evaluate(ICacheEntryEvent <int, V> evt)
            {
                if (err)
                {
                    throw new Exception("Filter error.");
                }

                FILTER_EVTS.Add(new FilterEvent(ignite, CreateEvent(evt)));

                return(res);
            }
Пример #8
0
            /** <inheritDoc /> */
            public bool Evaluate(ICacheEntryEvent <int, V> evt)
            {
                if (err)
                {
                    throw new Exception("Filter error.");
                }

                FILTER_EVTS.Add(new FilterEvent(ignite,
                                                CQU.CreateEvent <object, object>(evt.Key, evt.OldValue, evt.Value)));

                return(res);
            }
        /// <summary>
        /// Creates object-typed event.
        /// </summary>
        private static ICacheEntryEvent <object, object> CreateEvent <T, V>(ICacheEntryEvent <T, V> e)
        {
            switch (e.EventType)
            {
            case CacheEntryEventType.Created:
                return(new CacheEntryCreateEvent <object, object>(e.Key, e.Value));

            case CacheEntryEventType.Updated:
                return(new CacheEntryUpdateEvent <object, object>(e.Key, e.OldValue, e.Value));

            default:
                return(new CacheEntryRemoveEvent <object, object>(e.Key, e.OldValue));
            }
        }
Пример #10
0
        /// <summary>
        /// Creates object-typed event.
        /// </summary>
        private static ICacheEntryEvent <object, object> CreateEvent <T, V>(ICacheEntryEvent <T, V> e)
        {
            if (!e.HasOldValue)
            {
                return(new CacheEntryCreateEvent <object, object>(e.Key, e.Value));
            }

            if (e.Value.Equals(e.OldValue))
            {
                return(new CacheEntryRemoveEvent <object, object>(e.Key, e.OldValue));
            }

            return(new CacheEntryUpdateEvent <object, object>(e.Key, e.OldValue, e.Value));
        }
Пример #11
0
        public static ICacheEntryEvent <TK, TV>[] ReadEvents <TK, TV>(IBinaryStream stream,
                                                                      Marshaller marsh, bool keepBinary)
        {
            var reader = marsh.StartUnmarshal(stream, keepBinary);

            int cnt = reader.ReadInt();

            ICacheEntryEvent <TK, TV>[] evts = new ICacheEntryEvent <TK, TV> [cnt];

            for (int i = 0; i < cnt; i++)
            {
                evts[i] = ReadEvent0 <TK, TV>(reader);
            }

            return(evts);
        }
Пример #12
0
 /** <inheritdoc /> */
 public bool Evaluate(ICacheEntryEvent <int, int> evt)
 {
     throw new Exception(Error);
 }
Пример #13
0
 public bool Evaluate(ICacheEntryEvent <TK, TV> evt)
 {
     throw new InvalidOperationException(GetType() + " cannot be invoked directly.");
 }
Пример #14
0
 /// <summary>
 /// Evaluates cache entry event.
 /// </summary>
 /// <param name="evt">Event.</param>
 public bool Evaluate(ICacheEntryEvent <int, string> evt)
 {
     return(evt.Key >= _threshold);
 }
Пример #15
0
 public bool Evaluate(ICacheEntryEvent <long, object> evt)
 {
     _ignite.GetServices().GetService <StreamService>(nameof(StreamService))
     .UpdateStreamItemAsync(_stream, evt.Key);
     return(false);
 }
Пример #16
0
            /** <inheritdoc /> */
            public bool Evaluate(ICacheEntryEvent <int, IBinaryObject> evt)
            {
                LastValue = evt.Value;

                return(evt.Value.GetField <int>("Id") % 2 == 0);
            }
Пример #17
0
        /** <inheritDoc /> */
        public bool Evaluate(IBinaryStream stream)
        {
            ICacheEntryEvent <TK, TV> evt = CQU.ReadEvent <TK, TV>(stream, _ignite.Marshaller, _keepBinary);

            return(_filter.Evaluate(evt));
        }
Пример #18
0
            /** <inheritdoc /> */
            public bool Evaluate(ICacheEntryEvent <int, int> evt)
            {
                LastKey = evt.Key;

                return(evt.Key % 2 == 1);
            }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="ignite">Grid.</param>
 /// <param name="entry">Entry.</param>
 public FilterEvent(IIgnite ignite, ICacheEntryEvent <object, object> entry)
 {
     this.ignite = ignite;
     this.entry  = entry;
 }
Пример #20
0
            /** <inheritdoc /> */
            public bool Evaluate(ICacheEntryEvent <int, Person> evt)
            {
                LastValue = evt.Value;

                return(evt.Value.Id % 2 == 0);
            }