Search in sources :

Example 1 with PdxInstanceFactory

use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.

the class PdxInstanceSortedHelper method createPdxInstance.

private PdxInstance createPdxInstance() {
    Collections.sort(fieldList);
    PdxInstanceFactory factory = createPdxInstanceFactory();
    for (JSONFieldHolder<?> f : fieldList) {
        filldata(factory, f);
    }
    return factory.create();
}
Also used : PdxInstanceFactory(org.apache.geode.pdx.PdxInstanceFactory)

Example 2 with PdxInstanceFactory

use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.

the class PdxStringQueryJUnitTest method testQueriesWithRangeIndex.

@Test
public void testQueriesWithRangeIndex() throws Exception {
    Index index = qs.createIndex("index2", "p.secId", "/exampleRegion p, p.positions.values");
    assertTrue(index instanceof RangeIndex);
    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 111);
    pf.writeString("secId", "IBM");
    pf.writeString("status", "active");
    HashMap positions = new HashMap();
    positions.put("price", "50");
    positions.put("price", "60");
    pf.writeObject("positions", positions);
    PdxInstance pi = pf.create();
    r.put("IBM", pi);
    positions = new HashMap();
    positions.put("price", "100");
    positions.put("price", "120");
    r.put("YHOO", new TestObject(222, "YHOO", positions, "inactive"));
    pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 333);
    pf.writeString("secId", "GOOGL");
    pf.writeString("status", "active");
    positions = new HashMap();
    positions.put("price", "130");
    positions.put("price", "150");
    pf.writeObject("positions", positions);
    pi = pf.create();
    positions = new HashMap();
    positions.put("price", "200");
    positions.put("price", "220");
    r.put("VMW", new TestObject(111, "VMW", positions, "inactive"));
    r.put("GOOGL", pi);
    Map map = ((RangeIndex) index).getValueToEntriesMap();
    for (Object key : map.keySet()) {
        assertTrue(key instanceof PdxString);
    }
    executeQueriesValidateResults(INDEX_TYPE_RANGE);
    qs.removeIndex(index);
    r.clear();
}
Also used : PdxInstanceFactory(org.apache.geode.pdx.PdxInstanceFactory) PdxInstance(org.apache.geode.pdx.PdxInstance) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) PrimaryKeyIndex(org.apache.geode.cache.query.internal.index.PrimaryKeyIndex) PdxString(org.apache.geode.pdx.internal.PdxString) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with PdxInstanceFactory

use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.

the class PdxStringQueryJUnitTest method putPdxInstances.

public void putPdxInstances() throws Exception {
    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 111);
    pf.writeString("status", "active");
    pf.writeString("secId", "IBM");
    PdxInstance pi = pf.create();
    r.put("IBM", pi);
    pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 222);
    pf.writeString("status", "inactive");
    pf.writeString("secId", "YHOO");
    pi = pf.create();
    r.put("YHOO", pi);
    pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 333);
    pf.writeString("status", "active");
    pf.writeString("secId", "GOOGL");
    pi = pf.create();
    r.put("GOOGL", pi);
    pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 111);
    pf.writeString("status", "inactive");
    pf.writeString("secId", "VMW");
    pi = pf.create();
    r.put("VMW", pi);
}
Also used : PdxInstanceFactory(org.apache.geode.pdx.PdxInstanceFactory) PdxInstance(org.apache.geode.pdx.PdxInstance)

Example 4 with PdxInstanceFactory

use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.

the class PdxStringQueryJUnitTest method putHeterogeneousObjects.

public void putHeterogeneousObjects() throws Exception {
    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 111);
    pf.writeString("secId", "IBM");
    pf.writeString("status", "active");
    PdxInstance pi = pf.create();
    r.put("IBM", pi);
    r.put("YHOO", new TestObject(222, "YHOO", "inactive"));
    r.put("GOOGL", new TestObject(333, "GOOGL", "active"));
    pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 111);
    pf.writeString("secId", "VMW");
    pf.writeString("status", "inactive");
    pi = pf.create();
    r.put("VMW", pi);
}
Also used : PdxInstanceFactory(org.apache.geode.pdx.PdxInstanceFactory) PdxInstance(org.apache.geode.pdx.PdxInstance)

Example 5 with PdxInstanceFactory

use of org.apache.geode.pdx.PdxInstanceFactory in project geode by apache.

the class PdxQueryDUnitTest method testLocalMapInPeerTypePdxRegistry.

/**
   * In PeerTypeRegistration when a PdxType is updated, a local map of class => PdxTypes is
   * populated. This map is used to search a field for a class in different versions (PdxTypes) This
   * test verifies that the map is being updated by the cacheListener
   *
   * @throws CacheException
   */
@Test
public void testLocalMapInPeerTypePdxRegistry() throws CacheException {
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    final VM vm3 = host.getVM(3);
    final int numberOfEntries = 10;
    final String name = "/" + regionName;
    final String[] qs = { "select * from " + name + " where pdxStatus = 'active'", "select pdxStatus from " + name + " where id > 4" };
    // Start server1
    final int port1 = (Integer) vm0.invoke(new SerializableCallable("Create Server1") {

        @Override
        public Object call() throws Exception {
            Region r1 = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            CacheServer server = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
            server.setPort(port);
            server.start();
            return port;
        }
    });
    // Start server2
    final int port2 = (Integer) vm1.invoke(new SerializableCallable("Create Server2") {

        @Override
        public Object call() throws Exception {
            Region r1 = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            CacheServer server = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
            server.setPort(port);
            server.start();
            return port;
        }
    });
    // client1 loads version 1 objects on server1
    vm2.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm0.getHost()), port1);
            ClientCache cache = getClientCache(cf);
            Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionName);
            // Load version 1 objects
            for (int i = 0; i < numberOfEntries; i++) {
                PdxInstanceFactory pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("PdxVersionedNewPortfolio", false);
                pdxInstanceFactory.writeInt("id", i);
                pdxInstanceFactory.writeString("pdxStatus", (i % 2 == 0 ? "active" : "inactive"));
                PdxInstance pdxInstance = pdxInstanceFactory.create();
                region.put("key-" + i, pdxInstance);
            }
            return null;
        }
    });
    // client 2 loads version 2 objects on server2
    vm3.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm1.getHost()), port2);
            ClientCache cache = getClientCache(cf);
            Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionName);
            // Load version 2 objects
            for (int i = numberOfEntries; i < numberOfEntries * 2; i++) {
                PdxInstanceFactory pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("PdxVersionedNewPortfolio", false);
                pdxInstanceFactory.writeInt("id", i);
                pdxInstanceFactory.writeString("status", (i % 2 == 0 ? "active" : "inactive"));
                PdxInstance pdxInstance = pdxInstanceFactory.create();
                region.put("key-" + i, pdxInstance);
            }
            return null;
        }
    });
    // on server 1 verify local map in PeerTypeRegistration has fields
    vm0.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            TypeRegistration registration = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.").getPdxRegistry().getTypeRegistration();
            Assert.assertTrue(registration instanceof PeerTypeRegistration);
            Map<String, Set<PdxType>> m = ((PeerTypeRegistration) registration).getClassToType();
            assertEquals(1, m.size());
            assertEquals("PdxVersionedNewPortfolio", m.keySet().iterator().next());
            assertEquals(2, m.values().iterator().next().size());
            for (PdxType p : m.values().iterator().next()) {
                assertEquals("PdxVersionedNewPortfolio", p.getClassName());
            }
            return null;
        }
    });
    // on server 2 verify local map in PeerTypeRegistration has fields
    vm1.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            TypeRegistration registration = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.").getPdxRegistry().getTypeRegistration();
            Assert.assertTrue(registration instanceof PeerTypeRegistration);
            Map<String, Set<PdxType>> m = ((PeerTypeRegistration) registration).getClassToType();
            assertEquals(1, m.size());
            assertEquals("PdxVersionedNewPortfolio", m.keySet().iterator().next());
            assertEquals(2, m.values().iterator().next().size());
            for (PdxType p : m.values().iterator().next()) {
                assertEquals("PdxVersionedNewPortfolio", p.getClassName());
            }
            return null;
        }
    });
    Invoke.invokeInEveryVM(DistributedTestCase.class, "disconnectFromDS");
}
Also used : PdxInstanceFactory(org.apache.geode.pdx.PdxInstanceFactory) PdxType(org.apache.geode.pdx.internal.PdxType) PeerTypeRegistration(org.apache.geode.pdx.internal.PeerTypeRegistration) ClientTypeRegistration(org.apache.geode.pdx.internal.ClientTypeRegistration) TypeRegistration(org.apache.geode.pdx.internal.TypeRegistration) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) PeerTypeRegistration(org.apache.geode.pdx.internal.PeerTypeRegistration) CacheException(org.apache.geode.cache.CacheException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) PdxInstance(org.apache.geode.pdx.PdxInstance) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) Map(java.util.Map) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

PdxInstanceFactory (org.apache.geode.pdx.PdxInstanceFactory)23 PdxInstance (org.apache.geode.pdx.PdxInstance)22 Test (org.junit.Test)18 Region (org.apache.geode.cache.Region)13 Host (org.apache.geode.test.dunit.Host)12 VM (org.apache.geode.test.dunit.VM)12 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 CacheException (org.apache.geode.cache.CacheException)11 QueryService (org.apache.geode.cache.query.QueryService)11 SelectResults (org.apache.geode.cache.query.SelectResults)11 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)8 ClientCache (org.apache.geode.cache.client.ClientCache)7 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)7 CacheServer (org.apache.geode.cache.server.CacheServer)7 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)6 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)6 Query (org.apache.geode.cache.query.Query)4 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)4 PdxString (org.apache.geode.pdx.internal.PdxString)4 Cache (org.apache.geode.cache.Cache)3