Ejemplo n.º 1
0
        public void LongKeyCASHashTableCheckDeleteNotFound()
        {
            var    hashTable = new CAS.LongKeyCASHashTable(arrayLength, keyByteArrayLength, contentByteArrayLength);
            string message   = "";

            Assert.AreEqual(hashTable.TryDelete(message), -2);
        }
Ejemplo n.º 2
0
        public void LongKeyCASHashTableCheckDelete()
        {
            var hashTable = new CAS.LongKeyCASHashTable(arrayLength, keyByteArrayLength, contentByteArrayLength);
            var result    = Utility.GetDataString().Result;

            var    u8  = Encoding.UTF8;
            string key = null;

            byte[] content = null;

            foreach (var record in result.EmptyIfNull())
            {
                key     = record.linkId.ToString() + "-" + record.clcId.ToString() + "-" + record.sbp;
                content = u8.GetBytes(record.url);
                Assert.AreEqual(hashTable.TrySet(key, content), 0);
            }

            key     = null;
            content = null;

            foreach (var record in result.EmptyIfNull())
            {
                key = record.linkId.ToString() + "-" + record.clcId.ToString() + "-" + record.sbp;
                Assert.AreEqual(hashTable.TryDelete(key), 0);
                Assert.AreEqual(hashTable.TryGet(key, out content), -3);
                Assert.IsNull(content);
                content = null;
            }
        }
Ejemplo n.º 3
0
        public void LongKeyCASHashTableCheckDeleteInvildInput()
        {
            var hashTable = new CAS.LongKeyCASHashTable(arrayLength, keyByteArrayLength, contentByteArrayLength);

            string message = null;

            try { hashTable.TryDelete(message); }
            catch (ArgumentNullException e)
            { message = e.Message; }
            Assert.IsTrue(message.Contains("key"));

            message = Encoding.UTF8.GetString(new byte[keyByteArrayLength + 1]);

            try { hashTable.TryDelete(message); }
            catch (ArgumentOutOfRangeException e)
            { message = e.Message; }
            Assert.IsTrue(message.Contains("Key length shouldn't longer than init value when you create hash table."));
        }
Ejemplo n.º 4
0
        public void LongKeyCASHashTableCheckGetDeleted()
        {
            var hashTable = new CAS.LongKeyCASHashTable(arrayLength, keyByteArrayLength, contentByteArrayLength);

            string message = "";

            byte[] content = new byte[] { 0xff };

            Assert.AreEqual(hashTable.TrySet(message, content), 0);
            Assert.AreEqual(hashTable.TryDelete(message), 0);

            content = null;
            Assert.AreEqual(hashTable.TryGet(message, out content), -3);
            Assert.IsNull(content);
        }
        private void LongKeyperfDeleteOneRecordVerifyResult(ManualResetEvent mre, CAS.LongKeyCASHashTable hashTable, List <RecordString> record, int index)
        {
            mre.WaitOne();
            var u8 = Encoding.UTF8;

            int InputParametersError = 0;
            int NoExists             = 0;
            int IsDeleted            = 0;
            int ExceptionError       = 0;
            int DeleteSuccessfully   = 0;
            int Zero = 0;

            int result;

            var externalStopWatch = new Stopwatch();

            externalStopWatch.Start();

            var internalStopWatch = new Stopwatch();

            string key = record[index].linkId.ToString() + "-" + record[index].clcId.ToString() + "-" + record[index].sbp;

            for (var i = 0; i < perfTestAttemptsForDelete; i++)
            {
                internalStopWatch.Start();
                result = hashTable.TryDelete(key);
                internalStopWatch.Stop();

                switch (result)
                {
                case 0:
                    Interlocked.Increment(ref DeleteSuccessfully);
                    break;

                case -1:
                    Interlocked.Increment(ref InputParametersError);
                    break;

                case -2:
                    Interlocked.Increment(ref NoExists);
                    break;

                case -3:
                    Interlocked.Increment(ref IsDeleted);
                    break;

                case -4:
                    Interlocked.Increment(ref ExceptionError);
                    break;

                default:
                    Interlocked.Increment(ref Zero);
                    break;
                }
                ;
            }

            var internalTs = internalStopWatch.Elapsed;

            externalStopWatch.Stop();
            var externalTs = externalStopWatch.Elapsed;

            Console.WriteLine(
                "TaskId" + "\t" + Task.CurrentId + "\t" +
                "perfDeleteOneRecordVerifyResult" + "\t" + perfTestAttemptsForDelete + "\t" +
                "InternalAPICallTotalTime" + "\t" + internalTs.ToString() + "\t" +
                "TestingTotalTime" + "\t" + externalTs.ToString() + "\t" +
                "DeleteSuccessfully" + "\t" + DeleteSuccessfully + "\t" +
                "InputParametersError" + "\t" + InputParametersError + "\t" +
                "NoExists" + "\t" + NoExists + "\t" +
                "IsDeleted" + "\t" + IsDeleted + "\t" +
                "ExceptionError" + "\t" + ExceptionError + "\t" +
                "Zero" + "\t" + Zero + "\t"
                );
        }