public void CreateAndVerifyExpiry() { try { IRegion <string, int> region = CacheHelper.CreateLocalRegionWithETTL <string, int>(RegionName, ExpirationAction.LocalInvalidate, TimeToLive); Apache.Geode.Client.RegionAttributes <string, int> newAttrs = region.Attributes; int ttl = newAttrs.EntryTimeToLive; Assert.AreEqual(TimeToLive, ttl); region[Key] = Val; // countdown begins... it is ttl so access should not play into it.. Thread.Sleep(2000); // sleep for some time, expect value to still be there. int res = region[Key]; Assert.IsNotNull(res); Assert.AreEqual(Val, res); Thread.Sleep(6000); // sleep for 6 more seconds, expect value to be invalid. bool containsKey = region.ContainsValueForKey(Key); Assert.IsFalse(containsKey, "The region should not contain the key"); } finally { CacheHelper.Close(); } }
public static string RegionTag(Apache.Geode.Client.RegionAttributes <TKey, TVal> attrs) { string tag = string.Empty; tag += attrs.CachingEnabled ? "Caching" : "NoCache"; tag += (attrs.CacheListener == null) ? "Nlstnr" : "Lstnr"; return(tag); }
// Testing for attibute validation. private void ValidateAttributes(IRegion <object, object> region) { Apache.Geode.Client.RegionAttributes <object, object> regAttr = region.Attributes; int initialCapacity = regAttr.InitialCapacity; Assert.AreEqual(1000, initialCapacity, "Expected initial capacity to be 1000"); Assert.AreEqual(DiskPolicyType.Overflows, regAttr.DiskPolicy, "Expected Action to be overflow to disk"); }
public void StepOne(string locators) { CacheHelper.CreateTCRegion_Pool <object, object>(QueryRegionNames[0], true, true, null, locators, "__TESTPOOL1_", true); CacheHelper.CreateTCRegion_Pool <object, object>(QueryRegionNames[1], true, true, null, locators, "__TESTPOOL1_", true); CacheHelper.CreateTCRegion_Pool <object, object>(QueryRegionNames[2], true, true, null, locators, "__TESTPOOL1_", true); CacheHelper.CreateTCRegion_Pool <object, object>(QueryRegionNames[3], true, true, null, locators, "__TESTPOOL1_", true); IRegion <object, object> region = CacheHelper.GetRegion <object, object>(QueryRegionNames[0]); Apache.Geode.Client.RegionAttributes <object, object> regattrs = region.Attributes; region.CreateSubRegion(QueryRegionNames[1], regattrs); }
public static string RegionAttributesToString(Apache.Geode.Client.RegionAttributes <TKey, TVal> attrs) { StringBuilder attrsSB = new StringBuilder(); attrsSB.Append(Environment.NewLine + "caching: " + attrs.CachingEnabled); attrsSB.Append(Environment.NewLine + "pool: " + attrs.PoolName); attrsSB.Append(Environment.NewLine + "initialCapacity: " + attrs.InitialCapacity); attrsSB.Append(Environment.NewLine + "loadFactor: " + attrs.LoadFactor); attrsSB.Append(Environment.NewLine + "concurrencyLevel: " + attrs.ConcurrencyLevel); attrsSB.Append(Environment.NewLine + "lruEntriesLimit: " + attrs.LruEntriesLimit); attrsSB.Append(Environment.NewLine + "lruEvictionAction: " + attrs.LruEvictionAction); attrsSB.Append(Environment.NewLine + "entryTimeToLive: " + attrs.EntryTimeToLive); attrsSB.Append(Environment.NewLine + "entryTimeToLiveAction: " + attrs.EntryTimeToLiveAction); attrsSB.Append(Environment.NewLine + "entryIdleTimeout: " + attrs.EntryIdleTimeout); attrsSB.Append(Environment.NewLine + "entryIdleTimeoutAction: " + attrs.EntryIdleTimeoutAction); attrsSB.Append(Environment.NewLine + "regionTimeToLive: " + attrs.RegionTimeToLive); attrsSB.Append(Environment.NewLine + "regionTimeToLiveAction: " + attrs.RegionTimeToLiveAction); attrsSB.Append(Environment.NewLine + "regionIdleTimeout: " + attrs.RegionIdleTimeout); attrsSB.Append(Environment.NewLine + "regionIdleTimeoutAction: " + attrs.RegionIdleTimeoutAction); attrsSB.AppendFormat("{0}cacheLoader: {1}", Environment.NewLine, attrs.CacheLoader != null ? "Enabled" : "Disabled"); attrsSB.AppendFormat("{0}cacheWriter: {1}", Environment.NewLine, attrs.CacheWriter != null ? "Enabled" : "Disabled"); attrsSB.AppendFormat("{0}cacheListener: {1}", Environment.NewLine, attrs.CacheListener != null ? "Enabled" : "Disabled"); attrsSB.Append(Environment.NewLine + "concurrency-checks-enabled: " + attrs.ConcurrencyChecksEnabled); attrsSB.Append(Environment.NewLine); return(attrsSB.ToString()); }
public void XmlCacheCreationWithOverflow() { Cache cache = null; IRegion <object, object> region1; IRegion <object, object> region2; IRegion <object, object> region3; IRegion <object, object>[] rootRegions; //Region<object, object>[] subRegions; ICollection <IRegion <object, object> > subRegions; /*string host_name = "XML_CACHE_CREATION_TEST";*/ const UInt32 totalSubRegionsRoot1 = 2; const UInt32 totalRootRegions = 3; try { CacheHelper.CloseCache(); Util.Log("Creating cache with the configurations provided in valid_overflowAttr.xml"); string cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "valid_overflowAttr.xml"; cache = new CacheFactory().Set("cache-xml-file", cachePath).Create(); Util.Log("Successfully created the cache."); rootRegions = cache.RootRegions <object, object>(); Assert.IsNotNull(rootRegions); Assert.AreEqual(totalRootRegions, rootRegions.Length); Util.Log("Root regions in Cache: "); foreach (IRegion <object, object> rg in rootRegions) { Util.Log('\t' + rg.Name); } region1 = rootRegions[0]; //subRegions = region1.SubRegions(true); subRegions = region1.SubRegions(true); Assert.IsNotNull(subRegions); Assert.AreEqual(subRegions.Count, totalSubRegionsRoot1); Util.Log("SubRegions for the root region: "); foreach (IRegion <object, object> rg in subRegions) { Util.Log('\t' + rg.Name); } Util.Log("Testing if the nesting of regions is correct..."); region2 = rootRegions[1]; subRegions = region2.SubRegions(true); string childName; string parentName; foreach (IRegion <object, object> rg in subRegions) { childName = rg.Name; IRegion <object, object> parent = rg.ParentRegion; parentName = parent.Name; if (childName == "SubSubRegion221") { Assert.AreEqual("SubRegion22", parentName); } } region3 = rootRegions[2]; //subRegions = region1.SubRegions(true); subRegions = region3.SubRegions(true); Assert.IsNotNull(subRegions); Assert.AreEqual(subRegions.Count, totalSubRegionsRoot1); Util.Log("SubRegions for the root region: "); foreach (IRegion <object, object> rg in subRegions) { Util.Log('\t' + rg.Name); } Apache.Geode.Client.RegionAttributes <object, object> attrs = region1.Attributes; //Util.Log("Attributes of root region Root1 are: "); bool cachingEnabled = attrs.CachingEnabled; Assert.IsTrue(cachingEnabled); uint lruEL = attrs.LruEntriesLimit; Assert.AreEqual(35, lruEL); int concurrency = attrs.ConcurrencyLevel; Assert.AreEqual(10, concurrency); int initialCapacity = attrs.InitialCapacity; Assert.AreEqual(25, initialCapacity); var regionIdleTO = attrs.RegionIdleTimeout; Assert.AreEqual(20, regionIdleTO); ExpirationAction action1 = attrs.RegionIdleTimeoutAction; Assert.AreEqual(ExpirationAction.Destroy, action1); DiskPolicyType type = attrs.DiskPolicy; Assert.AreEqual(DiskPolicyType.Overflows, type); string persistenceDir, maxPageCount, pageSize; string lib = attrs.PersistenceLibrary; string libFun = attrs.PersistenceFactory; Util.Log(" persistence library1 = " + lib); Util.Log(" persistence function1 = " + libFun); Properties <string, string> pconfig = attrs.PersistenceProperties; Assert.IsNotNull(pconfig, "Persistence properties should not be null for root1."); persistenceDir = (string)pconfig.Find("PersistenceDirectory"); maxPageCount = (string)pconfig.Find("MaxPageCount"); pageSize = (string)pconfig.Find("PageSize"); Assert.IsNotNull(persistenceDir, "Persistence directory should not be null."); Assert.AreNotEqual(0, persistenceDir.Length, "Persistence directory should not be empty."); Assert.IsNotNull(maxPageCount, "Persistence MaxPageCount should not be null."); Assert.AreNotEqual(0, maxPageCount.Length, "Persistence MaxPageCount should not be empty."); Assert.IsNotNull(pageSize, "Persistence PageSize should not be null."); Assert.AreNotEqual(0, pageSize.Length, "Persistence PageSize should not be empty."); Util.Log("****Attributes of Root1 are correctly set****"); Apache.Geode.Client.RegionAttributes <object, object> attrs2 = region2.Attributes; string lib2 = attrs2.PersistenceLibrary; string libFun2 = attrs2.PersistenceFactory; Util.Log(" persistence library2 = " + lib2); Util.Log(" persistence function2 = " + libFun2); Properties <string, string> pconfig2 = attrs2.PersistenceProperties; Assert.IsNotNull(pconfig2, "Persistence properties should not be null for root2."); persistenceDir = (string)pconfig2.Find("PersistenceDirectory"); maxPageCount = (string)pconfig2.Find("MaxPageCount"); maxPageCount = (string)pconfig2.Find("PageSize"); Assert.IsNotNull(persistenceDir, "Persistence directory should not be null."); Assert.AreNotEqual(0, persistenceDir.Length, "Persistence directory should not be empty."); Assert.IsNotNull(maxPageCount, "Persistence MaxPageCount should not be null."); Assert.AreNotEqual(0, maxPageCount.Length, "Persistence MaxPageCount should not be empty."); Assert.IsNotNull(pageSize, "Persistence PageSize should not be null."); Assert.AreNotEqual(0, pageSize.Length, "Persistence PageSize should not be empty."); Util.Log("****Attributes of Root2 are correctly set****"); Apache.Geode.Client.RegionAttributes <object, object> attrs3 = region3.Attributes; //Util.Log("Attributes of root region Root1 are: "); Assert.IsTrue(attrs3.CachingEnabled); Assert.AreEqual(35, attrs3.LruEntriesLimit); Assert.AreEqual(10, attrs3.ConcurrencyLevel); Assert.AreEqual(25, attrs3.InitialCapacity); Assert.AreEqual(20, attrs3.RegionIdleTimeout); Assert.AreEqual(ExpirationAction.Destroy, attrs3.RegionIdleTimeoutAction); Assert.AreEqual(DiskPolicyType.Overflows, attrs3.DiskPolicy); Util.Log(" persistence library1 = " + attrs3.PersistenceLibrary); Util.Log(" persistence function1 = " + attrs3.PersistenceFactory); Properties <string, string> pconfig3 = attrs.PersistenceProperties; Assert.IsNotNull(pconfig3, "Persistence properties should not be null for root1."); Assert.IsNotNull(pconfig3.Find("PersistenceDirectory"), "Persistence directory should not be null."); Assert.AreNotEqual(0, pconfig3.Find("PersistenceDirectory").Length, "Persistence directory should not be empty."); Assert.IsNotNull(pconfig3.Find("MaxPageCount"), "Persistence MaxPageCount should not be null."); Assert.AreNotEqual(0, pconfig3.Find("MaxPageCount").Length, "Persistence MaxPageCount should not be empty."); Assert.IsNotNull(pconfig3.Find("PageSize"), "Persistence PageSize should not be null."); Assert.AreNotEqual(0, pconfig3.Find("PageSize"), "Persistence PageSize should not be empty."); Util.Log("****Attributes of Root1 are correctly set****"); region1.DestroyRegion(null); region2.DestroyRegion(null); region3.DestroyRegion(null); if (!cache.IsClosed) { cache.Close(); } ////////////////////////////testing of cache.xml completed/////////////////// Util.Log("Create cache with the configurations provided in the invalid_overflowAttr1.xml."); Util.Log("Non existent XML; exception should be thrown"); try { cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "non-existent.xml"; cache = new CacheFactory().Set("cache-xml-file", cachePath).Create(); Assert.Fail("Creation of cache with non-existent.xml should fail!"); } catch (CacheXmlException ex) { Util.Log("Expected exception with non-existent.xml: {0}", ex); } Util.Log("This is a well-formed xml....attributes not provided for persistence manager. exception should be thrown"); try { cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_overflowAttr1.xml"; cache = new CacheFactory().Set("cache-xml-file", cachePath).Create(); Assert.Fail("Creation of cache with invalid_overflowAttr1.xml should fail!"); } catch (IllegalStateException ex) { Util.Log("Expected exception with invalid_overflowAttr1.xml: {0}", ex); } ///////////////testing of invalid_overflowAttr1.xml completed/////////////////// Util.Log("Create cache with the configurations provided in the invalid_overflowAttr2.xml."); Util.Log("This is a well-formed xml....attribute values is not provided for persistence library name......should throw an exception"); try { cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_overflowAttr2.xml"; cache = new CacheFactory().Set("cache-xml-file", cachePath).Create(); Assert.Fail("Creation of cache with invalid_overflowAttr2.xml should fail!"); } catch (CacheXmlException ex) { Util.Log("Expected exception with invalid_overflowAttr2.xml: {0}", ex); } ///////////////testing of invalid_overflowAttr2.xml completed/////////////////// Util.Log("Create cache with the configurations provided in the invalid_overflowAttr3.xml."); Util.Log("This is a well-formed xml....but region-attributes for persistence invalid......should throw an exception"); try { cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_overflowAttr3.xml"; cache = new CacheFactory().Set("cache-xml-file", cachePath).Create(); Assert.Fail("Creation of cache with invalid_overflowAttr3.xml should fail!"); } catch (CacheXmlException ex) { Util.Log("Expected exception with invalid_overflowAttr3.xml: {0}", ex); } ///////////////testing of invalid_overflowAttr3.xml completed/////////////////// } catch (Exception ex) { Assert.Fail("Caught exception: {0}", ex); } finally { if (cache != null && !cache.IsClosed) { cache.Close(); } } }
public override void DoCreateRegion() { FwkInfo("In DoCreateRegion() Durable"); ClearCachedKeys(); string rootRegionData = GetStringValue("regionSpec"); string tagName = GetStringValue("TAG"); string endpoints = Util.BBGet(JavaServerBB, EndPointTag + tagName) as string; if (rootRegionData != null && rootRegionData.Length > 0) { string rootRegionName; rootRegionName = GetRegionName(rootRegionData); if (rootRegionName != null && rootRegionName.Length > 0) { IRegion <TKey, TVal> region; if ((region = CacheHelper <TKey, TVal> .GetRegion(rootRegionName)) == null) { bool isDC = GetBoolValue("isDurable"); string m_isPool = null; try { // Check if this is a thin-client region; if so set the endpoints int redundancyLevel = 0; if (endpoints != null && endpoints.Length > 0) { redundancyLevel = GetUIntValue(RedundancyLevelKey); if (redundancyLevel < 0) { redundancyLevel = 0; } if (redundancyLevel < 0) { redundancyLevel = 0; } string conflateEvents = GetStringValue(ConflateEventsKey); string durableClientId = ""; int durableTimeout = 300; if (isDC) { durableTimeout = GetUIntValue("durableTimeout"); bool isFeeder = GetBoolValue("isFeeder"); if (isFeeder) { durableClientId = "Feeder"; // VJR: Setting FeederKey because listener cannot read boolean isFeeder // FeederKey is used later on by Verify task to identify feeder's key in BB Util.BBSet("DURABLEBB", "FeederKey", "ClientName_" + Util.ClientNum + "_Count"); } else { durableClientId = String.Format("ClientName_{0}", Util.ClientNum); } } FwkInfo("DurableClientID is {0} and DurableTimeout is {1}", durableClientId, durableTimeout); ResetKey("sslEnable"); bool isSslEnable = GetBoolValue("sslEnable"); CacheHelper <TKey, TVal> .InitConfigForPoolDurable(durableClientId, durableTimeout, conflateEvents, isSslEnable); } RegionFactory rootAttrs = CacheHelper <TKey, TVal> .DCache.CreateRegionFactory(RegionShortcut.PROXY); SetRegionAttributes(rootAttrs, rootRegionData, ref m_isPool); rootAttrs = CreatePool(rootAttrs, redundancyLevel); region = CacheHelper <TKey, TVal> .CreateRegion(rootRegionName, rootAttrs); Apache.Geode.Client.RegionAttributes <TKey, TVal> regAttr = region.Attributes; FwkInfo("Region attributes for {0}: {1}", rootRegionName, CacheHelper <TKey, TVal> .RegionAttributesToString(regAttr)); } catch (Exception ex) { FwkSevere("Caught Exception: {0}", ex); } } } else { FwkSevere("DoCreateRegion() failed to create region"); } } FwkInfo("DoCreateRegion() complete."); }