示例#1
0
        public void TestListenerEvents()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config =
                XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-near-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("dist-extend-direct");

            cache.Clear();

            ListenerWithWait listen = new ListenerWithWait();

            cache.AddCacheListener(listen, "test", true);

            cache.Insert("test", "c");
            CacheEventArgs localEvent = listen.WaitForEvent(2000);

            Assert.IsNotNull(localEvent);

            String value = (String)cache["test"];

            localEvent = listen.WaitForEvent(4000);
            Assert.AreEqual("c", value);
            Assert.IsNull(localEvent);

            CacheFactory.Shutdown();
        }
        public override void Execute(ObjectConstructionArgs args)
        {
            if (args.Result == null &&
                args.Options.Cache != Cache.Disabled)
            {
                var cachename    = GetCacheName(args);
                var cacheManager = CacheFactory.GetCache(cachename);

                var key = CacheKeyGenerator.Generate(args);

                var cacheItem = cacheManager.Get <object>(key);
                if (cacheItem != null)
                {
                    args.Result = cacheItem;
                    ModelCounter.Instance.CachedModels++;
                }
                else
                {
                    base.Execute(args);
                }

                cacheManager.AddOrUpdate(key, args.Result);
            }
            else
            {
                base.Execute(args);
            }
        }
        public void TestLocalNamedCacheDispose()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;
            IXmlDocument config           = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;
            INamedCache cache;

            string[] keys   = { "key1", "key2", "key3", "key4" };
            string[] values = { "value1", "value2", "value3", "value4" };
            using (cache = CacheFactory.GetCache("local-default"))
            {
                cache.Clear();
                IDictionary h = new Hashtable();
                h.Add(keys[0], values[0]);
                h.Add(keys[1], values[1]);
                h.Add(keys[2], values[2]);
                h.Add(keys[3], values[3]);
                cache.InsertAll(h);

                foreach (object key in cache.Keys)
                {
                    Assert.IsTrue(cache.Contains(key));
                }
            }
            //after disposal
            Assert.IsFalse(cache.IsActive);
            LocalNamedCache lnc = cache as LocalNamedCache;

            Assert.IsNotNull(lnc);
            Assert.IsTrue(lnc.IsReleased);
            Assert.IsNull(lnc.CacheService);

            CacheFactory.Shutdown();
        }
示例#4
0
        /// <summary>
        /// 泛型方法,反射生成InsertSql语句
        /// </summary>
        /// <param name="entity">实体类</param>
        /// <returns>int</returns>
        public static string InsertSql <T>(T entity)
        {
            string cacheKey = string.Format("T-SQL:INSERT:{0}:{1}", typeof(T).Name, typeof(T).FullName.GetMd5Code());
            string cache    = CacheFactory.GetCache().Get <string>(cacheKey);

            if (string.IsNullOrEmpty(cache))
            {
                StringBuilder sb   = new StringBuilder();
                Type          type = entity.GetType();
                //表名
                string table = EntityAttributeHelper.GetEntityTable <T>();
                //获取不做映射的字段
                List <string> notMappedField = EntityAttributeHelper.GetNotMappedFields <T>();

                sb.Append(" INSERT INTO ");
                sb.Append(table);
                sb.Append("(");
                StringBuilder  sp      = new StringBuilder();
                StringBuilder  sbPrame = new StringBuilder();
                PropertyInfo[] props   = type.GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    if (!notMappedField.Contains(prop.Name))
                    {
                        object value = prop.GetValue(entity, null);
                        if (value != null)
                        {
                            if (value.GetType() == typeof(DateTime))
                            {
                                var time = (DateTime)value;
                                if (time.Ticks != 0 && time != DateTime.MinValue && time != SqlDateTime.MinValue.Value)
                                {
                                    sbPrame.Append(",[" + prop.Name + "]");
                                    sp.Append("," + DbParameters.CreateDbParmCharacter() + "" + (prop.Name));
                                }
                            }
                            else
                            {
                                sbPrame.Append(",[" + prop.Name + "]");
                                sp.Append("," + DbParameters.CreateDbParmCharacter() + "" + (prop.Name));
                            }
                        }
                        else
                        {
                            if (prop.PropertyType.IsNullableType())
                            {
                                sbPrame.Append(",[" + prop.Name + "]");
                                sp.Append("," + DbParameters.CreateDbParmCharacter() + "" + (prop.Name));
                            }
                        }
                    }
                }
                sb.Append(sbPrame.ToString().Substring(1, sbPrame.ToString().Length - 1) + ") VALUES (");
                sb.Append(sp.ToString().Substring(1, sp.ToString().Length - 1) + ")");

                cache = sb.ToString();
                CacheFactory.GetCache().Add(cacheKey, cache);
            }
            return(cache);
        }
示例#5
0
        public override void Execute(ObjectConstructionArgs args)
        {
            if (args.Result == null && //if we already have a result don't do anything
                args.Options.Cache.IsEnabled() && //if the model has the cache explicitly  disabled
                args.AbstractTypeCreationContext.CacheEnabled && //
                DisableCache.Current != Cache.Disabled    //has the cache disabler been used? This is legacy and should go.
                )
            {
                var cachename    = GetCacheName(args);
                var cacheManager = CacheFactory.GetCache(cachename);

                var key = CacheKeyGenerator.Generate(args);

                var cacheItem = cacheManager.Get <object>(key);
                if (cacheItem != null)
                {
                    args.Result = cacheItem;
                    ModelCounter.Instance.CachedModels++;
                }
                else
                {
                    base.Execute(args);
                }

                cacheManager.AddOrUpdate(key, args.Result);
            }
            else
            {
                base.Execute(args);
            }
        }
示例#6
0
        public override void TestNamedCacheProperties()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);
            string      key   = "testNamedCachePropertiesKey";
            string      value = "testNamedCachePropertiesValue";

            // INamedCache
            Assert.IsTrue(cache.IsActive);

            cache.Clear();
            Assert.AreEqual(cache.Count, 0);

            cache.Insert(GetKeyObject(key), value);
            Assert.AreEqual(cache.Count, 1);
            Assert.AreEqual(cache[GetKeyObject(key)], value);

            // BundlingNamedCache
            BundlingNamedCache bundleCache = (BundlingNamedCache)cache;

            Assert.IsFalse(bundleCache.IsFixedSize);
            Assert.IsFalse(bundleCache.IsReadOnly);
            Assert.IsTrue(bundleCache.IsSynchronized);

            // RemoteNamedCache
            SafeNamedCache safeCache = (SafeNamedCache)bundleCache.NamedCache;

            Assert.IsTrue(safeCache.IsActive);
            CacheFactory.ReleaseCache(cache);
            CacheFactory.Shutdown();
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String key = Request["key"];

            String orderby = "interestingness-desc";

            if (String.IsNullOrEmpty(key))
            {
                return;
            }

            cache = CacheFactory.GetCache();

            currentCacheKey = key + orderby;

            object result = cache.get(currentCacheKey);

            if (result == null)
            {
                FlickrFetcher fetcher = new FlickrFetcher();
                fetched(fetcher.FetchGroup(key, ""));
            }
            else
            {
                AjaxResponse response = new AjaxResponse();
                response.Status  = "OK";
                response.RawData = result;
                Response.Write(response.ToString());
            }
            Response.ContentType = "application/json";
        }
        public void Clear()
        {
            var cache = CacheFactory.GetCache(CacheFactoryName);

            cache.Clear();
            cache.Release();
        }
示例#9
0
        // GET api/values/5
        public HttpResponseMessage Get(int id)
        {
            IList <StudentModel> studentsList;
            HttpResponseMessage  response;
            var currentPrincipal = Thread.CurrentPrincipal as UserExtended;

            if (currentPrincipal == null)
            {
                response = Request.CreateResponse(HttpStatusCode.NonAuthoritativeInformation);
                return(response);
            }

            var cache = CacheFactory.GetCache(CacheType.InMemoryObjectCache, CacheIdentifiers.StudentProfileCache);// Should be injected as static object

            if (!cache.Contains(StudentProfileCacheObjects.StudentProfileModel.ToString()))
            {
                studentsList = GetStudentProfile(currentPrincipal.TenantTypes);
                cache.Add(new CacheItem(StudentProfileCacheObjects.StudentProfileModel.ToString(), studentsList), new CacheItemPolicy());
            }
            else
            {
                studentsList = (IList <StudentModel>)cache.Get(StudentProfileCacheObjects.StudentProfileModel.ToString());
            }

            response = Request.CreateResponse(HttpStatusCode.OK);
            var serializer       = new JavaScriptSerializer();
            var serializedResult = serializer.Serialize(studentsList);

            response.Content = new StringContent(serializedResult, Encoding.UTF8, "application/json");
            return(response);
        }
示例#10
0
        public void TestNearCacheDispose()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache;

            string[] keys   = { "key1", "key2", "key3", "key4" };
            string[] values = { "value1", "value2", "value3", "value4" };
            using (nearcache = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone))
            {
                nearcache.Clear();
                IDictionary h = new Hashtable();
                h.Add(keys[0], values[0]);
                h.Add(keys[1], values[1]);
                h.Add(keys[2], values[2]);
                h.Add(keys[3], values[3]);
                nearcache.InsertAll(h);

                foreach (object key in nearcache.Keys)
                {
                    Assert.IsTrue(nearcache.Contains(key));
                }
            }
            //after disposal
            Assert.IsFalse(nearcache.IsActive);
            // fresh reference to the cache
            safecache = CacheFactory.GetCache(CacheName);
            Assert.IsTrue(safecache.IsActive);
            CacheFactory.Shutdown();
        }
示例#11
0
        public void TestNearCacheTruncate()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("Aleks", 1);
            ht.Add("Ana", 2);
            ht.Add("Goran", 3);
            ht.Add("Ivan", 4);
            nearcache.InsertAll(ht);

            IFilter filter = new BetweenFilter(IdentityExtractor.Instance, 2, 10);

            object[] result = nearcache.GetKeys(filter);
            Assert.AreEqual(3, result.Length);

            nearcache.Truncate();
            Assert.IsTrue(nearcache.IsActive);

            Thread.Sleep(2000);
            result = nearcache.GetKeys(filter);
            Assert.AreEqual(0, result.Length);

            nearcache.Release();
            Assert.IsFalse(nearcache.IsActive);

            CacheFactory.Shutdown();
        }
示例#12
0
        public void NearCacheListenNoneGetEntriesTest()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("Aleks", 1);
            ht.Add("Ana", 4);
            ht.Add("Goran", 3);
            ht.Add("Ivan", 2);
            nearcache.InsertAll(ht);

            IFilter filter = new BetweenFilter(IdentityExtractor.Instance, 2, 10);

            object[] result = nearcache.GetEntries(filter);
            Assert.AreEqual(3, result.Length);

            result = nearcache.GetEntries(filter, IdentityExtractor.Instance);
            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(i + 2, ((ICacheEntry)result[i]).Value);
            }

            CacheFactory.Shutdown();
        }
示例#13
0
        public void NearCacheListenNoneAggregateTest()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("Aleks", 1);
            ht.Add("Ana", 2);
            ht.Add("Goran", 3);
            ht.Add("Ivan", 4);
            nearcache.InsertAll(ht);

            IEntryAggregator aggregator = new Count();
            object           count      = nearcache.Aggregate(nearcache.Keys, aggregator);

            Assert.AreEqual(ht.Count, count);

            IFilter filter = new LessFilter(IdentityExtractor.Instance, 3);

            count = nearcache.Aggregate(filter, aggregator);
            Assert.AreEqual(2, count);

            nearcache.Clear();
            nearcache.Release();
            Assert.IsFalse(nearcache.IsActive);

            CacheFactory.Shutdown();
        }
示例#14
0
        public void NearCacheListenNoneInvokeTest()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("Aleks", 1);
            ht.Add("Ana", 2);
            ht.Add("Goran", 3);
            ht.Add("Ivan", 4);
            nearcache.InsertAll(ht);

            IFilter         filter    = new GreaterFilter(IdentityExtractor.Instance, 199);
            IEntryProcessor processor = new ConditionalPut(filter, 204);

            nearcache.Invoke("Ivan", processor);
            Assert.AreEqual(4, nearcache["Ivan"]);
            Assert.AreEqual(4, nearcache.BackCache["Ivan"]);

            nearcache["Ivan"] = 200;
            nearcache.Invoke("Ivan", processor);
            Assert.AreEqual(200, nearcache["Ivan"]);
            Assert.AreEqual(204, nearcache.BackCache["Ivan"]);

            nearcache.Clear();
            nearcache.Release();
            Assert.IsFalse(nearcache.IsActive);

            CacheFactory.Shutdown();
        }
        public void TestPofExtractorWithValueChangeEventFilter1()
        {
            // Testing on remote cache using CustomerKeyClass, which is not
            // defined on Java side
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            // CustomerKeyClass is not defined on the Java side
            //
            Hashtable      ht   = new Hashtable();
            CustomKeyClass key1 = new CustomKeyClass("Customer1");
            CustomKeyClass key2 = new CustomKeyClass("Customer2");

            ht.Add("key1", key1);
            ht.Add("key2", key2);
            cache.InsertAll(ht);

            SyncListener listener = new SyncListener();
            IFilter      filter   = new ValueChangeEventFilter(new PofExtractor(typeof(String), 0));

            cache.AddCacheListener(listener,
                                   filter,
                                   false);
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new CustomKeyClass("Customer1");
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new CustomKeyClass("Customer12");
            Assert.IsNotNull(listener.CacheEvent);

            CacheFactory.Shutdown();
        }
示例#16
0
 static CacheManager()
 {
     RunTimeCache = (RunTimeCache)CacheFactory.GetCache("RunTime");
     RedisDefault = (RedisCache)CacheFactory.GetCache("RedisDefault");
     RedisDb      = CacheFactory.GetRedis("RedisDb");
     RedisChat    = CacheFactory.GetRedis("RedisChat");
 }
        public AzureCacheClient(string cacheName = null, string endpointUrl = null, string authorizationToken = null, bool useLocalCache = true)
        {
            if (!String.IsNullOrEmpty(endpointUrl) && !String.IsNullOrEmpty(authorizationToken))
            {
                var config = new DataCacheFactoryConfiguration {
                    AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, endpointUrl),
                    SecurityProperties   = new DataCacheSecurity(authorizationToken, false)
                };
                if (useLocalCache)
                {
                    config.LocalCacheProperties = new DataCacheLocalCacheProperties(10000, TimeSpan.FromMinutes(5), DataCacheLocalCacheInvalidationPolicy.TimeoutBased);
                }
                CacheFactory = new DataCacheFactory(config);
            }
            else
            {
                CacheFactory = new DataCacheFactory();
            }

            if (string.IsNullOrEmpty(cacheName))
            {
                DataCache = CacheFactory.GetDefaultCache();
            }
            else
            {
                DataCache = CacheFactory.GetCache(cacheName);
            }
        }
示例#18
0
        /// <summary>
        /// 保存区域表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="areaEntity">区域实体</param>
        /// <returns></returns>
        public void SaveForm(string keyValue, AreaEntity areaEntity)
        {
            IDbTransaction tran = null;

            Logger(this.GetType(), "SaveForm-保存区域表单(新增、修改)", () =>
            {
                using (var conn = this.BaseRepository().GetBaseConnection())
                {
                    tran = conn.BeginTransaction();

                    if (!string.IsNullOrEmpty(keyValue))
                    {
                        areaEntity.Modify(keyValue);
                        int res = this.BaseRepository().Update <AreaEntity>(conn, areaEntity, tran);
                    }
                    else
                    {
                        areaEntity.Create();
                        int res = this.BaseRepository().Insert <AreaEntity>(conn, areaEntity, tran);
                    }

                    tran.Commit();
                }
            }, e =>
            {
                Trace.WriteLine(e.Message);
            });

            CacheFactory.GetCache().Remove("__AreaCache");
        }
示例#19
0
        public override void TestNamedCacheEntryCollection()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);

            object[] keys   = { GetKeyObject("key1"), GetKeyObject("key2"), GetKeyObject("key3"), GetKeyObject("key4") };
            string[] values = { "value1", "value2", "value3", "value4" };
            cache.Clear();
            IDictionary h = new Hashtable();

            h.Add(keys[0], values[0]);
            h.Add(keys[1], values[1]);
            h.Add(keys[2], values[2]);
            h.Add(keys[3], values[3]);
            cache.InsertAll(h);

            BundlingNamedCache    bundleCache = (BundlingNamedCache)cache;
            IDictionaryEnumerator de          = bundleCache.NamedCache.GetEnumerator();
            ArrayList             al          = new ArrayList(h.Values);

            for (; de.MoveNext();)
            {
                Assert.IsTrue(al.Contains(de.Value));
                Assert.IsTrue(h.Contains(de.Key));
            }

            CacheFactory.ReleaseCache(cache);
            CacheFactory.Shutdown();
        }
        public static void GetCache()
        {
            Console.WriteLine("------password example begins------");

            IPrincipal principal        = SecurityExampleHelper.Login("BuckarooBanzai");
            IPrincipal principalCurrent = Thread.CurrentPrincipal;

            try
            {
                Thread.CurrentPrincipal = principal;
                CacheFactory.GetCache(SecurityExampleHelper.SECURITY_CACHE_NAME);
                Console.WriteLine("------password example succeeded------");
            }
            catch (Exception e)
            {
                // get exception if the password is invalid
                Console.WriteLine("Unable to connect to proxy");
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                Thread.CurrentPrincipal = principalCurrent;
            }
            Console.WriteLine("------password example completed------");
        }
示例#21
0
        /// <summary>
        /// 拼接删除SQL语句
        /// </summary>
        /// <param name="entity">实体类</param>
        /// <returns></returns>
        public static string DeleteSql <T>(T entity)
        {
            string cacheKey = string.Format("T-SQL:DELETE:{0}:{1}", typeof(T).Name, typeof(T).FullName.GetMd5Code());
            string cache    = CacheFactory.GetCache().Get <string>(cacheKey);

            if (string.IsNullOrEmpty(cache))
            {
                Type           type  = entity.GetType();
                PropertyInfo[] props = type.GetProperties();
                //表名
                string table = EntityAttributeHelper.GetEntityTable <T>();

                StringBuilder sb = new StringBuilder("DELETE FROM " + table + " WHERE 1=1");
                foreach (PropertyInfo prop in props)
                {
                    if (prop.GetValue(entity, null) != null)
                    {
                        sb.Append(" AND " + prop.Name + " = " + DbParameters.CreateDbParmCharacter() + "" + prop.Name + "");
                    }
                }

                cache = sb.ToString();
                CacheFactory.GetCache().Add(cacheKey, cache);
            }
            return(cache);
        }
示例#22
0
        protected override ISessionModelManager CreateModelManager(ISerializer serializer)
        {
            m_extAttrCache = CacheFactory.GetCache(SplitSessionModelManager.EXTERNAL_ATTRIBUTES_CACHE_NAME);
            m_extAttrCache.Clear();

            return(new SplitSessionModelManager(serializer, 500));
        }
        /// <summary>
        /// Executes when a Start command is sent to the service by the Service Control Manager.
        /// </summary>
        /// <param name="args">Data passed by the start command.</param>
        protected override void OnStart(string[] args)
        {
            try
            {
                // Reading service configuration settings from its configuration file
                Configuration.ReadConfigParams();

                ///
                /// Configure this service to receive backing store events
                ///
                NamedCache         cache  = CacheFactory.GetCache(Configuration.CACHE_NAME);
                BackingStorePolicy policy = new BackingStorePolicy();

                // We want to receive asynchronous write-behind events from StateServer:
                policy.EnableAsyncOperations = true;

                // Our customized IBackingStore implementation that knows how to write a cached
                // object to the database:
                BackingStoreAdapter adapter = new BackingStoreAdapter();

                // Register to handle backing store events:
                cache.SetBackingStoreAdapter(adapter, policy);
                Logger.WriteMessage(TraceEventType.Information, 1, $"[OnStart] Backing store adapter was successfully registered for handling events in named cache '{Configuration.CACHE_NAME}'");
            }
            catch (Exception ex)
            {
                Logger.WriteError(2, ex);
                throw;
            }
        }
示例#24
0
        public void TestPreloadRequest()
        {
            IEntryProcessor processor  = PreloadRequest.Instance;
            IEntryProcessor processor1 = PreloadRequest.Instance;

            Assert.AreEqual(processor, processor1);
            Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode());
            Assert.AreEqual(processor.ToString(), processor1.ToString());

            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Temperature bgd = new Temperature(25, 'c', 12);
            Temperature nyc = new Temperature(99, 'f', 12);

            cache.Insert("BGD", bgd);
            cache.Insert("NYC", nyc);

            object o = cache.Invoke("BGD", processor);

            Assert.IsNull(o);

            CacheFactory.Shutdown();
        }
示例#25
0
文件: UnitTest.cs 项目: wyh0395/Berry
        private void RedisTest()
        {
            RedisHelper   redis = new RedisHelper();
            List <string> keys  = redis.GetKeys();

            Console.WriteLine("__TestBaseEntityKey是否存储:" + redis.KeyExists("__TestBaseEntityKey") + "\r\n");

            keys.ForEach(k =>
            {
                bool e = redis.KeyExists(k);
                Console.WriteLine(k + "是否存储:" + e + "\r\n");
            });
            Console.WriteLine("===========================");

            DataItemCache dataItem = new DataItemCache();
            var           res      = dataItem.GetDataItemList();

            Console.WriteLine("res:" + res.Count());

            Console.WriteLine("===========================");
            BaseEntity cache = CacheFactory.GetCache().Get <BaseEntity>("__TestBaseEntityKey");

            if (cache == null)
            {
                cache = new BaseEntity
                {
                    Id = "123",
                    PK = 1
                };
                CacheFactory.GetCache().Add("__TestBaseEntityKey", cache);
            }
            Console.WriteLine(cache.Id);
        }
        public void TestPofExtractorWithValueChangeEventFilter2()
        {
            // Testing on remote cache using Address, which is defined on
            // Java side.
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Hashtable ht       = new Hashtable();
            Address   address1 = new Address("Street1", "City1", "State1", "Zip1");
            Address   address2 = new Address("Street2", "City2", "State2", "Zip2");

            ht.Add("key1", address1);
            ht.Add("key2", address2);
            cache.InsertAll(ht);

            SyncListener listener = new SyncListener();
            IFilter      filter   = new ValueChangeEventFilter(new PofExtractor(typeof(String), 0));

            cache.AddCacheListener(listener,
                                   filter,
                                   false);
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new Address("Street1", "City1a", "State1a", "Zip1a");
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new Address("Street1a", "City1", "State1", "Zip1");
            Assert.IsNotNull(listener.CacheEvent);

            CacheFactory.Shutdown();
        }
        public void TestIndexes()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            Assert.IsTrue(cache is LocalNamedCache);

            LocalNamedCache localNamedCache = cache as LocalNamedCache;

            Assert.IsNotNull(localNamedCache);
            localNamedCache.AddIndex(IdentityExtractor.Instance, true, null);
            localNamedCache.RemoveIndex(IdentityExtractor.Instance);

            localNamedCache.AddIndex(IdentityExtractor.Instance, true, SafeComparer.Instance);
            localNamedCache.RemoveIndex(IdentityExtractor.Instance);

            localNamedCache.AddIndex(IdentityExtractor.Instance, false, null);
            localNamedCache.RemoveIndex(IdentityExtractor.Instance);

            localNamedCache.AddIndex(IdentityExtractor.Instance, false, SafeComparer.Instance);
            localNamedCache.RemoveIndex(IdentityExtractor.Instance);
            CacheFactory.Shutdown();
        }
        public void TestExtractorEventTransformer()
        {
            //testing on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Hashtable ht       = new Hashtable();
            Address   address1 = new Address("Street1", "City1", "State1", "Zip1");
            Address   address2 = new Address("Street2", "City2", "State2", "Zip2");

            ht.Add("key1", address1);
            ht.Add("key2", address2);
            cache.InsertAll(ht);

            SyncListener           listener    = new SyncListener();
            IFilter                filter      = new ValueChangeEventFilter("getStreet");
            IValueExtractor        extractor   = IdentityExtractor.Instance;
            ICacheEventTransformer transformer = new ExtractorEventTransformer(null, extractor);

            cache.AddCacheListener(listener,
                                   new CacheEventTransformerFilter(filter,
                                                                   transformer),
                                   false);
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new Address("Street1", "City1a", "State1a", "Zip1a");
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new Address("Street1a", "City1a", "State1a", "Zip1a");
            Assert.IsNotNull(listener.CacheEvent);

            CacheFactory.Shutdown();
        }
        public void TestCustomEvictionPolicy()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-custom-eviction");

            Assert.IsTrue(cache is LocalNamedCache);

            LocalNamedCache localNamedCache = cache as LocalNamedCache;

            Assert.IsNotNull(localNamedCache);

            LocalCache localCache = localNamedCache.LocalCache;

            Assert.IsNotNull(localCache);

            Assert.AreEqual(localCache.EvictionType, LocalCache.EvictionPolicyType.External);
            Assert.IsInstanceOf(typeof(TestEvictionPolicy), localCache.EvictionPolicy);

            CacheFactory.Shutdown();
        }
示例#30
0
        public void NearCacheListenNoneWithNullsTest()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add(1, "Aleks");
            ht.Add(2, "Ana");
            ht.Add(3, "Goran");
            ht.Add(4, "Ivan");
            nearcache.InsertAll(ht);
            nearcache.Insert(5, null);
            Assert.AreEqual(ht.Count + 1, nearcache.Count);
            Assert.AreEqual(ht.Count, nearcache.FrontCache.Count);

            nearcache.Clear();
            nearcache.Release();
            Assert.IsFalse(nearcache.IsActive);

            CacheFactory.Shutdown();
        }