Example #1
0
        private static bool Check(BerkeleyKeyValueCursor cursor, List <int> keys)
        {
            var readKeys = new List <int>();

            for (BerkeleyResult <BerkeleyKeyValue> result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_FIRST).Result;
                 result.Error.BerkeleyDbError != BerkeleyDbError.DB_NOTFOUND;
                 result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_NEXT).Result)
            {
                result.Error.ThrowIfError();

                String skey = Encoding.UTF8.GetString(result.Result.Key);
                int    ikey = int.Parse(skey.Replace("key", ""));

                String svalue = Encoding.UTF8.GetString(result.Result.Value);
                int    ivalue = int.Parse(svalue.Replace("value", ""));

                if (ikey != ivalue)
                {
                    throw new InvalidOperationException();
                }

                readKeys.Add(ikey);
            }

            return(keys.SequenceEqual(readKeys));
        }
        private static int GetPageSize(BerkeleyDb bdb)
        {
            BerkeleyResult <int> pageSizeResult = bdb.GetPageSizeAsync().Result;

            pageSizeResult.Error.ThrowIfError();
            return(pageSizeResult.Result);
        }
Example #3
0
 private static void ReadAll(BerkeleyKeyValueCursor cursor)
 {
     for (BerkeleyResult <BerkeleyKeyValue> result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_FIRST).Result;
          result.Error.BerkeleyDbError != BerkeleyDbError.DB_NOTFOUND;
          result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_NEXT).Result)
     {
         result.Error.ThrowIfError();
         WriteLine(result.Result.Key, result.Result.Value);
     }
 }
        private static void KeyValueCheck(BerkeleyKeyValueCursor cursor, List <int> keys)
        {
            var readKeys = new List <int>();

            for (BerkeleyResult <BerkeleyKeyValue> result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_FIRST).Result;
                 result.Error.BerkeleyDbError != BerkeleyDbError.DB_NOTFOUND;
                 result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_NEXT).Result)
            {
                result.Error.ThrowIfError();

                String skey = Encoding.UTF8.GetString(result.Result.Key);
                int    ikey = int.Parse(skey.Replace("key", ""));

                String svalue = Encoding.UTF8.GetString(result.Result.Value);
                int    ivalue = int.Parse(svalue.Replace("value", ""));

                Assert.IsTrue(ikey == ivalue, "read error");

                readKeys.Add(ikey);
            }

            Assert.IsTrue(keys.SequenceEqual(readKeys), "delete error");
        }