コード例 #1
0
        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();
        }
コード例 #2
0
        /// <summary>
        /// Compare the KeyExtractor with another object to determine
        /// equality.
        /// </summary>
        /// <remarks>
        /// Two KeyExtractor objects are considered equal if their underlying
        /// <b>IValueExtractors</b> are equal.
        /// </remarks>
        /// <param name="o">
        /// The reference object with which to compare.
        /// </param>
        /// <returns>
        /// <b>true</b> if this KeyExtractor and the passed object are
        /// equivalent.
        /// </returns>
        public override bool Equals(object o)
        {
            if (o is KeyExtractor)
            {
                KeyExtractor target = (KeyExtractor)o;
                return(Equals(m_extractor, target.m_extractor));
            }

            return(false);
        }
コード例 #3
0
        public void TestChainedExtractor()
        {
            IValueExtractor extractor = new ChainedExtractor("InnerMember.field");

            IValueExtractor re1 = new ReflectionExtractor("InnerMember");
            IValueExtractor re2 = new ReflectionExtractor("field");

            IValueExtractor[] res = { re1, re2 };

            IValueExtractor extractor1 = new ChainedExtractor(re1, re2);
            IValueExtractor extractor2 = new ChainedExtractor(res);

            Assert.IsNotNull(extractor);
            Assert.IsNotNull(extractor1);
            Assert.IsNotNull(extractor2);
            Assert.AreEqual(extractor, extractor1);
            Assert.AreEqual(extractor1, extractor2);
            Assert.AreEqual(extractor.ToString(), extractor1.ToString());
            Assert.AreEqual(extractor.GetHashCode(), extractor1.GetHashCode());

            IValueExtractor[] extractors = (extractor as ChainedExtractor).Extractors;
            Assert.IsNotNull(extractors);
            Assert.AreEqual(extractors.Length, 2);
            Assert.AreEqual(extractors[0], re1);
            Assert.AreEqual(extractors[1], re2);

            ReflectionTestType o = new ReflectionTestType();

            Assert.AreEqual(extractor.Extract(o), o.InnerMember.field);
            Assert.AreEqual(extractor.Extract(o), extractors[1].Extract(extractors[0].Extract(o)));
            Assert.IsNull(extractor.Extract(null));

            // testing on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Address a1 = new Address("street1", "city1", "state1", "zip1");
            Address a2 = new Address("street2", "city2", "state2", "zip2");
            Address a3 = new Address("street3", "city1", "state3", "zip3");

            Hashtable ht = new Hashtable();

            ht.Add(a1, "chainedExtractorValue1");
            ht.Add(a2, "chainedExtractorValue2");
            ht.Add(a3, "chainedExtractorValue3");
            cache.InsertAll(ht);

            extractor1 = new KeyExtractor(IdentityExtractor.Instance);
            extractor2 = new KeyExtractor(new ReflectionExtractor("getCity"));
            extractor  = new KeyExtractor(new ChainedExtractor(extractor1, extractor2));

            IFilter     filter = new EqualsFilter(extractor, "city1");
            ICollection keys   = cache.GetKeys(filter);
            ArrayList   list   = new ArrayList(keys);

            Assert.AreEqual(keys.Count, 2);
            Assert.AreEqual(((Address)list[0]).City, "city1");
            Assert.AreEqual(((Address)list[1]).City, "city1");

            CacheFactory.Shutdown();
        }
コード例 #4
0
        public void TestKeyExtractor()
        {
            IValueExtractor extractor  = new KeyExtractor((IValueExtractor)null);
            IValueExtractor extractor1 = new KeyExtractor((IValueExtractor)null);
            IValueExtractor extractor2 = IdentityExtractor.Instance;

            Assert.IsNotNull(extractor);
            Assert.AreEqual(extractor, extractor1);
            Assert.AreNotEqual(extractor, extractor2);
            Assert.AreEqual(extractor.ToString(), extractor1.ToString());
            Assert.AreEqual(extractor.GetHashCode(), extractor1.GetHashCode());

            extractor = new KeyExtractor(IdentityExtractor.Instance);
            Assert.IsNotNull(extractor);
            IValueExtractor innerExtractor = (extractor as KeyExtractor).Extractor;

            Assert.IsNotNull(innerExtractor);
            Assert.IsInstanceOf(typeof(IdentityExtractor), innerExtractor);

            object o = "value";

            Assert.AreEqual(o, extractor.Extract(o));

            extractor = new KeyExtractor("field");
            Assert.IsNotNull(extractor);
            innerExtractor = (extractor as KeyExtractor).Extractor;
            Assert.IsNotNull(innerExtractor);
            Assert.IsInstanceOf(typeof(ReflectionExtractor), innerExtractor);
            ReflectionExtractor re = innerExtractor as ReflectionExtractor;

            Assert.AreEqual(re.MemberName, "field");

            o = new ReflectionTestType();
            Assert.AreEqual(extractor.Extract(o), (o as ReflectionTestType).field);

            extractor = new KeyExtractor("InnerMember.field");
            Assert.IsNotNull(extractor);
            innerExtractor = (extractor as KeyExtractor).Extractor;
            Assert.IsNotNull(innerExtractor);
            Assert.IsInstanceOf(typeof(ChainedExtractor), innerExtractor);
            ChainedExtractor ce = innerExtractor as ChainedExtractor;

            Assert.IsNotNull(ce.Extractors);
            Assert.AreEqual(ce.Extractors.Length, 2);
            Assert.AreEqual(extractor.Extract(o), (o as ReflectionTestType).InnerMember.field);

            // testing on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("identityExtractorKey1", 435);
            ht.Add("identityExtractorKey2", 253);
            ht.Add("identityExtractorKey3", 3);
            ht.Add("identityExtractorKey4", null);
            ht.Add("identityExtractorKey5", -3);
            cache.InsertAll(ht);

            extractor = new KeyExtractor(IdentityExtractor.Instance);
            IFilter     filter = new EqualsFilter(extractor, "identityExtractorKey3");
            ICollection keys   = cache.GetKeys(filter);

            Assert.Contains("identityExtractorKey3", (IList)keys);
            Assert.AreEqual(keys.Count, 1);

            CacheFactory.Shutdown();
        }