public void XmlCacheCreationWithOverflow()

in clicache/integration-test/OverflowTestsN.cs [420:659]


    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();
        }
      }
    }