public virtual bool WaitForKey(string key, int maxTries, int sleepMillis)
        {
            int  tries = 0;
            bool found = false;

            while ((tries < maxTries) && (!(found = m_region.ContainsKey(key))))
            {
                Thread.Sleep(sleepMillis);
                tries++;
            }
            return(found);
        }
Exemple #2
0
        public void checkContainsKey(int txnState)
        {
            IRegion <TKey, TVal>    region    = GetRegion();
            Dictionary <TKey, TVal> BfTxOpMap = new Dictionary <TKey, TVal>();
            Dictionary <TKey, TVal> AfTxOpMap = new Dictionary <TKey, TVal>();

            try
            {
                if (txnState == 3)
                {
                    BfTxOpMap = BeforeTxMap["put"];
                    AfTxOpMap = AfterTxMap["put"];
                }
                else
                {
                    BfTxOpMap = BeforeTxMap["put"];
                }
            }
            catch (Exception e)
            {
                FwkException("Throwing this exception {0} BMap cpunt={1} AfMap Count={2}", e.Message, BfTxOpMap.Count, AfTxOpMap.Count);
            }
            FwkInfo("BfTxOpmap count is {0} and AfterTxMap is {1}", BfTxOpMap.Count, AfTxOpMap.Count);
            foreach (KeyValuePair <TKey, TVal> bkp in BfTxOpMap)
            {
                FwkInfo("Inside BfTxOpMap");
                TKey BfTxKey = bkp.Key;
                if (!region.ContainsKey(BfTxKey))
                {
                    FwkException("getKey: expected key {0} is not present in the region key set", bkp.Key.ToString());
                }
            }
            foreach (KeyValuePair <TKey, TVal> akp in AfTxOpMap)
            {
                FwkInfo("Inside AfTxOpMap");
                TKey AfTxKey = akp.Key;
                if (!region.ContainsKey(AfTxKey))
                {
                    FwkException("getKey: expected key {0} is not present in the region key set", akp.Key.ToString());
                }
            }
        }
Exemple #3
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");
            }
        }
        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);

                Console.WriteLine("Created the RegionFactory.");

                // Create the example Region
                IRegion <string, string> region = regionFactory.Create <string, string>("exampleRegion");

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

                // Get the cache transaction manager from the cache.
                CacheTransactionManager txManager = cache.CacheTransactionManager;

                // Starting a transaction
                txManager.Begin();
                Console.WriteLine("Transaction started.");

                region["Key1"] = "Value1";
                region["Key2"] = "Value2";

                Console.WriteLine("Put two entries into the region");

                try {
                    // Prepare the transaction
                    txManager.Prepare();
                    Console.WriteLine("Transaction Prepared");

                    // Commit the transaction
                    txManager.Commit();
                    Console.WriteLine("Transaction Committed");
                }
                catch (CommitConflictException e)
                {
                    Console.WriteLine("CommitConflictException encountered. Exception: {0}", e.Message);
                }

                if (region.ContainsKey("Key1"))
                {
                    Console.WriteLine("Obtained the first entry from the Region");
                }

                if (region.ContainsKey("Key2"))
                {
                    Console.WriteLine("Obtained the second entry from the Region");
                }

                //start a new transaction
                txManager.Begin();
                Console.WriteLine("Transaction Started");

                // Put a new entry
                region["Key3"] = "Value3";
                Console.WriteLine("Put the third entry into the Region");

                // remove the first key
                region.Remove("Key1", null);
                Console.WriteLine("remove the first entry");

                txManager.Prepare();
                Console.WriteLine("Transaction Prepared");

                txManager.Rollback();
                Console.WriteLine("Transaction Rollbacked");

                if (region.ContainsKey("Key1"))
                {
                    Console.WriteLine("Obtained the first entry from the Region");
                }

                if (region.ContainsKey("Key2"))
                {
                    Console.WriteLine("Obtained the second entry from the Region");
                }

                if (region.ContainsKey("Key3"))
                {
                    Console.WriteLine("ERROR: Obtained the third entry from the Region.");
                }

                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("Transactions Geode Exception: {0}", gfex.Message);
            }
        }
 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.ContainsKey(keys.ToString()), "Key should have been found in the region");
 }
Exemple #6
0
        public override void DoTask(int iters, object data)
        {
            Int32 localcnt = m_cnt;

            Interlocked.Increment(ref m_cnt);
            IDictionary <TKey, TVal> hmoc = new Dictionary <TKey, TVal>();

            lock (m_maps)
            {
                m_maps.Add(hmoc);
            }
            int  offset = Util.Rand(m_MaxKeys);
            int  count  = offset;
            TKey key    = default(TKey);

            Util.Log("EntryTask::DoTask: starting {0} iterations.", iters);
            while (Running && (iters-- != 0))
            {
                int idx = count % m_MaxKeys;
                key = (TKey)(object)("AAAAAA" + localcnt + idx.ToString("D10"));
                string opcode = FwkTest <TKey, TVal> .CurrentTest.GetStringValue("entryOps");

                if (opcode == null)
                {
                    opcode = "no-opcode";
                }
                if (opcode == "put")
                {
                    lock (CLASS_LOCK)
                    {
                        DeltaTestImpl newValue = null;
                        if (m_region.ContainsKey(key))
                        {
                            DeltaTestImpl oldValue = m_region[key] as DeltaTestImpl;
                            if (oldValue == null)
                            {
                                newValue      = getLatestDelta(key, localcnt, false);
                                m_region[key] = (TVal)(object)newValue;
                            }
                            else
                            {
                                newValue = new DeltaTestImpl(oldValue);
                                newValue.SetIntVar(oldValue.GetIntVar() + 1);
                                m_region[key] = (TVal)(object)newValue;
                            }
                            Interlocked.Increment(ref m_update);
                            //Util.BBSet("ToDeltaBB", key.ToString(), newValue.GetToDeltaCounter());
                        }
                        else
                        {
                            newValue = getLatestDelta(key, localcnt, true);
                            m_region.Add(key, (TVal)(object)newValue);
                            Interlocked.Increment(ref m_create);
                        }
                        //(m_maps[localcnt]).Add(key, newValue);
                        m_maps[localcnt][key] = (TVal)(object)newValue;
                    }
                }
                else if (opcode == "destroy")
                {
                    DeltaTestImpl oldValue = null;
                    if (m_region.ContainsKey(key))
                    {
                        if ((oldValue = m_region[key] as DeltaTestImpl) == null)
                        {
                            if (m_isDestroy)
                            {
                                m_region.Remove(key);
                                (m_maps[localcnt]).Remove(key);
                            }
                        }
                        else
                        {
                            m_maps[localcnt][key] = (TVal)(object)oldValue;
                            m_region.Remove(key);
                            //(m_maps[localcnt]).Remove(key);
                        }
                        Interlocked.Increment(ref m_destroy);
                    }
                }
                else if (opcode == "invalidate")
                {
                    DeltaTestImpl oldValue = null;
                    if (m_region.ContainsKey(key))
                    {
                        if ((oldValue = m_region[key] as DeltaTestImpl) != null)
                        {
                            m_maps[localcnt].Add(key, (TVal)(object)oldValue);
                            m_region.Invalidate(key);
                            Interlocked.Increment(ref m_invalidate);
                            m_maps[localcnt].Add(key, default(TVal));
                        }
                    }
                }
            }
            Interlocked.Add(ref m_iters, count - offset);
        }