Search in sources :

Example 51 with PortfolioPdx

use of org.apache.geode.cache.query.data.PortfolioPdx in project geode by apache.

the class PutAllWithIndexPerfDUnitTest method testPutAllWithIndexes.

@Ignore("TODO: test is disabled")
@Test
public void testPutAllWithIndexes() {
    final String name = "testRegion";
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final int numberOfEntries = 10000;
    // Start server
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.put(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
            Cache cache = new CacheFactory(config).create();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            cache.createRegionFactory(factory.create()).create(name);
            try {
                startBridgeServer(0, false);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            // Create Index on empty region
            try {
                cache.getQueryService().createIndex("idIndex", "ID", "/" + name);
            } catch (Exception e) {
                Assert.fail("index creation failed", e);
            }
        }
    });
    // Create client region
    final int port = vm0.invoke(() -> PutAllWithIndexPerfDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    vm1.invoke(new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            ClientCache cache = new ClientCacheFactory().addPoolServer(host0, port).create();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(name);
        }
    });
    vm1.invoke(new CacheSerializableRunnable("putAll() test") {

        @Override
        public void run2() throws CacheException {
            Region exampleRegion = ClientCacheFactory.getAnyInstance().getRegion(name);
            Map warmupMap = new HashMap();
            Map data = new HashMap();
            for (int i = 0; i < 10000; i++) {
                Object p = new PortfolioPdx(i);
                if (i < 1000)
                    warmupMap.put(i, p);
                data.put(i, p);
            }
            for (int i = 0; i < 10; i++) {
                exampleRegion.putAll(warmupMap);
            }
            long start = System.currentTimeMillis();
            for (int i = 0; i < 10; i++) {
                exampleRegion.putAll(data);
            }
            long end = System.currentTimeMillis();
            timeWithoutStructTypeIndex = ((end - start) / 10);
            System.out.println("Total putall time for 10000 objects is: " + ((end - start) / 10) + "ms");
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Remove Index and create new one") {

        @Override
        public void run2() throws CacheException {
            try {
                Cache cache = CacheFactory.getAnyInstance();
                cache.getQueryService().removeIndexes();
                cache.getRegion(name).clear();
                cache.getQueryService().createIndex("idIndex", "p.ID", "/" + name + " p");
            } catch (Exception e) {
                Assert.fail("index creation failed", e);
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("putAll() test") {

        @Override
        public void run2() throws CacheException {
            Region exampleRegion = ClientCacheFactory.getAnyInstance().getRegion(name);
            exampleRegion.clear();
            Map warmupMap = new HashMap();
            Map data = new HashMap();
            for (int i = 0; i < 10000; i++) {
                Object p = new PortfolioPdx(i);
                if (i < 1000)
                    warmupMap.put(i, p);
                data.put(i, p);
            }
            for (int i = 0; i < 10; i++) {
                exampleRegion.putAll(warmupMap);
            }
            long start = System.currentTimeMillis();
            for (int i = 0; i < 10; i++) {
                exampleRegion.putAll(data);
            }
            long end = System.currentTimeMillis();
            timeWithStructTypeIndex = ((end - start) / 10);
            System.out.println("Total putall time for 10000 objects is: " + ((end - start) / 10) + "ms");
        }
    });
    if (timeWithoutStructTypeIndex > timeWithStructTypeIndex) {
        fail("putAll took more time without struct type index than simple index");
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) HashMap(java.util.HashMap) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) HashMap(java.util.HashMap) Map(java.util.Map) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)51 Region (org.apache.geode.cache.Region)50 Test (org.junit.Test)50 QueryService (org.apache.geode.cache.query.QueryService)47 SelectResults (org.apache.geode.cache.query.SelectResults)46 Query (org.apache.geode.cache.query.Query)34 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)28 VM (org.apache.geode.test.dunit.VM)27 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)26 Host (org.apache.geode.test.dunit.Host)26 CacheException (org.apache.geode.cache.CacheException)19 Struct (org.apache.geode.cache.query.Struct)17 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)14 AttributesFactory (org.apache.geode.cache.AttributesFactory)13 ClientCache (org.apache.geode.cache.client.ClientCache)13 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)13 CompiledSelect (org.apache.geode.cache.query.internal.CompiledSelect)13 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)13 Iterator (java.util.Iterator)12 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)12