public void TestExtractorSerialization()
        {
            ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml");

            Assert.IsNotNull(ctx);

            ChainedExtractor         chainedExtractor         = new ChainedExtractor("member1");
            ComparisonValueExtractor comparisonValueExtractor = new ComparisonValueExtractor("member2", "member3");
            IdentityExtractor        identityExtractor        = new IdentityExtractor();
            KeyExtractor             keyExtractor             = new KeyExtractor("member4");
            MultiExtractor           multiExtractor           = new MultiExtractor("member5,member6,member7");
            ReflectionExtractor      reflectionExtractor      = new ReflectionExtractor("member8");

            Stream stream = new MemoryStream();

            ctx.Serialize(new DataWriter(stream), chainedExtractor);
            ctx.Serialize(new DataWriter(stream), comparisonValueExtractor);
            ctx.Serialize(new DataWriter(stream), identityExtractor);
            ctx.Serialize(new DataWriter(stream), keyExtractor);
            ctx.Serialize(new DataWriter(stream), multiExtractor);
            ctx.Serialize(new DataWriter(stream), reflectionExtractor);

            stream.Position = 0;
            Assert.AreEqual(chainedExtractor, ctx.Deserialize(new DataReader(stream)));
            Assert.AreEqual(comparisonValueExtractor, ctx.Deserialize(new DataReader(stream)));
            Assert.AreEqual(identityExtractor, ctx.Deserialize(new DataReader(stream)));
            Assert.AreEqual(keyExtractor, ctx.Deserialize(new DataReader(stream)));
            Assert.AreEqual(multiExtractor, ctx.Deserialize(new DataReader(stream)));
            Assert.AreEqual(reflectionExtractor, ctx.Deserialize(new DataReader(stream)));

            stream.Close();
        }
        public void TestComparisonValueExtractor()
        {
            // testing on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Score score = new Score(1, 1, 126, 10000L, 1.24f, 1432.55, new decimal(11223344), new RawInt128(new byte[] { 1 }), 1);

            cache.Insert("score1", score);

            IValueExtractor exByte    = new ReflectionExtractor("getByteValue");
            IValueExtractor exShort   = new ReflectionExtractor("getShortValue");
            IValueExtractor exInt     = new ReflectionExtractor("getIntValue");
            IValueExtractor exLong    = new ReflectionExtractor("getLongValue");
            IValueExtractor exFloat   = new ReflectionExtractor("getFloatValue");
            IValueExtractor exDouble  = new ReflectionExtractor("getDoubleValue");
            IValueExtractor exDecimal = new ReflectionExtractor("getBigDecimalValue");
            IValueExtractor exInt128  = new ReflectionExtractor("getBigIntegerValue");

            //different ways to instantiate same extractor
            ComparisonValueExtractor cve1 = new ComparisonValueExtractor(exByte, exShort);
            ComparisonValueExtractor cve2 = new ComparisonValueExtractor(exInt, exLong);
            ComparisonValueExtractor cve3 = new ComparisonValueExtractor(exFloat, exDouble);
            ComparisonValueExtractor cve4 = new ComparisonValueExtractor(exDecimal, exDecimal);
            ComparisonValueExtractor cve5 = new ComparisonValueExtractor(exInt128, exInt128);

            IFilter     filter = new EqualsFilter(cve1, score.ByteValue - score.ShortValue);
            ICollection keys   = cache.GetKeys(filter);

            Assert.IsNotEmpty(keys);
            Assert.IsTrue(keys.Count == 1);

            filter = new EqualsFilter(cve2, score.IntValue - score.LongValue);
            keys   = cache.GetKeys(filter);
            Assert.IsNotEmpty(keys);
            Assert.IsTrue(keys.Count == 1);

            filter = new EqualsFilter(cve3, score.FloatValue - score.DoubleValue);
            keys   = cache.GetKeys(filter);
            Assert.IsNotEmpty(keys);
            Assert.IsTrue(keys.Count == 1);

            filter = new EqualsFilter(cve4, (decimal)0);
            keys   = cache.GetKeys(filter);
            Assert.IsNotEmpty(keys);
            Assert.IsTrue(keys.Count == 1);

            filter = new EqualsFilter(cve5, NumberUtils.DecimalToRawInt128(score.RawInt128Value.ToDecimal() - score.RawInt128Value.ToDecimal()));
            keys   = cache.GetKeys(filter);
            Assert.IsNotEmpty(keys);
            Assert.IsTrue(keys.Count == 1);

            CacheFactory.Shutdown();
        }
        public void TestUnitComparisonValueExtractor()
        {
            IValueExtractor exByte    = new ReflectionExtractor("ByteValue");
            IValueExtractor exShort   = new ReflectionExtractor("ShortValue");
            IValueExtractor exInt     = new ReflectionExtractor("IntValue");
            IValueExtractor exLong    = new ReflectionExtractor("LongValue");
            IValueExtractor exFloat   = new ReflectionExtractor("FloatValue");
            IValueExtractor exDouble  = new ReflectionExtractor("DoubleValue");
            IValueExtractor exDecimal = new ReflectionExtractor("DecimalValue");
            IValueExtractor exInt128  = new ReflectionExtractor("RawInt128Value");

            IValueExtractor[] extractors = new IValueExtractor[] { exDouble, exInt };
            //different ways to instantiate same extractor
            ComparisonValueExtractor cve1 = new ComparisonValueExtractor(extractors);
            ComparisonValueExtractor cve2 = new ComparisonValueExtractor(exDouble, exInt);
            ComparisonValueExtractor cve3 = new ComparisonValueExtractor(exDouble, exInt, null);
            ComparisonValueExtractor cve4 = new ComparisonValueExtractor("DoubleValue", "IntValue");
            ComparisonValueExtractor cve5 = new ComparisonValueExtractor("DoubleValue", "IntValue", null);

            Assert.IsNotNull(cve1);
            Assert.IsNotNull(cve2);
            Assert.IsNotNull(cve3);
            Assert.IsNotNull(cve4);
            Assert.IsNotNull(cve5);
            Assert.IsTrue(cve1.Equals(cve2));
            Assert.IsTrue(cve1.Equals(cve3));
            Assert.IsTrue(cve1.Equals(cve4));
            Assert.IsTrue(cve1.Equals(cve5));
            Assert.IsNull(cve1.Comparer);
            Assert.AreEqual(cve1.Extractors.Length, 2);

            Score score = new Score(1, 1, 126, 10000L, 1.24f, 1432.55, new decimal(11223344), new RawInt128(new byte[] { 1 }), 1);

            Assert.AreEqual(cve1.Extract(score), score.DoubleValue - Convert.ToDouble(score.IntValue));
            cve1 = new ComparisonValueExtractor(exByte, exShort);
            Assert.AreEqual(cve1.Extract(score), Convert.ToInt32(score.ByteValue) - Convert.ToInt32(score.ShortValue));
            cve1 = new ComparisonValueExtractor(exLong, exInt);
            Assert.AreEqual(cve1.Extract(score), score.LongValue - Convert.ToInt64(score.IntValue));
            cve1 = new ComparisonValueExtractor(exLong, exFloat);
            Assert.AreEqual(cve1.Extract(score), Convert.ToDouble(score.LongValue) - Convert.ToDouble(score.FloatValue));
            cve1 = new ComparisonValueExtractor(exDecimal, exDouble);
            Assert.AreEqual(cve1.Extract(score), Decimal.Subtract(score.DecimalValue, Convert.ToDecimal(score.DoubleValue)));

            ComparisonValueExtractor cve6 = new ComparisonValueExtractor("ShortValue", "ShortValue", Comparer.Default);

            Assert.AreEqual(cve6.Extract(score),
                            SafeComparer.CompareSafe(Comparer.Default, score.ShortValue, score.ShortValue));
        }