public virtual 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); // SafeNamedCache SafeNamedCache safeCache = (SafeNamedCache)cache; Assert.IsFalse(safeCache.IsReleased); Assert.IsFalse(safeCache.IsFixedSize); Assert.IsFalse(safeCache.IsReadOnly); Assert.IsTrue(safeCache.IsSynchronized); // RemoteNamedCache RemoteNamedCache remoteCache = (RemoteNamedCache)safeCache.NamedCache; Assert.IsTrue(remoteCache.Channel.IsOpen); Assert.IsInstanceOf(typeof(NamedCacheProtocol), remoteCache.Protocol); CacheFactory.ReleaseCache(cache); CacheFactory.Shutdown(); }
public virtual 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); SafeNamedCache safeCache = (SafeNamedCache)cache; IDictionaryEnumerator de = safeCache.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 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(); }
/// <summary> /// Release and destroy the specified cache. /// </summary> /// <remarks> /// <b>Warning:</b> This method is used to completely destroy the /// specified cache across the cluster. All references in the entire /// cluster to this cache will be invalidated, the cached data will /// be cleared, and all resources will be released. /// </remarks> /// <param name="cache"> /// The cache object to be released. /// </param> public virtual void DestroyCache(INamedCache cache) { SafeNamedCache cacheSafe = (SafeNamedCache)cache; RemoveCacheReference(cacheSafe); ICacheService service = CacheService; try { INamedCache cacheWrapped = cacheSafe.NamedCache; if (cacheWrapped == null) { throw new InvalidOperationException("Cache is already released"); } else { service.DestroyCache(cacheWrapped); } } catch (Exception) { if (service != null && service.IsRunning) { throw; } } }
/// <summary> /// Obtain an <see cref="INamedCache"/> interface that provides a view /// of resources shared among members of a cluster. /// </summary> /// <remarks> /// The view is identified by name within this ICacheService. /// Typically, repeated calls to this method with the same view name /// will result in the same view reference being returned. /// </remarks> /// <param name="name"> /// The name, within this ICacheService, that uniquely identifies a /// view; <c>null</c> is legal, and may imply a default name. /// </param> /// <returns> /// An <b>INamedCache</b> interface which can be used to access the /// resources of the specified view. /// </returns> /// <exception cref="InvalidOperationException"> /// If the service is not running. /// </exception> public INamedCache EnsureCache(string name) { if (string.IsNullOrEmpty(name)) { name = "Default"; } ScopedReferenceStore storeCache = StoreSafeNamedCache; SafeNamedCache cacheSafe = (SafeNamedCache)storeCache.GetCache(name); if (cacheSafe == null) { lock (storeCache) { INamedCache cache = RunningCacheService.EnsureCache(name); cacheSafe = new SafeNamedCache { SafeCacheService = this, CacheName = name, NamedCache = cache, Principal = Thread.CurrentPrincipal }; storeCache.PutCache(cacheSafe); } } return(cacheSafe); }
/// <summary> /// Removes <see cref="SafeNamedCache"/> from the /// <see cref="ScopedReferenceStore"/>. /// </summary> /// <param name="cacheSafe"> /// <b>SafeNamedCache</b> to be removed. /// </param> protected virtual void RemoveCacheReference(SafeNamedCache cacheSafe) { cacheSafe.IsReleased = true; ScopedReferenceStore storeCache = StoreSafeNamedCache; lock (storeCache) { storeCache.ReleaseCache(cacheSafe); } }
public void TestNearNamedCacheInstancing() { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-near-cache-config.xml"); ccf.Config = config; INamedCache cache = ccf.EnsureCache("dist-extend-direct"); Assert.IsNotNull(cache); Assert.IsInstanceOf(typeof(NearCache), cache); NearCache nc = cache as NearCache; Assert.IsNotNull(nc); ICache fc = nc.FrontCache; INamedCache bc = nc.BackCache; Assert.IsNotNull(fc); Assert.IsNotNull(bc); Assert.IsInstanceOf(typeof(SafeNamedCache), nc.BackCache); Assert.IsInstanceOf(typeof(LocalNamedCache), nc.FrontCache); SafeNamedCache sc = nc.BackCache as SafeNamedCache; Assert.IsNotNull(sc); Assert.AreEqual(sc.CacheName, "dist-extend-direct"); Assert.IsInstanceOf(typeof(RemoteNamedCache), sc.NamedCache); RemoteNamedCache rc = sc.NamedCache as RemoteNamedCache; Assert.IsNotNull(rc); Assert.AreEqual(rc.CacheName, sc.CacheName); LocalNamedCache lnc = nc.FrontCache as LocalNamedCache; Assert.IsNotNull(lnc); LocalCache lc = lnc.LocalCache; Assert.AreEqual(lc.ExpiryDelay, LocalCache.DEFAULT_EXPIRE); Assert.AreEqual(lc.FlushDelay, 0); Assert.AreEqual(lc.HighUnits, LocalCache.DEFAULT_UNITS); Assert.AreEqual(lc.CalculatorType, LocalCache.UnitCalculatorType.Fixed); Assert.AreEqual(lc.EvictionType, LocalCache.EvictionPolicyType.Hybrid); CacheFactory.Shutdown(); }
public void TestRemoteNamedCacheInstancing() { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; INamedCache cache = ccf.EnsureCache("dist-extend-direct"); Assert.IsNotNull(cache); Assert.IsInstanceOf(typeof(SafeNamedCache), cache); SafeNamedCache sc = cache as SafeNamedCache; Assert.IsNotNull(sc); Assert.AreEqual(sc.CacheName, "dist-extend-direct"); Assert.IsInstanceOf(typeof(RemoteNamedCache), sc.NamedCache); RemoteNamedCache rc = sc.NamedCache as RemoteNamedCache; Assert.IsNotNull(rc); Assert.AreEqual(rc.CacheName, sc.CacheName); Assert.IsNotNull(sc.CacheService); Assert.IsInstanceOf(typeof(SafeCacheService), sc.CacheService); SafeCacheService scs = (SafeCacheService)sc.CacheService; Assert.AreEqual(scs.CacheNames.Count, 1); Assert.Contains(sc.CacheName, new ArrayList(scs.CacheNames)); List <INamedCache> listCache = new List <INamedCache>(scs.StoreSafeNamedCache.GetAllCaches()); Assert.AreEqual(listCache.Count, 1); Assert.Contains(sc.CacheName, new List <string>(scs.StoreSafeNamedCache.GetNames())); Assert.AreEqual(scs.ServiceType, ServiceType.RemoteCache); Assert.IsInstanceOf(typeof(RemoteCacheService), scs.CacheService); Assert.AreEqual(rc.CacheService, scs.CacheService); RemoteCacheService rcs = scs.CacheService as RemoteCacheService; Assert.IsNotNull(rcs); Assert.AreEqual(rcs.ServiceName, "ExtendTcpCacheService"); Assert.IsTrue(cache.IsActive); Assert.IsTrue(cache.CacheService.IsRunning); CacheFactory.Shutdown(); Assert.IsFalse(cache.IsActive); Assert.IsFalse(cache.CacheService.IsRunning); }
public virtual void TestInitialize() { INamedCache cache = CacheFactory.GetCache(CacheName); Assert.IsNotNull(cache); Assert.IsInstanceOf(typeof(SafeNamedCache), cache); Assert.IsInstanceOf(typeof(SafeCacheService), cache.CacheService); Assert.AreEqual(cache.CacheName, CacheName); Assert.IsTrue(cache.IsActive); Assert.IsTrue(cache.CacheService.IsRunning); SafeNamedCache safeCache = (SafeNamedCache)cache; Assert.IsInstanceOf(typeof(RemoteNamedCache), safeCache.NamedCache); Assert.IsInstanceOf(typeof(RemoteCacheService), safeCache.SafeCacheService.CacheService); CacheFactory.ReleaseCache(cache); Assert.IsFalse(cache.IsActive); CacheFactory.Shutdown(); Assert.AreEqual(cache.CacheName, CacheName); Assert.IsFalse(cache.CacheService.IsRunning); }
/// <summary> /// Release local resources associated with the specified instance of /// the cache. /// </summary> /// <remarks> /// <p> /// This invalidates a reference obtained by using the /// <see cref="ICacheService.EnsureCache"/> method.</p> /// <p> /// Releasing a map reference to a cache makes the map reference no /// longer usable, but does not affect the cache itself. In other /// words, all other references to the cache will still be valid, and /// the cache data is not affected by releasing the reference.</p> /// <p> /// The reference that is released using this method can no longer be /// used; any attempt to use the reference will result in an /// exception.</p> /// </remarks> /// <param name="cache"> /// The cache object to be released. /// </param> public virtual void ReleaseCache(INamedCache cache) { SafeNamedCache cacheSafe = (SafeNamedCache)cache; RemoveCacheReference(cacheSafe); ICacheService service = CacheService; try { INamedCache cacheWrapped = cacheSafe.NamedCache; if (cacheWrapped != null) { service.ReleaseCache(cacheWrapped); } } catch (Exception) { if (service != null && service.IsRunning) { throw; } } }