Exemplo n.º 1
0
        public void Lesser()
        {
            //register the type to get a valid TypeDescription
            //the type description is used to create CachedObjects from objects of the registered type
            var typeDescription = ClientSideTypeDescription.RegisterType(typeof(CacheableTypeOk));

            KeyInfo valueKey = null;

            foreach (var keyInfo in typeDescription.IndexFields)
            {
                if (keyInfo.Name == "IndexKeyValue")
                {
                    valueKey = keyInfo.AsKeyInfo;
                }
            }

            Assert.IsNotNull(valueKey);


            //fill in order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80)));

                checkLE(indexByValue);
                checkLS(indexByValue);
            }

            //fill out of order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6)));


                checkLE(indexByValue);
                checkLS(indexByValue);
            }

            //fill out of order transactional
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.BeginFill();

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6)));
                indexByValue.EndFill();

                checkLE(indexByValue);
                checkLS(indexByValue);
            }


            //all equals
            {
                var indexByValue = new OrderedIndex(valueKey);

                var keyType = new KeyInfo(KeyDataType.IntKey, KeyType.ScalarIndex, "test", true);

                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 45)));
                indexByValue.Put(CachedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 45)));

                //value not fount (too small)
                var result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 0);

                result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);

                //value not found (too big)
                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 6);

                //value found (all match the index key )
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                //not found (Lt)
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);
            }
        }
Exemplo n.º 2
0
        public void Lesser()
        {
            var schema = TypedSchemaFactory.FromType <CacheableTypeOk>();

            //register the type to get a valid CollectionSchema
            //the type description is used to create CachedObjects from objects of the registered type
            var typeDescription = TypedSchemaFactory.FromType(typeof(CacheableTypeOk));

            KeyInfo valueKey = null;

            foreach (var keyInfo in typeDescription.IndexFields)
            {
                if (keyInfo.Name == "IndexKeyValue")
                {
                    valueKey = keyInfo;
                }
            }

            Assert.IsNotNull(valueKey);


            //fill in order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80), schema));

                CheckLe(indexByValue);
                CheckLs(indexByValue);
            }

            //fill out of order
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6), schema));


                CheckLe(indexByValue);
                CheckLs(indexByValue);
            }

            //fill out of order transactional
            {
                var indexByValue = new OrderedIndex(valueKey);

                indexByValue.BeginFill();

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 80), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 1), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 13), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 4), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 14), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 6), schema));
                indexByValue.EndFill();

                CheckLe(indexByValue);
                CheckLs(indexByValue);
            }


            //all equals
            {
                var indexByValue = new OrderedIndex(valueKey);

                var keyType = new KeyInfo("test", 0, IndexType.Ordered);

                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(6, 106, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(1, 101, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(4, 104, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(2, 102, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(5, 105, "A", DateTime.Now, 45), schema));
                indexByValue.Put(PackedObject.Pack(new CacheableTypeOk(3, 103, "A", DateTime.Now, 45), schema));

                //value not fount (too small)
                var result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 0);

                result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);

                //value not found (too big)
                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                result1 = indexByValue.GetMany(MakeIntValue(50, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 6);

                //value found (all match the index key )
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Le);
                Assert.AreEqual(result1.Count, 6);

                //not found (Lt)
                result1 = indexByValue.GetMany(MakeIntValue(45, keyType), QueryOperator.Lt);
                Assert.AreEqual(result1.Count, 0);
            }
        }