Exemple #1
0
        public void IncludeCurrentStateEventTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cache.Put("key1", "value1");
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.includeCurrentState  = true;
                cl.AddListener(listener.CreatedEventAction);
                AssertNoEvents(listener);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                AssertOnlyCreated("key1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Exemple #2
0
        public void CustomEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.converterFactoryName = "to-string-converter-factory";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                cache.Put("key1", "value1");
                AssertOnlyCustom("custom event: key1 value1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
        protected void TestAddRemoveListener(IRemoteCache <string, string> cache)
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Remove(K1);
                cache.Remove(K2);
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                cache.Put(K1, V1);
                var remoteEvent = listener.PollCreatedEvent();
                Assert.AreEqual(K1, remoteEvent.GetKey());
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
 public void CreatedEventTest()
 {
     IRemoteCache<string, string> cache = remoteManager.GetCache<string, string>();
     cache.Clear();
     Event.ClientListener<string, string> cl = new Event.ClientListener<string, string>();
     cl.filterFactoryName = "";
     cl.converterFactoryName = "";
     cl.addListener(createdEventAction);
     createdEventCounter = 0;
     createdSemaphore = new System.Threading.Semaphore(0, 1);
     cache.addClientListener(cl, new string[] { }, new string[] { }, null);
     Assert.AreEqual(0, createdEventCounter);
     cache.Put("key1", "value1");
     createdSemaphore.WaitOne();
     Assert.AreEqual(1, createdEventCounter);
     cache.removeClientListener(cl);
 }
Exemple #5
0
        public void ConditionalEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                AssertNoEvents(listener);
                cache.PutIfAbsent("key1", "value1");
                AssertOnlyCreated("key1", listener);
                cache.PutIfAbsent("key1", "value1again");
                AssertNoEvents(listener);
                cache.Replace("key1", "modified");
                AssertOnlyModified("key1", listener);
                cache.ReplaceWithVersion("key1", "modified", 0);
                AssertNoEvents(listener);
                IVersionedValue <string> versioned = cache.GetVersioned("key1");
                //TODO: this needs conversion from long to ulong (is it a bug?)
                cache.ReplaceWithVersion("key1", "modified", versioned.GetVersion());
                AssertOnlyModified("key1", listener);
                cache.RemoveWithVersion("key1", 0);
                AssertNoEvents(listener);
                versioned = cache.GetVersioned("key1");
                cache.RemoveWithVersion("key1", versioned.GetVersion());
                AssertOnlyRemoved("key1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Exemple #6
0
        private void AddClientListener <CQK, CQV>(Event.ClientListener <CQK, CQV> cl, string[] filterFactoryParams, string[] converterFactoryParams, Action recoveryCallback)
        {
            VectorVectorChar vvcFilterParams = new VectorVectorChar();

            foreach (string s in filterFactoryParams)
            {
                vvcFilterParams.Add(toVectorChar(marshaller.ObjectToByteBuffer(s)));
            }

            VectorVectorChar vvcConverterParams = new VectorVectorChar();

            foreach (string s in converterFactoryParams)
            {
                vvcConverterParams.Add(toVectorChar(marshaller.ObjectToByteBuffer(s)));
            }
            InternalClientEventListenerCallback <CQK, CQV> cb = new InternalClientEventListenerCallback <CQK, CQV>(cl, marshaller);
            DotNetClientListener listener = cache.addClientListener(cb, toVectorChar(cl.filterFactoryName), toVectorChar(cl.converterFactoryName), cl.includeCurrentState, vvcFilterParams, vvcConverterParams, cl.useRawData, cl.interestFlag);

            cl.listenerId = toByteArray(listener.getUListenerId());
            addListener(cl.listenerId, listener);
        }
Exemple #7
0
        public void FilterEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "string-is-equal-filter-factory";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { "wantedkeyprefix" }, new string[] { }, null);
                AssertNoEvents(listener);
                cache.Put("key1", "value1");
                cache.Put("wantedkeyprefix_key1", "value2");
                //only one received; one is ignored
                AssertOnlyCreated("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
                cache.Replace("key1", "modified");
                cache.Replace("wantedkeyprefix_key1", "modified");
                AssertOnlyModified("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
                cache.Remove("key1");
                cache.Remove("wantedkeyprefix_key1");
                AssertOnlyRemoved("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Exemple #8
0
        public void BasicEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                AssertNoEvents(listener);
                cache.Put("key1", "value1");
                AssertOnlyCreated("key1", listener);
                cache.Put("key1", "value1bis");
                AssertOnlyModified("key1", listener);
                cache.Remove("key1");
                AssertOnlyRemoved("key1", listener);
                cache.Put("key1", "value1", 100, TimeUnit.MILLISECONDS);
                AssertOnlyCreated("key1", listener);
                TimeUtils.WaitFor(() => { return(cache.Get("key1") == null); });
                AssertOnlyExpired("key1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }