예제 #1
0
 public void ClassCleanUp()
 {
     if (_cacheFactory != null)
     {
         _cacheFactory.Close();
     }
 }
예제 #2
0
        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();
                }
            }
        }
예제 #3
0
        public void runPoolXmlCreation()
        {
            string xmlLocation = CacheHelper.TestDir + Path.DirectorySeparatorChar + "valid_cache_pool.xml";

            string duplicateXMLFile = Util.Rand(3432898).ToString() + "valid_cache_pool.xml";

            CacheHelper.createDuplicateXMLFile(xmlLocation, duplicateXMLFile);
            xmlLocation = duplicateXMLFile;

            var cache = new CacheFactory()
                        .Set("cache-xml-file", xmlLocation)
                        .Create();

            Region[] rootRegions = cache.RootRegions <object, object>();
            Assert.AreEqual(2, rootRegions.Length);

            ICollection <IRegion <object, object> > subRegionsCol = rootRegions[0].SubRegions(true);

            Region[] subRegions = new Region[subRegionsCol.Count];
            subRegionsCol.CopyTo(subRegions, 0);
            Assert.AreEqual(1, subRegions.Length);

            ICollection <IRegion <object, object> > subRegions2Col = rootRegions[1].SubRegions(true);

            Region[] subRegions2 = new Region[subRegions2Col.Count];
            subRegions2Col.CopyTo(subRegions2, 0);
            Assert.AreEqual(0, subRegions2.Length);

            string poolNameRegion1   = rootRegions[0].Attributes.PoolName;
            string poolNameRegion2   = rootRegions[1].Attributes.PoolName;
            string poolNameSubRegion = subRegions[0].Attributes.PoolName;

            Assert.AreEqual("test_pool_1", poolNameRegion1);
            Assert.AreEqual("test_pool_2", poolNameRegion2);
            Assert.AreEqual("test_pool_2", poolNameSubRegion);

            Pool poolOfRegion1   = cache.GetPoolManager().Find(poolNameRegion1);
            Pool poolOfRegion2   = cache.GetPoolManager().Find(poolNameRegion2);
            Pool poolOfSubRegion = cache.GetPoolManager().Find(poolNameSubRegion);

            string[] locators = new string[1] {
                "localhost:" + CacheHelper.LOCATOR_PORT_1
            };
            string[] servers = new string[2] {
                "localhost:" + CacheHelper.HOST_PORT_1, "localhost:" + CacheHelper.HOST_PORT_2
            };

            // ARB:
            // TODO: check if server list contains the two endpoints (currently using null argument for servers list)
            bool check1 = checkPoolAttributes(poolOfRegion1, locators, null, TimeSpan.FromMilliseconds(12345), TimeSpan.FromMilliseconds(23456), 3, 7, 3, TimeSpan.FromMilliseconds(5555), TimeSpan.FromMilliseconds(12345),
                                              "test_pool_1", TimeSpan.FromMilliseconds(23456), "ServerGroup1", 32768, true, TimeSpan.FromMilliseconds(900123), TimeSpan.FromMilliseconds(567), 0, TimeSpan.FromMilliseconds(10123), 5, true, TimeSpan.FromMilliseconds(250001));

            bool check2 = checkPoolAttributes(poolOfRegion2, null, servers, TimeSpan.FromMilliseconds(23456), TimeSpan.FromMilliseconds(34567), 2, 8, 5, TimeSpan.FromMilliseconds(6666), TimeSpan.FromMilliseconds(23456),
                                              "test_pool_2", TimeSpan.FromMilliseconds(34567), "ServerGroup2", 65536, false, TimeSpan.FromMilliseconds(800222), TimeSpan.FromMilliseconds(678), 1, TimeSpan.FromMilliseconds(20345), 3, false, TimeSpan.FromMilliseconds(5000));

            bool check3 = checkPoolAttributes(poolOfSubRegion, null, servers, TimeSpan.FromMilliseconds(23456), TimeSpan.FromMilliseconds(34567), 2, 8, 5, TimeSpan.FromMilliseconds(6666), TimeSpan.FromMilliseconds(23456),
                                              "test_pool_2", TimeSpan.FromMilliseconds(34567), "ServerGroup2", 65536, false, TimeSpan.FromMilliseconds(800222), TimeSpan.FromMilliseconds(678), 1, TimeSpan.FromMilliseconds(20345), 3, false, TimeSpan.FromMilliseconds(5000));

            Assert.IsTrue(check1, "Attribute check 1 failed");
            Assert.IsTrue(check2, "Attribute check 2 failed");
            Assert.IsTrue(check3, "Attribute check 3 failed");

            cache.Close();
            try
            {
                Util.Log("Testing invalid_cache_pool.xml");
                xmlLocation      = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_cache_pool.xml";
                duplicateXMLFile = Util.Rand(3432898).ToString() + "invalid_cache_pool.xml";
                CacheHelper.createDuplicateXMLFile(xmlLocation, duplicateXMLFile);
                xmlLocation = duplicateXMLFile;
                cache       = new CacheFactory()
                              .Set("cache-xml-file", xmlLocation)
                              .Create();
                Assert.Fail("invalid_cache_pool.xml did not throw exception");
            }
            catch (GeodeException excp)
            {
                Util.Log("Expected {0}: {1}", excp.GetType().Name, excp.Message);
            }

            try
            {
                Util.Log("Testing invalid_cache_pool2.xml");
                xmlLocation      = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_cache_pool2.xml";
                duplicateXMLFile = Util.Rand(3432898).ToString() + "invalid_cache_pool2.xml";
                CacheHelper.createDuplicateXMLFile(xmlLocation, duplicateXMLFile);
                xmlLocation = duplicateXMLFile;
                cache       = new CacheFactory()
                              .Set("cache-xml-file", xmlLocation)
                              .Create();
                Assert.Fail("invalid_cache_pool2.xml did not throw exception");
            }
            catch (GeodeException excp)
            {
                Util.Log("Expected {0}: {1}", excp.GetType().Name, excp.Message);
            }

            try
            {
                Util.Log("Testing invalid_cache_pool3.xml");
                xmlLocation      = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_cache_pool3.xml";
                duplicateXMLFile = "invalid_cache_pool3.xml";
                CacheHelper.createDuplicateXMLFile(xmlLocation, duplicateXMLFile);
                xmlLocation = duplicateXMLFile;
                cache       = new CacheFactory()
                              .Set("cache-xml-file", xmlLocation)
                              .Create();
                Assert.Fail("invalid_cache_pool3.xml did not throw exception");
            }
            catch (GeodeException excp)
            {
                Util.Log("Expected {0}: {1}", excp.GetType().Name, excp.Message);
            }

            try
            {
                Util.Log("Testing invalid_cache_pool4.xml");
                xmlLocation      = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_cache_pool4.xml";
                duplicateXMLFile = Util.Rand(3432898).ToString() + "invalid_cache_pool4.xml";
                CacheHelper.createDuplicateXMLFile(xmlLocation, duplicateXMLFile);
                xmlLocation = duplicateXMLFile;
                cache       = new CacheFactory()
                              .Set("cache-xml-file", xmlLocation)
                              .Create();
                Assert.Fail("invalid_cache_pool4.xml did not throw exception");
            }
            catch (GeodeException excp)
            {
                Util.Log("Expected {0}: {1}", excp.GetType().Name, excp.Message);
            }
        }