Exemplo n.º 1
0
        public void TestInsertRangeWithExistingItems()
        {
            var list     = new LargeList <Int32>();
            var size     = (1 << 16) + 2222;
            var oneThird = size / 3;

            for (int i = 0; i < oneThird; i++)
            {
                list.Add(i);
            }
            for (int i = 2 * oneThird; i < 3 * oneThird; i++)
            {
                list.Add(i);
            }
            var helperArray = new Int32[oneThird];

            for (int i = oneThird; i < 2 * oneThird; i++)
            {
                helperArray[i - oneThird] = i;
            }

            list.InsertRange(oneThird, helperArray);

            for (int i = 0; i < 3 * oneThird; i++)
            {
                Assert.AreEqual(list[i], i);
            }
        }
Exemplo n.º 2
0
        public void FilterLargeList()
        {
            if (!args.ValidateLDT())
            {
                return;
            }
            Key key = new Key(args.ns, args.set, "setkey");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Initialize large set operator.
            LargeList llist = client.GetLargeList(null, key, binName);
            int       orig1 = 1;
            int       orig2 = 2;
            int       orig3 = 3;
            int       orig4 = 4;

            // Write values.
            llist.Add(Value.Get(orig1), Value.Get(orig2), Value.Get(orig3), Value.Get(orig4));

            // Filter on values
            IList filterList = llist.Filter("largelist_example", "my_filter_func", Value.Get(orig3));

            Assert.IsNotNull(filterList);
            Assert.AreEqual(1, filterList.Count);

            long v = (long)filterList[0];

            Assert.AreEqual(orig3, (int)v);
        }
Exemplo n.º 3
0
        public void TestSizeConstructor()
        {
            var list = new LargeList <Int32>(1);

            list.Add(1);
            Assert.AreEqual(list.Count, 1);
            foreach (var item in list)
            {
                Assert.AreEqual(item, 1);
            }

            var size = (1 << 14) + 1;

            list = new LargeList <Int32>(size);

            for (int i = 0; i < size * 2; i++)
            {
                list.Add(i);
            }

            for (int i = 0; i < size * 2; i++)
            {
                Assert.AreEqual(list[i], i);
            }
        }
        public void SimpleLargeList()
        {
            Key key = new Key(args.ns, args.set, "setkey");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Initialize large set operator.
            LargeList llist = client.GetLargeList(null, key, binName);
            string    orig1 = "llistValue1";
            string    orig2 = "llistValue2";
            string    orig3 = "llistValue3";

            // Write values.
            llist.Add(Value.Get(orig1));
            llist.Add(Value.Get(orig2));
            llist.Add(Value.Get(orig3));

            // Perform a Range Query -- look for "llistValue2" to "llistValue3"
            IList rangeList = llist.Range(Value.Get(orig2), Value.Get(orig3));

            Assert.IsNotNull(rangeList);
            Assert.AreEqual(2, rangeList.Count);

            string v2 = (string)rangeList[0];
            string v3 = (string)rangeList[1];

            Assert.AreEqual(orig2, v2);
            Assert.AreEqual(orig3, v3);

            // Remove last value.
            llist.Remove(Value.Get(orig3));

            int size = llist.Size();

            Assert.AreEqual(2, size);

            IList  listReceived = llist.Find(Value.Get(orig2));
            string expected     = orig2;

            Assert.IsNotNull(listReceived);

            string stringReceived = (string)listReceived[0];

            Assert.IsNotNull(stringReceived);
            Assert.AreEqual(expected, stringReceived);
        }
Exemplo n.º 5
0
        private LargeList <Int32> CreateList(int size)
        {
            var list = new LargeList <Int32>();

            for (int i = 0; i < size; i++)
            {
                list.Add(i);
            }

            return(list);
        }
Exemplo n.º 6
0
        public void TestInsert()
        {
            var list = new LargeList <Int32>();

            list.Insert(0, 0);
            list.Add(2);

            list.Insert(1, 1);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(i, list[i]);
            }
        }
        public void RunVolumeInsert()
        {
            // This key has already been created in runSimpleExample().
            Key key = new Key(args.ns, args.set, "setkey");

            int       itemCount = 2000;
            LargeList llist2    = client.GetLargeList(null, key, "NumberBin");

            for (int i = itemCount; i > 0; i--)
            {
                llist2.Add(Value.Get(i));
            }
            Assert.AreEqual(2000, llist2.Size());
        }
Exemplo n.º 8
0
        public void TestEnumerator()
        {
            var list        = new LargeList <Int32>();
            var size        = 1 << 20;
            var helperArray = new int[size];

            for (int i = 0; i < size; i++)
            {
                list.Add(i);
                helperArray[i] = i;
            }

            foreach (var num in list)
            {
                Assert.AreEqual(num, helperArray[num]);
            }
        }
Exemplo n.º 9
0
        public void TestSort()
        {
            var size        = (1 << 14) + 1234;
            var list        = new LargeList <Int32>();
            var helperArray = new Int32[size];
            var random      = new Random();

            for (int i = 0; i < size; i++)
            {
                var n = random.Next();
                helperArray[i] = n;
                list.Add(n);
            }

            Array.Sort(helperArray);
            list.Sort();

            for (int i = 0; i < size; i++)
            {
                Assert.AreEqual(helperArray[i], list[i]);
            }
        }
Exemplo n.º 10
0
        public void SimpleLargeList()
        {
            if (!args.ValidateLDT())
            {
                return;
            }
            Key key = new Key(args.ns, args.set, "setkey");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Initialize large set operator.
            LargeList llist = client.GetLargeList(null, key, binName);
            string    orig1 = "llistValue1";
            string    orig2 = "llistValue2";
            string    orig3 = "llistValue3";

            // Write values.
            llist.Add(Value.Get(orig1));
            llist.Add(Value.Get(orig2));
            llist.Add(Value.Get(orig3));

            // Perform exists.
            bool b = llist.Exists(Value.Get(orig2));

            Assert.IsTrue(b);

            b = llist.Exists(Value.Get("notfound"));
            Assert.IsFalse(b);

            // Test record not found.
            LargeList nflist = client.GetLargeList(null, new Key(args.ns, args.set, "sfdfdqw"), binName);

            b = nflist.Exists(Value.Get(orig2));
            Assert.IsFalse(b);

            IList klist = new List <Value>();

            klist.Add(Value.Get(orig2));
            klist.Add(Value.Get(orig1));
            klist.Add(Value.Get("notfound"));
            IList <bool> blist = llist.Exists(klist);

            Assert.IsTrue(blist[0]);
            Assert.IsTrue(blist[1]);
            Assert.IsFalse(blist[2]);

            // Test record not found.
            IList <bool> blist2 = nflist.Exists(klist);

            Assert.IsFalse(blist2[0]);
            Assert.IsFalse(blist2[1]);
            Assert.IsFalse(blist2[2]);

            // Perform a Range Query -- look for "llistValue2" to "llistValue3"
            IList rangeList = llist.Range(Value.Get(orig2), Value.Get(orig3));

            Assert.IsNotNull(rangeList);
            Assert.AreEqual(2, rangeList.Count);

            string v2 = (string)rangeList[0];
            string v3 = (string)rangeList[1];

            Assert.AreEqual(orig2, v2);
            Assert.AreEqual(orig3, v3);

            // Remove last value.
            llist.Remove(Value.Get(orig3));

            int size = llist.Size();

            Assert.AreEqual(2, size);

            IList  listReceived = llist.Find(Value.Get(orig2));
            string expected     = orig2;

            Assert.IsNotNull(listReceived);

            string stringReceived = (string)listReceived[0];

            Assert.IsNotNull(stringReceived);
            Assert.AreEqual(expected, stringReceived);
        }
Exemplo n.º 11
0
        public void RunWithSerializedBin()
        {
            if (!args.ValidateLDT())
            {
                return;
            }
            Key key = new Key(args.ns, args.set, "accountId");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Initialize large list operator.
            LargeList list = client.GetLargeList(null, key, "trades");

            // Write trades
            Dictionary <string, Value> map = new Dictionary <string, Value>();
            MemoryStream ms = new MemoryStream(500);

            DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43);

            map["key"] = Value.Get(timestamp1.Ticks);
            BinaryWriter writer = new BinaryWriter(ms);

            writer.Write("IBM");              // ticker
            writer.Write(100);                // qty
            writer.Write(181.82);             // price
            map["value"] = Value.Get(ms.ToArray());
            list.Add(Value.Get(map));

            DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17);

            map["key"] = Value.Get(timestamp2.Ticks);
            ms.SetLength(0);
            writer = new BinaryWriter(ms);
            writer.Write("GE");              // ticker
            writer.Write(500);               // qty
            writer.Write(26.36);             // price
            map["value"] = Value.Get(ms.ToArray());
            list.Add(Value.Get(map));

            DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19);

            map["key"] = Value.Get(timestamp3.Ticks);
            ms.SetLength(0);
            writer = new BinaryWriter(ms);
            writer.Write("AAPL");              // ticker
            writer.Write(75);                  // qty
            writer.Write(91.85);               // price
            map["value"] = Value.Get(ms.ToArray());
            list.Add(Value.Get(map));

            // Verify list size
            int size = list.Size();

            Assert.AreEqual(3, size);

            // Filter on range of timestamps
            DateTime begin   = new DateTime(2014, 6, 26);
            DateTime end     = new DateTime(2014, 6, 28);
            IList    results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks));

            Assert.IsNotNull(results);
            Assert.AreEqual(2, results.Count);

            // Verify data.
            ValidateWithSerializedBin(results, 0, timestamp2, "GE", 500, 26.36);
            ValidateWithSerializedBin(results, 1, timestamp3, "AAPL", 75, 91.85);
        }
Exemplo n.º 12
0
        public void DistinctBinsLargeList()
        {
            if (!args.ValidateLDT())
            {
                return;
            }
            Key key = new Key(args.ns, args.set, "accountId");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Initialize large list operator.
            LargeList list = client.GetLargeList(null, key, "trades");

            // Write trades
            Dictionary <string, Value> map = new Dictionary <string, Value>();

            DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43);

            map["key"]    = Value.Get(timestamp1.Ticks);
            map["ticker"] = Value.Get("IBM");
            map["qty"]    = Value.Get(100);
            map["price"]  = Value.Get(BitConverter.GetBytes(181.82));
            list.Add(Value.Get(map));

            DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17);

            map["key"]    = Value.Get(timestamp2.Ticks);
            map["ticker"] = Value.Get("GE");
            map["qty"]    = Value.Get(500);
            map["price"]  = Value.Get(BitConverter.GetBytes(26.36));
            list.Add(Value.Get(map));

            DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19);

            map["key"]    = Value.Get(timestamp3.Ticks);
            map["ticker"] = Value.Get("AAPL");
            map["qty"]    = Value.Get(75);
            map["price"]  = Value.Get(BitConverter.GetBytes(91.85));
            list.Add(Value.Get(map));

            // Verify list size
            int size = list.Size();

            Assert.AreEqual(3, size);

            // Filter on range of timestamps
            DateTime begin   = new DateTime(2014, 6, 26);
            DateTime end     = new DateTime(2014, 6, 28);
            IList    results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks));

            Assert.IsNotNull(results);
            Assert.AreEqual(2, results.Count);

            // Verify data.
            ValidateWithDistinctBins(results, 0, timestamp2, "GE", 500, 26.36);
            ValidateWithDistinctBins(results, 1, timestamp3, "AAPL", 75, 91.85);

            IList rows = list.Scan();

            foreach (IDictionary row in rows)
            {
                foreach (DictionaryEntry entry in row)
                {
                    //console.Info(entry.Key.ToString());
                    //console.Info(entry.Value.ToString());
                }
            }
        }