Esempio n. 1
0
        protected void invalidateEntry(IRegion <TKey, TVal> r, bool isLocalInvalidate)
        {
            TKey key                 = GetExistingKey(true, r);
            bool containsKey         = m_region.GetLocalView().ContainsKey(key);
            bool containsValueForKey = m_region.GetLocalView().ContainsValueForKey(key);

            Util.Log("containsKey for " + key + ": " + containsKey);
            Util.Log("containsValueForKey for " + key + ": " + containsValueForKey);
            try
            {
                if (isLocalInvalidate)
                { // do a local invalidate
                    m_region.GetLocalView().Invalidate(key);
                }
                else
                { // do a distributed invalidate
                    m_region.Invalidate(key);
                }
            }
            catch (EntryNotFoundException e)
            {
                Util.Log("Caught {0} (expected); continuing with test", e);
                return;
            }
        }
Esempio n. 2
0
        protected void destroyEntry(IRegion <TKey, TVal> m_region, bool isLocalDestroy)
        {
            TKey key = GetExistingKey(true, m_region);
            bool isSerialExecution = false;

            try
            {
                if (isLocalDestroy)
                { // do a local invalidate
                    m_region.GetLocalView().Remove(key);
                }
                else
                { // do a distributed invalidate
                    m_region.Remove(key);
                }
            }
            catch (EntryNotFoundException e)
            {
                if (isSerialExecution)
                {
                    throw new Exception(e.StackTrace);
                }
                else
                {
                    Util.Log("Caught {0} (expected with concurrent execution); continuing with test", e);
                    return;
                }
            }
        }
        void VerifyCloning()
        {
            Thread.Sleep(1000);
            string cKey = m_keys[0];
            IRegion <object, object> reg = CacheHelper.GetRegion <object, object>("DistRegionAck");
            DeltaTestImpl            val = reg[cKey] as DeltaTestImpl;

            if (val.GetIntVar() != 2)
            {
                Assert.Fail("Int value after cloning should be 2, is " + val.GetIntVar());
            }
            if (DeltaTestImpl.GetFromDataCount() != 2)
            {
                Assert.Fail("After cloning, fromDataCount should have been 2, is " + DeltaTestImpl.GetFromDataCount());
            }
            if (DeltaTestImpl.GetToDataCount() != 1)
            {
                Assert.Fail("After cloning, toDataCount should have been 1, is " + DeltaTestImpl.GetToDataCount());
            }

            System.Threading.Thread.Sleep(5000);
            //Assert.Greater(javaobject.PdxDelta.GotDelta, 7, "this should have recieve delta");
            javaobject.PdxDelta pd = (javaobject.PdxDelta)(reg.GetLocalView()["pdxdelta"]);
            Assert.Greater(pd.Delta, 7, "this should have recieve delta");
        }
Esempio n. 4
0
        private int GetNumOfEntries()
        {
            try
            {
                ICollection <object> keys = m_region.GetLocalView().Keys;

                if (keys != null)
                {
                    return(keys.Count);
                }
            }
            catch (RegionDestroyedException)
            {
            }
            return(0);
        }
Esempio n. 5
0
        private IRegion <object, object> CreateOverflowRegion(string regionName, string libraryName, string factoryFunctionName)
        {
            RegionFactory rf = CacheHelper.DCache.CreateRegionFactory(RegionShortcut.LOCAL);

            rf.SetCachingEnabled(true);
            rf.SetLruEntriesLimit(20);
            rf.SetInitialCapacity(1000);
            rf.SetDiskPolicy(DiskPolicyType.Overflows);

            Properties <string, string> sqliteProperties = new Properties <string, string>();

            sqliteProperties.Insert("PageSize", "65536");
            sqliteProperties.Insert("MaxFileSize", "512000000");
            String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString();

            sqliteProperties.Insert("PersistenceDirectory", sqlite_dir);

            rf.SetPersistenceManager(libraryName, factoryFunctionName, sqliteProperties);

            CacheHelper.Init();
            IRegion <object, object> region = CacheHelper.GetRegion <object, object>(regionName);

            if ((region != null) && !region.IsDestroyed)
            {
                region.GetLocalView().DestroyRegion();
                Assert.IsTrue(region.IsDestroyed, "IRegion<object, object> {0} was not destroyed.", regionName);
            }
            region = rf.Create <object, object>(regionName);
            Assert.IsNotNull(region, "IRegion<object, object> was not created.");

            return(region);
        }
Esempio n. 6
0
        public void StepOneQE(string locators, bool isPdx)
        {
            m_isPdx = isPdx;
            try
            {
                var poolFail    = CacheHelper.DCache.GetPoolManager().CreateFactory().Create("_TESTFAILPOOL_");
                var qsFail      = poolFail.GetQueryService();
                var qryFail     = qsFail.NewQuery <object>("select distinct * from /" + QERegionName);
                var resultsFail = qryFail.Execute();
                Assert.Fail("Since no endpoints defined, so exception expected");
            }
            catch (IllegalStateException ex)
            {
                Util.Log("Got expected exception: {0}", ex);
            }
            catch (Exception e) {
                Util.Log("Caught unexpected exception: {0}", e);
                throw e;
            }

            CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true,
                                                             null, locators, "__TESTPOOL1_", true);
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName);

            if (!m_isPdx)
            {
                Portfolio p1 = new Portfolio(1, 100);
                Portfolio p2 = new Portfolio(2, 100);
                Portfolio p3 = new Portfolio(3, 100);
                Portfolio p4 = new Portfolio(4, 100);

                region["1"] = p1;
                region["2"] = p2;
                region["3"] = p3;
                region["4"] = p4;
            }
            else
            {
                PortfolioPdx p1 = new PortfolioPdx(1, 100);
                PortfolioPdx p2 = new PortfolioPdx(2, 100);
                PortfolioPdx p3 = new PortfolioPdx(3, 100);
                PortfolioPdx p4 = new PortfolioPdx(4, 100);

                region["1"] = p1;
                region["2"] = p2;
                region["3"] = p3;
                region["4"] = p4;
            }

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();

            Query <object>          qry     = qs.NewQuery <object>("select distinct * from /" + QERegionName);
            ISelectResults <object> results = qry.Execute();
            var count = results.Size;

            Assert.AreEqual(4, count, "Expected 4 as number of portfolio objects.");

            // Bring down the region
            region.GetLocalView().DestroyRegion();
        }
        public void StepOneQE(string locators)
        {
            CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true,
                                                             null, locators, "__TESTPOOL1_", true);
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName);

            string[] /*sta*/ cnm = { "C#aaa", "C#bbb", "C#ccc", "C#ddd" };
            //CacheableStringArray cnm = CacheableStringArray.Create(sta);
            Portfolio p1 = new Portfolio(1, 2, cnm);
            Portfolio p2 = new Portfolio(2, 2, cnm);
            Portfolio p3 = new Portfolio(3, 2, cnm);
            Portfolio p4 = new Portfolio(4, 2, cnm);

            region["1"] = p1;
            region["2"] = p2;
            region["3"] = p3;
            region["4"] = p4;

            var                     qs      = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();
            Query <object>          qry     = qs.NewQuery <object>("select * from /" + QERegionName + "  p where p.ID!=3");
            ISelectResults <object> results = qry.Execute();

            Util.Log("Results size {0}.", results.Size);

            SelectResultsIterator <object> iter = results.GetIterator();

            while (iter.HasNext)
            {
                /*IGeodeSerializable*/ object item = iter.Next();
                Portfolio port = item as Portfolio;
                if (port == null)
                {
                    Position pos = item as Position;
                    if (pos == null)
                    {
                        //CacheableString cs = item as CacheableString;
                        string cs = item as string;
                        if (cs == null)
                        {
                            Util.Log("Query got other/unknown object.");
                        }
                        else
                        {
                            Util.Log("Query got string : {0}.", cs);
                        }
                    }
                    else
                    {
                        Util.Log("Query got Position object with secId {0}, shares {1}.", pos.SecId, pos.SharesOutstanding);
                    }
                }
                else
                {
                    Util.Log("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid);
                }
            }
            // Bring down the region
            region.GetLocalView().DestroyRegion();
        }
Esempio n. 8
0
 public void InvalidateOp(int key, Object CallbackArg)
 {
     for (int i = 1; i <= key; i++)
     {
         Util.Log("InvalidateOp:key={0}", i);
         m_region.GetLocalView().Invalidate(i, CallbackArg);
     }
 }
        public void DoLocalPut()
        {
            region1 = CacheHelper.GetRegion <object, object>(RegionName);
            region1.GetLocalView()[m_keys[2]] = m_vals[2];
            Assert.IsTrue(region1.GetLocalView().ContainsKey(m_keys[2]), "Key should have been found in the region");
            Assert.AreEqual(true, m_writer.IsWriterInvoked, "Writer Should be invoked");
            Assert.AreEqual(true, m_listener.IsListenerInvoked, "Listener Should be invoked");

            //try Update
            try
            {
                Util.Log("Trying UpdateEntry");
                m_listener.ResetListenerInvokation();
                UpdateEntry(RegionName, m_keys[2], m_nvals[2], false);
                Assert.Fail("Should have got NotAuthorizedException during updateEntry");
            }
            catch (NotAuthorizedException)
            {
                Util.Log("NotAuthorizedException Caught");
                Util.Log("Success");
            }
            catch (Exception other)
            {
                Util.Log("Stack trace: {0} ", other.StackTrace);
                Util.Log("Got  exception : {0}", other.Message);
            }
            Assert.AreEqual(true, m_writer.IsWriterInvoked, "Writer should be invoked");
            Assert.AreEqual(false, m_listener.IsListenerInvoked, "Listener should not be invoked");
            Assert.IsTrue(region1.GetLocalView().ContainsKey(m_keys[2]), "Key should have been found in the region");
            VerifyEntry(RegionName, m_keys[2], m_vals[2]);
            m_writer.SetWriterFailed();

            //test CacheWriter
            try
            {
                Util.Log("Testing CacheWriterException");
                UpdateEntry(RegionName, m_keys[2], m_nvals[2], false);
                Assert.Fail("Should have got NotAuthorizedException during updateEntry");
            }
            catch (CacheWriterException)
            {
                Util.Log("CacheWriterException Caught");
                Util.Log("Success");
            }
        }
Esempio n. 10
0
        protected TKey GetExistingKey(bool useServerKeys, IRegion <TKey, TVal> region)
        {
            TKey key = default(TKey);

            if (useServerKeys)
            {
                int    size = region.Count;
                TKey[] keys = (TKey[])region.Keys;
                key = keys[Util.Rand(0, size)];
            }
            else
            {
                int    size = region.GetLocalView().Count;
                TKey[] keys = (TKey[])region.GetLocalView().Keys;
                key = keys[Util.Rand(0, size)];
            }
            return(key);
        }
Esempio n. 11
0
        public virtual void Test(int key, int value, bool noack)
        {
            string     cKey   = "key" + key.ToString();
            StackFrame sf     = new StackFrame(1, true);
            int        line   = sf.GetFileLineNumber();
            string     method = sf.GetMethod().Name;

            if (value == -1)
            {
                Assert.IsFalse(m_region.GetLocalView().ContainsKey(cKey),
                               "unexpected key found at line {0} in method {1}.", line, method);
                if (noack)
                { // need to wait a bit and retest...
                    Thread.Sleep(1000);
                    Assert.IsFalse(m_region.GetLocalView().ContainsKey(cKey),
                                   "unexpected key found at line {0} in method {1}.", line, method);
                }
            }
            else if (value == 0)
            {
                if (noack)
                {
                    WaitForKey(cKey);
                }
                Assert.IsTrue(m_region.GetLocalView().ContainsKey(cKey),
                              "missing key at line {0} in method {1}.", line, method);
                Assert.IsFalse(m_region.ContainsValueForKey(cKey),
                               "should have found invalid at line {0} in method {1}.", line, method);
            }
            else
            {
                if (noack)
                {
                    WaitForKey(cKey);
                }
                Assert.IsTrue(m_region.GetLocalView().ContainsKey(cKey),
                              "missing key at line {0} in method {1}.", line, method);
                int val = WaitForValue(cKey, value, noack);
                Assert.AreEqual(value, val,
                                "unexpected value: \"{0}\", expected \"{1}\" from line {2} in method {3}",
                                val, value, line, method);
            }
        }
        void StepFourPdx()
        {
            Thread.Sleep(2000);
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);

            IRegion <object, object> regionLocal = region.GetLocalView();
            object ret = regionLocal[1];

            Assert.IsNotNull(ret);
            Assert.IsTrue(ret is IPdxSerializable);
        }
Esempio n. 13
0
 public void DoValidateDeltaTest()
 {
     FwkInfo("DoValidateDeltaTest() called.");
     try
     {
         IRegion <TKey, TVal> region = GetRegion();
         region.GetLocalView().DestroyRegion();
         TKey  key = default(TKey);
         Int32 expectedAfterCreateEvent  = (Int32)Util.BBGet("DeltaBB", "CREATECOUNT");
         Int32 expectedAfterUpdateEvent  = (Int32)Util.BBGet("DeltaBB", "UPDATECOUNT");
         Int32 expectedAfterDestroyEvent = (Int32)Util.BBGet("DeltaBB", "DESTROYCOUNT");
         long  eventAfterCreate          = (long)Util.BBGet("DeltaBB", "AFTER_CREATE_COUNT_" + Util.ClientId + "_" + region.Name);
         long  eventAfterUpdate          = (long)Util.BBGet("DeltaBB", "AFTER_UPDATE_COUNT_" + Util.ClientId + "_" + region.Name);
         long  eventAfterDestroy         = (long)Util.BBGet("DeltaBB", "AFTER_DESTROY_COUNT_" + Util.ClientId + "_" + region.Name);
         FwkInfo("DoValidateDeltaTest() -- eventAfterCreate {0} ,eventAfterUpdate {1} ,eventAfterDestroy {2}", eventAfterCreate, eventAfterUpdate, eventAfterDestroy);
         FwkInfo("DoValidateDeltaTest() -- expectedAfterCreateEvent {0} ,expectedAfterUpdateEvent {1}, expectedAfterDestroyEvent {2} ", expectedAfterCreateEvent, expectedAfterUpdateEvent, expectedAfterDestroyEvent);
         if (expectedAfterCreateEvent == eventAfterCreate && expectedAfterUpdateEvent == eventAfterUpdate && expectedAfterDestroyEvent == eventAfterDestroy)
         {
             DeltaClientValidationListener <TKey, TVal> cs = (region.Attributes.CacheListener) as DeltaClientValidationListener <TKey, TVal>;
             IDictionary <TKey, Int64> map = cs.getMap();
             Int32 mapCount        = map.Count;
             Int32 toDeltaMapCount = (Int32)Util.BBGet("MapCount", "size");
             if (mapCount == toDeltaMapCount)
             {
                 foreach (KeyValuePair <TKey, Int64> item in map)
                 {
                     key = (TKey)(object)item.Key;
                     Int64 value          = item.Value;
                     long  fromDeltaCount = (long)value;
                     long  toDeltaCount   = (long)Util.BBGet("ToDeltaBB", key.ToString());
                     if (toDeltaCount == fromDeltaCount)
                     {
                         FwkInfo("DoValidateDeltaTest() Delta Count Validation success with fromDeltaCount: {0} = toDeltaCount: {1}", fromDeltaCount, toDeltaCount);
                     }
                 }
                 FwkInfo("DoValidateDeltaTest() Validation success.");
             }
             else
             {
                 FwkException("Validation Failed() as fromDeltaMapCount: {0} is not equal to toDeltaMapCount: {1}", mapCount, toDeltaMapCount);
             }
         }
         else
         {
             FwkException("Validation Failed()for Region: {0} Expected were expectedAfterCreateEvent {1} expectedAfterUpdateEvent {2} expectedAfterDestroyEvent {3} eventAfterCreate {4}, eventAfterUpdate {5} ", region.Name, expectedAfterCreateEvent, expectedAfterUpdateEvent, expectedAfterDestroyEvent, eventAfterCreate, eventAfterUpdate, eventAfterDestroy);
         }
     }
     catch (Exception ex)
     {
         FwkException("DoValidateDeltaTest() Caught Exception: {0}", ex);
         FwkInfo("DoValidateDeltaTest() complete.");
     }
 }
Esempio n. 14
0
 public void DoFeederOps()
 {
     foreach (string regionName in RegionNamesForInterestNotify)
     {
         IRegion <object, object> region = CacheHelper.GetRegion <object, object>(regionName);
         foreach (string key in m_keysNonRegex)
         {
             region[key] = "11";
             region[key] = "22";
             region[key] = "33";
             region.GetLocalView().Invalidate(key);
             region.Remove(key);
         }
         foreach (string key in m_keysForRegex)
         {
             region[key] = "11";
             region[key] = "22";
             region[key] = "33";
             region.GetLocalView().Invalidate(key);
             region.Remove(key);
         }
     }
 }
Esempio n. 15
0
        private void TestEntryDestroy(IRegion <object, object> region)
        {
            //ICollection<object> cKeys = region.Keys;
            ICollection <object> cKeys = region.GetLocalView().Keys;

            string[] arrKeys = new string[cKeys.Count];
            cKeys.CopyTo(arrKeys, 0);

            for (int i = 50; i < 60; i++)
            {
                try
                {
                    region.GetLocalView().Remove(arrKeys[i]);
                }
                catch (Exception ex)
                {
                    Util.Log("Entry missing for {0}. Exception: {1}", arrKeys[i], ex.ToString());
                }
            }
            cKeys = region.GetLocalView().Keys;

            Assert.AreEqual(90, cKeys.Count, "Number of keys is not correct.");
        }
Esempio n. 16
0
    void DoDeltaAD_C1_afterC2Put()
    {
      Thread.Sleep(15000);
      DeltaTestAD val = null;
      IRegion<object, object> reg = CacheHelper.GetRegion<object, object>("DistRegionAck");
      Util.Log("client fetching entry from local cache");
      val = (DeltaTestAD)reg.GetEntry(1).Value;
      Assert.IsNotNull(val);
      Assert.AreEqual(3, val.DeltaUpdate);
      Util.Log("done");

      System.Threading.Thread.Sleep(5000);
      //Assert.Greater(javaobject.PdxDelta.GotDelta, 7, "this should have recieve delta");
      javaobject.PdxDelta pd = (javaobject.PdxDelta)(reg.GetLocalView()["pdxdelta"]);
      Assert.Greater(pd.Delta, 7, "this should have recieve delta");
    }
Esempio n. 17
0
        private void TestGetOp(IRegion <object, object> region, int num)
        {
            DoNput(region, num);

            ICollection <object> cKeys = region.GetLocalView().Keys;
            object cVal;

            Assert.AreEqual(num, cKeys.Count, "Number of keys does not match.");
            foreach (object cKey in cKeys)
            {
                RegionEntry <object, object> entry = region.GetEntry(cKey);
                cVal = entry.Value;
                if (IsOverflowed(cVal))
                {
                    cVal = region[cKey];
                    Assert.IsFalse(IsOverflowed(cVal), "Overflow token even after a Region.Get");
                }
            }
        }
Esempio n. 18
0
        private void CheckOverflowToken(IRegion <object, object> region, int num, int lruLimit)
        {
            //IGeodeSerializable cVal;
            //ICacheableKey[] cKeys = region.GetKeys();

            object cVal;
            ICollection <object> cKeys = region.GetLocalView().Keys;

            Assert.AreEqual(num, cKeys.Count, "Number of keys does not match.");
            int count = 0;

            foreach (object cKey in cKeys)
            {
                RegionEntry <object, object> entry = region.GetEntry(cKey);
                cVal = entry.Value;
                if (IsOverflowed(cVal))
                {
                    count++;
                }
            }
            Assert.AreEqual(0, count, "Number of overflowed entries should be zero");
        }
Esempio n. 19
0
        private void SetupRegion(uint entryTTL, uint entryIdleTimeout,
                                 uint regionTTL, uint regionIdleTimeout)
        {
            const ExpirationAction action = ExpirationAction.Destroy;

            RegionFactory rf = CacheHelper.DCache.CreateRegionFactory(RegionShortcut.LOCAL);

            rf.SetEntryTimeToLive(action, entryTTL);
            rf.SetEntryIdleTimeout(action, entryIdleTimeout);
            rf.SetRegionTimeToLive(action, regionTTL);
            rf.SetRegionIdleTimeout(action, regionIdleTimeout);

            CacheHelper.Init();
            IRegion <object, object> region = CacheHelper.GetRegion <object, object>(m_regionName);

            if ((region != null) && !region.IsDestroyed)
            {
                region.GetLocalView().DestroyRegion();
                Assert.IsTrue(region.IsDestroyed, "IRegion<object, object> {0} was not destroyed.", m_regionName);
            }
            m_region = rf.Create <object, object>(m_regionName);
            Assert.IsNotNull(m_region, "IRegion<object, object> was not created.");
        }
Esempio n. 20
0
        public void StepOneQE(string locators)
        {
            CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true,
                                                             null, locators, "__TESTPOOL1_", true);

            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName);
            Portfolio p1 = new Portfolio(1, 100);
            Portfolio p2 = new Portfolio(2, 100);
            Portfolio p3 = new Portfolio(3, 100);
            Portfolio p4 = new Portfolio(4, 100);

            region["1"] = p1;
            region["2"] = p2;
            region["3"] = p3;
            region["4"] = p4;

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();
            CqAttributesFactory <object, object> cqFac    = new CqAttributesFactory <object, object>();
            ICqListener <object, object>         cqLstner = new MyCqListener <object, object>();

            cqFac.AddCqListener(cqLstner);
            CqAttributes <object, object> cqAttr  = cqFac.Create();
            CqQuery <object, object>      qry     = qs.NewCq(CqName, "select * from /" + QERegionName + "  p where p.ID!=2", cqAttr, false);
            ICqResults <object>           results = qry.ExecuteWithInitialResults();

            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
            region["4"] = p1;
            region["3"] = p2;
            region["2"] = p3;
            region["1"] = p4;
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
            Util.Log("Results size {0}.", results.Size);

            foreach (var item in results)
            {
                if (item != null)
                {
                    Struct st = item as Struct;

                    string key = st["key"] as string;

                    Assert.IsNotNull(key, "key is null");

                    Portfolio port = st["value"] as Portfolio;

                    if (port == null)
                    {
                        Position pos = st["value"] as Position;
                        if (pos == null)
                        {
                            string cs = item as string;

                            if (cs == null)
                            {
                                Assert.Fail("value is null");
                                Util.Log("Query got other/unknown object.");
                            }
                            else
                            {
                                Util.Log("Query got string : {0}.", cs);
                            }
                        }
                        else
                        {
                            Util.Log("Query got Position object with secId {0}, shares {1}.", pos.SecId, pos.SharesOutstanding);
                        }
                    }
                    else
                    {
                        Util.Log("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid);
                    }
                }
            }
            qry = qs.GetCq <object, object>(CqName);
            qry.Stop();
            qry.Close();
            // Bring down the region
            region.GetLocalView().DestroyRegion();
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache.
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();

                Cache cache = cacheFactory.Create();

                Console.WriteLine("Created the Geode Cache");

                RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);

                IRegion <int, string> region = regionFactory.Create <int, string>("exampleRegion");

                Console.WriteLine("Created the Region with generics support programmatically.");

                // Put an Entry (Key and Value pair) into the Region using the IDictionary interface.
                region[111] = "Value1";

                Console.WriteLine("Put the first Entry into the Region");

                // Put an Entry into the Region the traditional way.
                region[123] = "123";

                Console.WriteLine("Put the second Entry into the Region");

                PerformanceCounter pc = new PerformanceCounter("Memory", "Available Bytes");
                long freeMemory       = Convert.ToInt64(pc.NextValue());

                // Are we a 64 bit process and do we have 5 GB free memory available?
                if (IntPtr.Size == 8 && freeMemory > 5L * 1024L * 1024L * 1024L)
                {
                    Char   ch   = 'A';
                    string text = new string(ch, 1024 * 1024);
                    Console.WriteLine("Putting over 4 GB data locally...");
                    for (int item = 0; item < (5 * 1024 /* 5 GB */); item++)
                    {
                        region.GetLocalView()[item] = text;
                    }
                    Console.WriteLine("Put over 4 GB data locally");
                }
                else
                {
                    Console.WriteLine("Not putting over 4 GB data locally due to lack of memory capacity");
                }

                // Get Entries back out of the Region via the IDictionary interface.
                string result1 = region[111];

                Console.WriteLine("Obtained the first Entry from the Region");

                string result2 = region[123];

                Console.WriteLine("Obtained the second Entry from the Region");

                // Invalidate an Entry in the Region.
                region.Invalidate(111);

                Console.WriteLine("Invalidated the first Entry in the Region");

                // Destroy an Entry in the Region using the IDictionary interface.
                region.Remove(123);

                Console.WriteLine("Destroyed the second Entry in the Region");

                // Close the Geode Cache.
                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("BasicOperations Geode Exception: {0}", gfex.Message);
            }
        }
Esempio n. 22
0
        public void OverflowPutGetManagedSetInstance()
        {
            RegionFactory rf = CacheHelper.DCache.CreateRegionFactory(RegionShortcut.LOCAL);

            rf.SetCachingEnabled(true);
            rf.SetLruEntriesLimit(20);
            rf.SetInitialCapacity(1000);
            rf.SetDiskPolicy(DiskPolicyType.Overflows);

            Properties <string, string> sqliteProperties = new Properties <string, string>();

            sqliteProperties.Insert("PageSize", "65536");
            sqliteProperties.Insert("MaxFileSize", "512000000");
            String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString();

            sqliteProperties.Insert("PersistenceDirectory", sqlite_dir);

            //rf.SetPersistenceManager(new Apache.Geode.Plugins.SQLite.SqLiteImpl<object, object>(), sqliteProperties);
            rf.SetPersistenceManager("SqLiteImpl", "createSqLiteInstance", sqliteProperties);

            CacheHelper.Init();
            IRegion <object, object> region = CacheHelper.GetRegion <object, object>("OverFlowRegion");

            if ((region != null) && !region.IsDestroyed)
            {
                region.GetLocalView().DestroyRegion();
                Assert.IsTrue(region.IsDestroyed, "IRegion<object, object> OverFlowRegion was not destroyed.");
            }
            region = rf.Create <object, object>("OverFlowRegion");
            Assert.IsNotNull(region, "IRegion<object, object> was not created.");
            ValidateAttributes(region);

            //Console.WriteLine("TEST-2");
            // put some values into the cache.
            DoNput(region, 100);
            //Console.WriteLine("TEST-2.1 All PUts Donee");

            CheckNumOfEntries(region, 100);

            //Console.WriteLine("TEST-3");
            // check whether value get evicted and token gets set as overflow
            CheckOverflowToken(region, 100, 20);
            // do some gets... printing what we find in the cache.
            DoNget(region, 100);
            TestEntryDestroy(region);
            TestGetOp(region, 100);

            //Console.WriteLine("TEST-4");
            // test to verify same region repeatedly to ensure that the persistece
            // files are created and destroyed correctly

            IRegion <object, object> subRegion;

            for (int i = 0; i < 1; i++)
            {
                subRegion = CreateSubRegion(region, "SubRegion", "Apache.Geode.Plugins.SqLite", "SqLiteImpl<object,object>.Create()");
                subRegion.DestroyRegion();
                Assert.IsTrue(subRegion.IsDestroyed, "Expected region to be destroyed");
                Assert.IsFalse(File.Exists(GetSqLiteFileName(sqlite_dir, "SubRegion")), "Persistence file present after region destroy");
            }
            //Console.WriteLine("TEST-5");
        }
Esempio n. 23
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache through XMLs/clientDelta.xml
                Properties <string, string> prop = Properties <string, string> .Create <string, string>();

                prop.Insert("cache-xml-file", "XMLs/clientDelta.xml");
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(prop);
                Cache        cache        = cacheFactory.Create();

                Console.WriteLine("Created the Geode Cache");

                // Get the example Region from the Cache which is declared in the Cache XML file.
                IRegion <string, DeltaExample> region = cache.GetRegion <string, DeltaExample>("exampleRegion");

                Console.WriteLine("Obtained the Region from the Cache");

                Serializable.RegisterTypeGeneric(DeltaExample.create);

                //Creating Delta Object.
                DeltaExample ptr = new DeltaExample(10, 15, 20);

                //Put the delta object. This will send the complete object to the server.
                region["Key1"] = ptr;

                Console.WriteLine("Completed put for a delta object");


                //Changing state of delta object.
                ptr.setField1(9);

                //Put delta object again. Since delta flag is set true it will calculate
                //Delta and send only Delta to the server.
                region["Key1"] = ptr;
                Console.WriteLine("Completed put with delta");

                //Locally invalidating the key.
                region.GetLocalView().Invalidate("Key1");
                //Fetching the value from server.
                DeltaExample retVal = (DeltaExample)region["Key1"];

                //Verification
                if (retVal.getField1() != 9)
                {
                    throw new GeodeException("First field should have been 9");
                }
                if (retVal.getField2() != 15)
                {
                    throw new GeodeException("Second field should have been 15");
                }
                if (retVal.getField3() != 20)
                {
                    throw new GeodeException("Third field should have been 20");
                }

                Console.WriteLine("Delta has been successfully applied at server");

                // Close the Geode Cache.
                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("Delta Geode Exception: {0}", gfex.Message);
            }
        }
Esempio n. 24
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache Programmatically.
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
                Cache        cache        = cacheFactory.SetSubscriptionEnabled(true)
                                            .Create();

                Console.WriteLine("Created the Geode Cache");

                RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
                // Create the example Region programmatically.
                IRegion <string, string> region = regionFactory
                                                  .SetEntryIdleTimeout(ExpirationAction.Destroy, 10)
                                                  .Create <string, string>("exampleRegion");

                Console.WriteLine("Created the Region with generics support programmatically.");

                // Plugin the SimpleCacheListener to the Region.
                AttributesMutator <string, string> attrMutator = region.AttributesMutator;
                attrMutator.SetCacheListener(new SimpleCacheListener <string, string>());

                Console.WriteLine("Set the generic SimpleCacheListener on the Region");

                // Put 3 Entries into the Region using the IDictionary interface.
                region["Key1"] = "Value1";
                region["Key2"] = "Value2";
                region["Key3"] = "Value3";

                Console.WriteLine("Put 3 Entries into the Region");

                // Get the Entry Idle Timeout specified in the Cache XML file.
                int entryIdleTimeout = region.Attributes.EntryIdleTimeout;

                Console.WriteLine("Got Entry Idle Timeout as {0} seconds", entryIdleTimeout);

                // Wait for half the Entry Idle Timeout duration.
                Thread.Sleep(entryIdleTimeout * 1000 / 2);

                // Get the number of Keys remaining in the Region, should be all 3.
                ICollection <string> keys = region.GetLocalView().Keys;

                Console.WriteLine("Got {0} keys before the Entry Idle Timeout duration elapsed", keys.Count);

                // Get 2 of the 3 Entries from the Region to "reset" their Idle Timeouts.
                string value1 = region["Key1"];
                string value2 = region["Key2"];

                Console.WriteLine("The SimpleCacheListener should next report the expiration action");

                // Wait for the entire Entry Idle Timeout duration.
                Thread.Sleep(entryIdleTimeout * 1000);

                // Get the number of Keys remaining in the Region, should be 0 now.
                keys = region.GetLocalView().Keys;

                Console.WriteLine("Got {0} keys after the Entry Idle Timeout duration elapsed", keys.Count);

                // Close the Geode Cache.
                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("DataExpiration Geode Exception: {0}", gfex.Message);
            }
        }
        public void StepOnePdxQE(string locators)
        {
            CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true,
                                                             null, locators, "__TESTPOOL1_", true);
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName);
            PortfolioPdx             p1     = new PortfolioPdx(1, 100);
            PortfolioPdx             p2     = new PortfolioPdx(2, 100);
            PortfolioPdx             p3     = new PortfolioPdx(3, 100);
            PortfolioPdx             p4     = new PortfolioPdx(4, 100);

            region["1"] = p1;
            region["2"] = p2;
            region["3"] = p3;
            region["4"] = p4;

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();
            CqAttributesFactory <object, object> cqFac    = new CqAttributesFactory <object, object>();
            ICqListener <object, object>         cqLstner = new MyCqListener <object, object>();

            cqFac.AddCqListener(cqLstner);
            CqAttributes <object, object> cqAttr = cqFac.Create();
            CqQuery <object, object>      qry    = qs.NewCq(CqName, "select * from /" + QERegionName + "  p where p.ID!=2", cqAttr, false);

            qry.Execute();
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
            region["4"] = p1;
            region["3"] = p2;
            region["2"] = p3;
            region["1"] = p4;
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete

            qry = qs.GetCq <object, object>(CqName);

            CqServiceStatistics cqSvcStats = qs.GetCqStatistics();

            Assert.AreEqual(1, cqSvcStats.numCqsActive());
            Assert.AreEqual(1, cqSvcStats.numCqsCreated());
            Assert.AreEqual(1, cqSvcStats.numCqsOnClient());

            cqAttr = qry.GetCqAttributes();
            ICqListener <object, object>[] vl = cqAttr.getCqListeners();
            Assert.IsNotNull(vl);
            Assert.AreEqual(1, vl.Length);
            cqLstner = vl[0];
            Assert.IsNotNull(cqLstner);
            MyCqListener <object, object> myLisner = (MyCqListener <object, object>)cqLstner;// as MyCqListener<object, object>;

            Util.Log("event count:{0}, error count {1}.", myLisner.getEventCountBefore(), myLisner.getErrorCountBefore());

            CqStatistics cqStats = qry.GetStatistics();

            Assert.AreEqual(cqStats.numEvents(), myLisner.getEventCountBefore());
            if (myLisner.getEventCountBefore() + myLisner.getErrorCountBefore() == 0)
            {
                Assert.Fail("cq before count zero");
            }
            qry.Stop();
            Assert.AreEqual(1, cqSvcStats.numCqsStopped());
            qry.Close();
            Assert.AreEqual(1, cqSvcStats.numCqsClosed());
            // Bring down the region
            region.GetLocalView().DestroyRegion();
        }
 public void CheckAssert()
 {
     Assert.AreEqual(true, m_writer.IsWriterInvoked, "Writer Should be invoked");
     Assert.AreEqual(false, m_listener.IsListenerInvoked, "Listener Should not be invoked");
     Assert.IsFalse(region.GetLocalView().ContainsKey(keys), "Key should have been found in the region");
 }