public void DoLocalGets(int numOps, bool useNewVal)
        {
            string valPrefix = (useNewVal ? NValuePrefix : ValuePrefix);
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(RegionName);

            for (int index = 1; index <= numOps; ++index)
            {
                int    sleepMillis = 100;
                int    numTries    = 30;
                string key         = KeyPrefix + index;
                string value       = valPrefix + index;
                while (numTries-- > 0)
                {
                    if (region.ContainsValueForKey(key))
                    {
                        string foundValue = region[key].ToString();
                        if (value.Equals(foundValue))
                        {
                            break;
                        }
                    }
                    Thread.Sleep(sleepMillis);
                }
            }
            for (int index = 1; index <= numOps; ++index)
            {
                string key = KeyPrefix + index;
                Assert.IsTrue(region.ContainsValueForKey(key));
                Object value = region[key];
                Assert.IsNotNull(value);
                Assert.AreEqual(valPrefix + index, value.ToString());
            }
        }
        public virtual bool WaitForValue(ICacheableKey cKey, int maxTries, int sleepMillis)
        {
            int  tries = 0;
            bool found = false;

            while ((tries++ < maxTries) && (!(found = m_region.ContainsValueForKey(cKey))))
            {
                Thread.Sleep(sleepMillis);
            }
            return(found);
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
        public void doEdgeClientValidation()
        {
            //Validate the number of expected key/values and no. of destroyed entries.
            Util.Log("Verifying expected keys/values");
            Util.Log("Region count is {0} and local region count is {1}", m_region.Count, m_region.GetLocalView().Count);
            TKey key;
            TVal val;
            bool success = true;

            lock (OpMap)
            {
                foreach (KeyValuePair <IRegion <TKey, TVal>, Dictionary <TKey, TVal> > kvp in OpMap)
                {
                    IRegion <TKey, TVal>    myregion = (IRegion <TKey, TVal>)kvp.Key;
                    Dictionary <TKey, TVal> mapp     = (Dictionary <TKey, TVal>)kvp.Value;
                    foreach (KeyValuePair <TKey, TVal> sp in mapp)
                    {
                        key = sp.Key;
                        val = sp.Value;
                        if (!m_region.ContainsKey(key))
                        {
                            FwkTest <TKey, TVal> .CurrentTest.FwkException("Expected containsKey() to be true for key {0} ,but it was false", key);

                            success = false;
                        }
                        if (val != null && !m_region.ContainsValueForKey(key))
                        {
                            FwkTest <TKey, TVal> .CurrentTest.FwkException("Expected containsValueForKey() to be true for key {0} ,but it was false", key);

                            success = false;
                        }
                    }
                }
            }
            if (!success)
            {
                FwkTest <TKey, TVal> .CurrentTest.FwkException("edge client validation failed");
            }
            else
            {
                Util.Log("Done executing doEdgeClientValidation - validation successful");
            }
        }