Example #1
0
 public void KeyIn54BitCheckDeleteNotFound()
 {
     try
     {
         var hashTable = new KeyIn54BitCASHashTable(arrayLength, contentLength);
         Assert.AreEqual(hashTable.TryDelete(2097151, 262143, 16383), -2);
     }
     catch (Exception ex)
     {
         if (log.IsFatalEnabled)
         {
             log.Fatal(ex.Message + "\t" + ex.StackTrace);
         }
     }
 }
Example #2
0
        public void KeyIn54BitCheckUpdateBringDeletedBack()
        {
            KeyIn54BitCASHashTable hashTable = null;

            try
            {
                hashTable = new KeyIn54BitCASHashTable(arrayLength, contentLength);
            }
            catch (Exception ex)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(ex.Message + "\t" + ex.StackTrace);
                }
            }

            var result = Utility.GetData().Result;

            int SBPCounter   = 0;
            var SBPHashTable = new ConcurrentDictionary <string, int>();
            int SBPId        = 0;

            foreach (var record in result.EmptyIfNull())
            {
                if (!SBPHashTable.ContainsKey(record.sbp))
                {
                    SBPId = Interlocked.Increment(ref SBPCounter);
                    SBPHashTable.TryAdd(record.sbp, SBPId);
                }
                else
                {
                    SBPId = SBPHashTable[record.sbp];
                }
                try
                {
                    Assert.AreEqual(hashTable.TrySet(record.linkId, record.clcId, SBPId, record.url), 0);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
            }

            string message = string.Empty;

            byte[] output;

            foreach (var record in result.EmptyIfNull())
            {
                SBPId = SBPHashTable[record.sbp];
                try
                {
                    Assert.AreEqual(hashTable.TryDelete(record.linkId, record.clcId, SBPId), 0);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
                output = null;
                try
                {
                    Assert.AreEqual(hashTable.TryGet(record.linkId, record.clcId, SBPId, out output), -3);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
                Assert.IsNull(output);
            }

            var u8 = Encoding.UTF8;

            //Update all the records again.
            foreach (var record in result.EmptyIfNull())
            {
                SBPId = SBPHashTable[record.sbp];
                try
                {
                    Assert.AreEqual(hashTable.TrySet(record.linkId, record.clcId, SBPId, record.url), 1);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
            }

            //We should get all the URL again.
            output = null;
            foreach (var record in result.EmptyIfNull())
            {
                SBPId = SBPHashTable[record.sbp];
                try
                {
                    Assert.AreEqual(hashTable.TryGet(record.linkId, record.clcId, SBPId, out output), 0);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
                Assert.AreEqual(u8.GetString(record.url), u8.GetString(output));
            }
        }
Example #3
0
        public void KeyIn54BitCheckDeleteAgain()
        {
            var stopWatch = new Stopwatch();
            KeyIn54BitCASHashTable hashTable = null;

            try
            {
                hashTable = new KeyIn54BitCASHashTable(arrayLength, contentLength);
            }
            catch (Exception ex)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(ex.Message + "\t" + ex.StackTrace);
                }
            }
            var result = Utility.GetData().Result;

            int SBPCounter   = 0;
            var SBPHashTable = new ConcurrentDictionary <string, int>();
            int SBPId        = 0;

            foreach (var record in result.EmptyIfNull())
            {
                if (!SBPHashTable.ContainsKey(record.sbp))
                {
                    SBPId = Interlocked.Increment(ref SBPCounter);
                    SBPHashTable.TryAdd(record.sbp, SBPId);
                }
                else
                {
                    SBPId = SBPHashTable[record.sbp];
                }
                try
                {
                    Assert.AreEqual(hashTable.TrySet(record.linkId, record.clcId, SBPId, record.url), 0);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
            }

            byte[] output;

            foreach (var record in result.EmptyIfNull())
            {
                SBPId = SBPHashTable[record.sbp];
                try
                {
                    Assert.AreEqual(hashTable.TryDelete(record.linkId, record.clcId, SBPId), 0);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
                output = null;

                try
                {
                    Assert.AreEqual(hashTable.TryGet(record.linkId, record.clcId, SBPId, out output), -3);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
                Assert.IsNull(output);
            }

            output = null;
            //Delete all the records again and nothing should happens.
            foreach (var record in result.EmptyIfNull())
            {
                SBPId = SBPHashTable[record.sbp];
                try
                {
                    Assert.AreEqual(hashTable.TryDelete(record.linkId, record.clcId, SBPId), -3);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }

                output = null;
                try
                {
                    Assert.AreEqual(hashTable.TryGet(record.linkId, record.clcId, SBPId, out output), -3);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }
                Assert.IsNull(output);
            }
        }
Example #4
0
        public void KeyIn54BitCheckDeleteInvildInput()
        {
            KeyIn54BitCASHashTable hashTable = null;

            try
            {
                hashTable = new KeyIn54BitCASHashTable(arrayLength, contentLength);
            }
            catch (Exception ex)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(ex.Message + "\t" + ex.StackTrace);
                }
            }

            try
            {
                string message = null;
                try { hashTable.TryDelete(0, 1, 1); }
                catch (ArgumentOutOfRangeException e)
                { message = e.Message; }
                Assert.IsTrue(message.Contains("linkId"));

                message = null;
                try { hashTable.TryDelete(4194304, 1, 1); }
                catch (ArgumentOutOfRangeException e)
                { message = e.Message; }
                Assert.IsTrue(message.Contains("linkId"));

                message = null;
                try { hashTable.TryDelete(1, 0, 1); }
                catch (ArgumentOutOfRangeException e)
                { message = e.Message; }
                Assert.IsTrue(message.Contains("clcId"));

                message = null;
                try { hashTable.TryDelete(1, 262144, 1); }
                catch (ArgumentOutOfRangeException e)
                { message = e.Message; }
                Assert.IsTrue(message.Contains("clcId"));

                message = null;
                try { hashTable.TryDelete(1, 1, 0); }
                catch (ArgumentOutOfRangeException e)
                { message = e.Message; }
                Assert.IsTrue(message.Contains("sbp"));

                message = null;
                try { hashTable.TryDelete(1, 1, 16384); }
                catch (ArgumentOutOfRangeException e)
                { message = e.Message; }
                Assert.IsTrue(message.Contains("sbp"));
            }
            catch (Exception ex)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(ex.Message + "\t" + ex.StackTrace);
                }
            }
        }
Example #5
0
        public void KeyIn54BitCheckGetDeleted()
        {
            KeyIn54BitCASHashTable hashTable = null;

            try
            {
                hashTable = new KeyIn54BitCASHashTable(arrayLength, contentLength);
            }
            catch (Exception ex)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(ex.Message + "\t" + ex.StackTrace);
                }
            }
            var result = Utility.GetData().Result;

            int SBPCounter   = 0;
            var SBPHashTable = new ConcurrentDictionary <string, int>();
            int SBPId        = 0;
            int i            = 0;

            long linkIdTemp = 0;
            long clcIdTemp  = 0;
            long SBPIdTemp  = 0;

            foreach (var record in result.EmptyIfNull())
            {
                if (!SBPHashTable.ContainsKey(record.sbp))
                {
                    SBPId = Interlocked.Increment(ref SBPCounter);
                    SBPHashTable.TryAdd(record.sbp, SBPId);
                }
                else
                {
                    SBPId = SBPHashTable[record.sbp];
                }

                try
                {
                    Assert.AreEqual(hashTable.TrySet(record.linkId, record.clcId, SBPId, record.url), 0);
                }
                catch (Exception ex)
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(ex.Message + "\t" + ex.StackTrace);
                    }
                }

                if (i++ == 1)
                {
                    linkIdTemp = record.linkId;
                    clcIdTemp  = record.clcId;
                    SBPIdTemp  = SBPId;
                }
            }

            try
            {
                Assert.AreEqual(hashTable.TryDelete(linkIdTemp, clcIdTemp, SBPIdTemp), 0);
                byte[] output = null;
                Assert.AreEqual(hashTable.TryGet(linkIdTemp, clcIdTemp, SBPIdTemp, out output), -3);
                Assert.IsNull(output);
            }
            catch (Exception ex)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(ex.Message + "\t" + ex.StackTrace);
                }
            }
        }