Search in sources :

Example 41 with PortfolioData

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

the class PRBasicIndexCreationDUnitTest method testPartitionedIndexCreationDuringPersistentRecovery.

/**
   * Test index usage with query on a partitioned region with bucket indexes.
   * 
   * @throws Throwable
   */
@Test
public void testPartitionedIndexCreationDuringPersistentRecovery() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    setCacheInVMs(vm0, vm1);
    int redundancy = 1;
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest.testPartitionedIndexCreationDuringPersistentRecovery started ");
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPersistentPRCreate(name, redundancy, PortfolioData.class));
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPersistentPRCreate(name, redundancy, PortfolioData.class));
    final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    // Restart a single member
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForCloseCache());
    setCacheInVMs(vm0);
    AsyncInvocation regionCreateFuture = vm0.invokeAsync(PRQHelp.getCacheSerializableRunnableForPersistentPRCreate(name, redundancy, PortfolioData.class));
    // Ok, I want to do this in parallel
    AsyncInvocation indexCreateFuture = vm1.invokeAsync(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnId", "p.ID", null, "p"));
    regionCreateFuture.getResult(20 * 1000);
    indexCreateFuture.getResult(20 * 1000);
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForLocalRegionCreation(localName, PortfolioData.class));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(localName, portfolio, cnt, cntDest));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRQueryAndCompareResults(name, localName));
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest.testPartitionedIndexCreationDuringPersistentRecovery done ");
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) PortfolioData(org.apache.geode.cache.query.data.PortfolioData) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 42 with PortfolioData

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

the class PRBasicMultiIndexCreationDUnitTest method testCreatePartitionedRegionThroughXMLAndAPI.

/**
   * Test creation of multiple index on partitioned regions and then adding a new node to the system
   * and checking it has created all the indexes already in the system.
   * 
   */
@Test
public void testCreatePartitionedRegionThroughXMLAndAPI() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    setCacheInVMs(vm0, vm1, vm2, vm3);
    // final String fileName = "PRIndexCreation.xml";
    // vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name,
    // fileName));
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest.testCreatePartitionedRegionThroughXMLAndAPI started ");
    // creating all the prs
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    ArrayList<String> names = new ArrayList<String>();
    names.add("PrIndexOnStatus");
    names.add("PrIndexOnID");
    names.add("PrIndexOnPKID");
    ArrayList<String> exps = new ArrayList<String>();
    exps.add("status");
    exps.add("ID");
    exps.add("pkid");
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForDefineIndex(name, names, exps));
    // adding a new node to an already existing system.
    vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    // putting some data in.
    final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
    // Putting the data into the PR's created
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
    vm2.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
}
Also used : VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) PortfolioData(org.apache.geode.cache.query.data.PortfolioData) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 43 with PortfolioData

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

the class PRBasicMultiIndexCreationDUnitTest method testCreatePartitionedIndexWithNoAliasBeforePuts.

/**
   * Test to see if index creation works with index creation like in serialQueryEntry.conf hydra
   * test before putting the data in the partitioned region.
   */
@Test
public void testCreatePartitionedIndexWithNoAliasBeforePuts() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm3 = host.getVM(3);
    setCacheInVMs(vm0, vm1, vm3);
    // final String fileName = "PRIndexCreation.xml";
    // vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name,
    // fileName));
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest.testCreatePartitionedIndexWithNoAliasAfterPuts started ");
    // creating all the prs
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    ArrayList<String> names = new ArrayList<String>();
    names.add("PrIndexOnStatus");
    names.add("PrIndexOnID");
    names.add("PrIndexOnPKID");
    ArrayList<String> exps = new ArrayList<String>();
    exps.add("status");
    exps.add("ID");
    exps.add("pkid");
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForDefineIndex(name, names, exps));
    // putting some data in.
    final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
    // Putting the data into the PR's created
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
    // vm2.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
}
Also used : VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) PortfolioData(org.apache.geode.cache.query.data.PortfolioData) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 44 with PortfolioData

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

the class PRBasicMultiIndexCreationDUnitTest method testPRBasicIndexCreate.

/**
   * Tests basic index creation on a partitioned system.
   * 
   * @throws Exception if an exception is generated
   */
@Test
public void testPRBasicIndexCreate() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    setCacheInVMs(vm0, vm1, vm2, vm3);
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest.testPRBasicIndexCreate started ....");
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRAccessorCreate(name, redundancy, PortfolioData.class));
    // Creating local region on vm0 to compare the results of query.
    // vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(localName,
    // Scope.DISTRIBUTED_ACK, redundancy));
    // Creating the Datastores Nodes in the VM1.
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest : creating all the prs ");
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
    // Putting the data into the PR's created
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    ArrayList<String> names = new ArrayList<String>();
    names.add("PrIndexOnStatus");
    names.add("PrIndexOnID");
    ArrayList<String> exps = new ArrayList<String>();
    exps.add("status");
    exps.add("ID");
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForDefineIndex(name, names, exps));
    // creating a duplicate index, should throw a IndexExistsException and if not
    // will throw a RuntimeException.
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForDuplicatePRIndexCreate(name, "PrIndexOnStatus", "p.status", null, "p"));
    vm2.invoke(PRQHelp.getCacheSerializableRunnableForDuplicatePRIndexCreate(name, "PrIndexOnStatus", "p.status", null, "p"));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForDuplicatePRIndexCreate(name, "PrIndexOnStatus", "p.status", null, "p"));
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest.testPRBasicIndexCreate is done ");
}
Also used : VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) PortfolioData(org.apache.geode.cache.query.data.PortfolioData) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 45 with PortfolioData

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

the class PRBasicMultiIndexCreationDUnitTest method testPRMultiIndexCreationAndGetIndex.

/*
   * Tests creation of multiple index creation on a partitioned region system and test
   * QueryService.getIndex(Region, indexName) API.
   *
   * @throws Exception if any exception are generated
   */
@Test
public void testPRMultiIndexCreationAndGetIndex() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    setCacheInVMs(vm0, vm1, vm2, vm3);
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreation.testPRMultiIndexCreation Test Started");
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRAccessorCreate(name, redundancy, PortfolioData.class));
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
    final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
    // Putting the data into the PR's created
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    ArrayList<String> names = new ArrayList<String>();
    names.add("PrIndexOnStatus");
    names.add("PrIndexOnID");
    ArrayList<String> exps = new ArrayList<String>();
    exps.add("status");
    exps.add("ID");
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForDefineIndex(name, names, exps));
    // Check all QueryService.getIndex APIS for a region.
    SerializableRunnable getIndexCheck = new CacheSerializableRunnable("Get Index Check") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Check for ID index
            Index idIndex = cache.getQueryService().getIndex(cache.getRegion(name), "PrIndexOnID");
            assertNotNull(idIndex);
            assertEquals("PrIndexOnID", idIndex.getName());
            assertEquals("ID", idIndex.getIndexedExpression());
            assertEquals("/" + name, idIndex.getFromClause());
            assertNotNull(idIndex.getStatistics());
            // Check for status index
            Index statusIndex = cache.getQueryService().getIndex(cache.getRegion(name), "PrIndexOnStatus");
            assertNotNull(statusIndex);
            assertEquals("PrIndexOnStatus", statusIndex.getName());
            assertEquals("status", statusIndex.getIndexedExpression());
            assertEquals("/" + name, statusIndex.getFromClause());
            assertNotNull(statusIndex.getStatistics());
            // Check for all Indexes on the region.
            Collection<Index> indexes = cache.getQueryService().getIndexes(cache.getRegion(name));
            for (Index ind : indexes) {
                assertNotNull(ind);
                assertNotNull(ind.getName());
                assertNotNull(ind.getIndexedExpression());
                assertNotNull(ind.getFromClause());
                assertNotNull(ind.getStatistics());
            }
        }
    };
    // Check getIndex() on accessor
    vm0.invoke(getIndexCheck);
    // Check getIndex() on datastore
    vm1.invoke(getIndexCheck);
    vm2.invoke(getIndexCheck);
    vm3.invoke(getIndexCheck);
    LogWriterUtils.getLogWriter().info("PRQBasicIndexCreationTest.testPRMultiIndexCreation ENDED");
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) PortfolioData(org.apache.geode.cache.query.data.PortfolioData) Index(org.apache.geode.cache.query.Index) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

PortfolioData (org.apache.geode.cache.query.data.PortfolioData)57 Test (org.junit.Test)57 Host (org.apache.geode.test.dunit.Host)52 VM (org.apache.geode.test.dunit.VM)52 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)52 Cache (org.apache.geode.cache.Cache)18 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)18 Region (org.apache.geode.cache.Region)17 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)17 CacheException (org.apache.geode.cache.CacheException)16 SelectResults (org.apache.geode.cache.query.SelectResults)14 Index (org.apache.geode.cache.query.Index)13 Query (org.apache.geode.cache.query.Query)12 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)12 ArrayList (java.util.ArrayList)11 AttributesFactory (org.apache.geode.cache.AttributesFactory)11 RegionFactory (org.apache.geode.cache.RegionFactory)11 LinkedList (java.util.LinkedList)9 List (java.util.List)9 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)9