public void TestPofExtractorWithFilter()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();
            for (int i = 1901; i <= 2000; i++)
            {
                PortablePersonLite customer = new PortablePersonLite();
                customer.Name = "Name" + i;
                customer.DOB  = new DateTime(i, 1, 1);
                cache.Insert(i, customer);
            }
            DateTime        criteria  = new DateTime(1970, 1, 1);
            IValueExtractor extractor = new PofExtractor(null, 2);
            IFilter         filter2   = new LessEqualsFilter(extractor, criteria);

            Assert.AreEqual(cache.GetEntries(filter2).Length, 70,
                            "Expected: 70; Result was: " + cache.GetEntries(filter2).Length);
            CacheFactory.Shutdown();
        }
        public void TestSerialization()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(1, typeof(PortablePerson), new PortableObjectSerializer(1));
            ctx.RegisterUserType(2, typeof(Address), new PortableObjectSerializer(2));

            PortablePerson aleks  = new PortablePerson("Aleksandar Seovic", new DateTime(1974, 8, 24));
            PortablePerson marija = new PortablePerson("Marija Seovic", new DateTime(1978, 2, 20));
            PortablePerson ana    = new PortablePerson("Ana Maria Seovic", new DateTime(2004, 8, 14, 7, 43, 0));

            aleks.Spouse   = marija;
            aleks.Address  = marija.Address = ana.Address = new Address("208 Myrtle Ridge Rd", "Lutz", "FL", "33549");
            aleks.Children = marija.Children = new PortablePerson[] { ana };

            Stream stream = new MemoryStream();

            ctx.Serialize(new DataWriter(stream), aleks);

            stream.Position = 0;
            PortablePerson aleks2 = (PortablePerson)ctx.Deserialize(new DataReader(stream));

            Assert.AreEqual(aleks.Name, aleks2.Name);
            Assert.AreEqual(aleks.DOB, aleks2.DOB);
            Assert.AreEqual(aleks.Spouse.Name, aleks2.Spouse.Name);
            Assert.AreEqual(aleks.Address.City, aleks2.Address.City);
            Assert.AreEqual(1, aleks2.Children.Length);
            Assert.AreEqual(ana.Name, aleks2.Children[0].Name);
            Assert.AreEqual(ana.Address.Street, aleks2.Children[0].Address.Street);

            SimplePofContext liteCtx = new SimplePofContext();

            liteCtx.RegisterUserType(1, typeof(PortablePersonLite), new PortableObjectSerializer(1));
            liteCtx.RegisterUserType(2, typeof(Address), new PortableObjectSerializer(2));

            stream.Position = 0;
            PortablePersonLite aleks3 = (PortablePersonLite)liteCtx.Deserialize(new DataReader(stream));

            Assert.AreEqual(aleks.Name, aleks3.Name);
            Assert.AreEqual(aleks.DOB, aleks3.DOB);
        }
Exemplo n.º 3
0
        public void TestConfigWithDefaultSerializer()
        {
            ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config-defaultserializer.xml");

            Assert.IsNotNull(ctx);

            IXmlElement config = ctx.Config;

            Assert.IsNotNull(config);

            // uses default serializer
            Address address         = new Address();
            string  addressTypeName = "Tangosol.Address";
            Type    addressType     = typeof(Address);

            int typeId = ctx.GetUserTypeIdentifier(addressType);

            Assert.AreEqual(typeId, 1201);
            string typeName = ctx.GetTypeName(typeId);

            Assert.AreEqual(typeName, addressTypeName);
            Type type = ctx.GetType(typeId);

            Assert.AreEqual(type, addressType);
            IPofSerializer serializer = ctx.GetPofSerializer(typeId);

            Assert.IsInstanceOf(typeof(DummyDefaultPofSerializer), serializer);
            Assert.IsTrue(ctx.IsUserType(address));

            // has its own serializer so default won't be used
            PortablePersonLite portablePersonLite         = new PortablePersonLite();
            string             portablePersonLiteTypeName = "Tangosol.PortablePersonLite";
            Type portablePersonLiteType = typeof(PortablePersonLite);

            typeId = ctx.GetUserTypeIdentifier(portablePersonLiteType);
            Assert.AreEqual(typeId, 1002);
            typeName = ctx.GetTypeName(typeId);
            Assert.AreEqual(typeName, portablePersonLiteTypeName);
            type = ctx.GetType(typeId);
            Assert.AreEqual(type, portablePersonLiteType);
            serializer = ctx.GetPofSerializer(typeId);
            Assert.IsInstanceOf(typeof(XmlPofSerializer), serializer);
            Assert.IsTrue(ctx.IsUserType(portablePersonLite));

            // is defined in included file with it's own default serializer
            // different from previous
            PortablePerson portablePerson         = new PortablePerson();
            string         portablePersonTypeName = "Tangosol.PortablePerson";
            Type           portablePersonType     = typeof(PortablePerson);

            typeId = ctx.GetUserTypeIdentifier(portablePersonType);
            Assert.AreEqual(typeId, 1005);
            typeName = ctx.GetTypeName(typeId);
            Assert.AreEqual(typeName, portablePersonTypeName);
            type = ctx.GetType(typeId);
            Assert.AreEqual(type, portablePersonType);
            serializer = ctx.GetPofSerializer(typeId);
            Assert.IsInstanceOf(typeof(BinaryPofSerializer), serializer);
            Assert.IsTrue(ctx.IsUserType(portablePerson));

            // does not have serializer defined and default is not specified
            // in the config, therefore will use PortableObjectSerializer
            serializer = ctx.GetPofSerializer(14); //UUID
            Assert.IsInstanceOf(typeof(PortableObjectSerializer), serializer);
        }