Search in sources :

Example 46 with PortfolioData

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

the class PRBasicIndexCreationDUnitTest 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));
    // should create a sucessful index.
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnStatus", "p.status", null, "p"));
    // creating a duplicate index should throw a IndexExistsException and if not
    // will throw a RuntimeException.
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnID", "p.ID", null, "p"));
    // 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("p.ID", idIndex.getIndexedExpression());
            assertEquals("/" + name + " p", 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("p.status", statusIndex.getIndexedExpression());
            assertEquals("/" + name + " p", 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);
    LogWriterUtils.getLogWriter().info("PRQBasicIndexCreationTest.testPRMultiIndexCreation ENDED");
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) 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)

Example 47 with PortfolioData

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

the class PRBasicIndexCreationDUnitTest 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);
    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));
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnStatus", "status", null, ""));
    // 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));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForIndexCreationCheck(name));
}
Also used : VM(org.apache.geode.test.dunit.VM) 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 48 with PortfolioData

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

the class PRBasicIndexCreationDUnitTest method testCreatePartitionedRegionThroughXMLAndAPI.

/**
   * Test creation of mutilple index on partitioned regions and then adding a new node to the system
   * and checking it has created all the indexes already in the sytem.
   * 
   */
@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);
    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));
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnStatus", "p.status", null, "p"));
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnId", "p.ID", null, "p"));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnPKID", "p.pkid", null, "p"));
    // 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) 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 49 with PortfolioData

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

the class PRBasicIndexCreationDUnitTest method testPartitionedIndexUsageWithPRQuery.

/**
   * Test index usage with query on a partitioned region with bucket indexes.
   */
@Test
public void testPartitionedIndexUsageWithPRQuery() 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.testPartitionedIndexUsageWithPRQuery started ");
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(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));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnId", "p.ID", null, "p"));
    final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForLocalRegionCreation(localName, PortfolioData.class));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(localName, portfolio, cnt, cntDest));
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRQueryAndCompareResults(name, localName));
    // validation on index usage with queries over a pr
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForIndexUsageCheck());
    vm1.invoke(PRQHelp.getCacheSerializableRunnableForIndexUsageCheck());
    vm2.invoke(PRQHelp.getCacheSerializableRunnableForIndexUsageCheck());
    vm3.invoke(PRQHelp.getCacheSerializableRunnableForIndexUsageCheck());
    LogWriterUtils.getLogWriter().info("PRBasicIndexCreationDUnitTest.testPartitionedIndexUsageWithPRQuery 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 50 with PortfolioData

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

the class PRBasicIndexCreationDUnitTest method testCreateIndexFromAccessor.

/**
   * Bug Fix 37201, creating index from a data accessor.
   */
@Test
public void testCreateIndexFromAccessor() 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);
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRAccessorCreate(name, redundancy, PortfolioData.class));
    // create more vms to host data.
    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
    vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
    // create the index form asscessor.
    vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRIndexCreate(name, "PrIndexOnStatus", "p.status", null, "p"));
}
Also used : VM(org.apache.geode.test.dunit.VM) 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)

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