| /*========================================================================= |
| * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. |
| * This product is protected by U.S. and international copyright |
| * and intellectual property laws. Pivotal products are covered by |
| * one or more patents listed at http://www.pivotal.io/patents. |
| *========================================================================= |
| */ |
| package com.gemstone.gemfire.cache.query.dunit; |
| |
| import java.util.Properties; |
| |
| import com.gemstone.gemfire.cache.CacheException; |
| import com.gemstone.gemfire.cache.query.QueryTestUtils; |
| import com.gemstone.gemfire.cache30.CacheSerializableRunnable; |
| |
| import dunit.DistributedTestCase; |
| import dunit.Host; |
| import dunit.SerializableRunnable; |
| import dunit.VM; |
| |
| public class HashIndexDUnitTest extends DistributedTestCase{ |
| |
| QueryTestUtils utils; |
| VM vm0; |
| |
| public HashIndexDUnitTest(String name) { |
| super(name); |
| } |
| |
| public void setUp() throws Exception { |
| super.setUp(); |
| getSystem(); |
| invokeInEveryVM(new SerializableRunnable("getSystem") { |
| public void run() { |
| getSystem(); |
| } |
| }); |
| Host host = Host.getHost(0); |
| vm0 = host.getVM(0); |
| utils = new QueryTestUtils(); |
| utils.createServer(vm0, getAllDistributedSystemProperties(new Properties())); |
| utils.createReplicateRegion("exampleRegion", vm0); |
| utils.createHashIndex(vm0,"ID", "r.ID", "/exampleRegion r"); |
| } |
| |
| |
| public void testHashIndexForIndexElemArray() throws Exception{ |
| doPut(200);// around 66 entries for a key in the index (< 100 so does not create a ConcurrentHashSet) |
| doQuery(); |
| doUpdate(200); |
| doQuery(); |
| doDestroy(200); |
| doQuery(); |
| Thread.sleep(5000); |
| } |
| |
| public void testHashIndexForConcurrentHashSet() throws Exception{ |
| doPut(333); //111 entries for a key in the index (> 100 so creates a ConcurrentHashSet) |
| doQuery(); |
| doUpdate(333); |
| doQuery(); |
| doDestroy(200); |
| doQuery(); |
| } |
| |
| public void doPut(final int entries) { |
| vm0.invokeAsync(new CacheSerializableRunnable("Putting values") { |
| public void run2() { |
| utils.createValuesStringKeys("exampleRegion", entries); |
| } |
| }); |
| } |
| |
| public void doUpdate(final int entries) { |
| vm0.invokeAsync(new CacheSerializableRunnable("Updating values") { |
| public void run2() { |
| utils.createDiffValuesStringKeys("exampleRegion", entries); |
| } |
| }); |
| } |
| |
| |
| public void doQuery() throws Exception{ |
| final String[] qarr = {"173", "174", "176", "180"}; |
| vm0.invokeAsync(new CacheSerializableRunnable("Executing query") { |
| public void run2() throws CacheException { |
| try { |
| for (int i = 0; i < 50; i++) { |
| utils.executeQueries(qarr); |
| } |
| } |
| catch (Exception e) { |
| throw new CacheException(e){}; |
| } |
| } |
| }); |
| } |
| |
| public void doDestroy(final int entries) { |
| vm0.invokeAsync(new CacheSerializableRunnable("Destroying values") { |
| public void run2() throws CacheException { |
| try { |
| Thread.sleep(500); |
| } catch (InterruptedException e) { |
| e.printStackTrace(); |
| } |
| try { |
| utils.destroyRegion("exampleRegion", entries); |
| } |
| catch (Exception e) { |
| throw new CacheException(e){}; |
| } |
| } |
| }); |
| } |
| |
| public void tearDown2() throws Exception{ |
| Thread.sleep(5000); |
| utils.closeServer(vm0); |
| } |
| |
| } |