Search in sources :

Example 16 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRColocatedDataSetQueryAndCompareResults.

public SerializableRunnableIF getCacheSerializableRunnableForPRColocatedDataSetQueryAndCompareResults(final String name, final String coloName, final String localName, final String coloLocalName) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the PR region
            String[] queries = new String[] { "r1.ID = r2.id", "r1.ID = r2.id AND r1.ID > 5", "r1.ID = r2.id AND r1.status = 'active'", // "r1.ID = r2.id LIMIT 10",
            "r1.ID = r2.id ORDER BY r1.ID", "r1.ID = r2.id ORDER BY r2.id", "r1.ID = r2.id ORDER BY r2.status", "r1.ID = r2.id AND r1.status != r2.status", "r1.ID = r2.id AND r1.status = r2.status", "r1.ID = r2.id AND r1.positions.size = r2.positions.size", "r1.ID = r2.id AND r1.positions.size > r2.positions.size", "r1.ID = r2.id AND r1.positions.size < r2.positions.size", "r1.ID = r2.id AND r1.positions.size = r2.positions.size AND r2.positions.size > 0", "r1.ID = r2.id AND (r1.positions.size > r2.positions.size OR r2.positions.size > 0)", "r1.ID = r2.id AND (r1.positions.size < r2.positions.size OR r1.positions.size > 0)" };
            Object[][] r = new Object[queries.length][2];
            Region region = null;
            region = cache.getRegion(name);
            assertNotNull(region);
            region = cache.getRegion(coloName);
            assertNotNull(region);
            region = cache.getRegion(localName);
            assertNotNull(region);
            region = cache.getRegion(coloLocalName);
            assertNotNull(region);
            final String[] expectedExceptions = new String[] { RegionDestroyedException.class.getName(), ReplyException.class.getName(), CacheClosedException.class.getName(), ForceReattemptException.class.getName(), QueryInvocationTargetException.class.getName() };
            for (final String expectedException : expectedExceptions) {
                getCache().getLogger().info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
            }
            QueryService qs = getCache().getQueryService();
            Object[] params;
            try {
                for (int j = 0; j < queries.length; j++) {
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    Function func = new TestQueryFunction("testfunction");
                    Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("<trace> Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, /" + coloName + " r2 where " + queries[j]).execute(func).getResult();
                    r[j][0] = ((ArrayList) funcResult).get(0);
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    SelectResults r2 = (SelectResults) qs.newQuery("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + localName + " r1, /" + coloLocalName + " r2 where " + queries[j]).execute();
                    r[j][1] = r2.asList();
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
                // compareTwoQueryResults(r, queries.length);
                StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
                ssORrs.CompareQueryResultsAsListWithoutAndWithIndexes(r, queries.length, false, false, queries);
            } catch (QueryInvocationTargetException e) {
                // cause and see whether or not it's okay
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (QueryException e) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught QueryException while querying" + e, e);
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (RegionDestroyedException rde) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a RegionDestroyedException while querying as expected ", rde);
            } catch (CancelException cce) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a CancelException while querying as expected ", cce);
            } finally {
                for (final String expectedException : expectedExceptions) {
                    getCache().getLogger().info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
                }
            }
        }
    };
    return (CacheSerializableRunnable) PrRegion;
}
Also used : StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) TestException(util.TestException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Function(org.apache.geode.cache.execute.Function) QueryException(org.apache.geode.cache.query.QueryException) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) Cache(org.apache.geode.cache.Cache)

Example 17 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRIndexCreate.

/**
   * This function creates a appropriate index on a PR given the name and other parameters.
   */
public CacheSerializableRunnable getCacheSerializableRunnableForPRIndexCreate(final String prRegionName, final String indexName, final String indexedExpression, final String fromClause, final String alias) {
    SerializableRunnable prIndexCreator = new CacheSerializableRunnable("PartitionedIndexCreator") {

        @Override
        public void run2() {
            try {
                Cache cache = getCache();
                QueryService qs = cache.getQueryService();
                Region region = cache.getRegion(prRegionName);
                LogWriter logger = cache.getLogger();
                if (null != fromClause) {
                    logger.info("Test Creating index with Name : [ " + indexName + " ] " + "IndexedExpression : [ " + indexedExpression + " ] Alias : [ " + alias + " ] FromClause : [ " + fromClause + " " + alias + " ] ");
                    Index parIndex = qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, fromClause);
                    logger.info("Index creted on partitioned region : " + parIndex);
                } else {
                    logger.info("Test Creating index with Name : [ " + indexName + " ] " + "IndexedExpression : [ " + indexedExpression + " ] Alias : [ " + alias + " ] FromClause : [ " + region.getFullPath() + " " + alias + " ] ");
                    Index parIndex = qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, region.getFullPath() + " " + alias);
                    logger.info("Index creted on partitioned region : " + parIndex);
                    logger.info("Number of buckets indexed in the partitioned region locally : " + "" + ((PartitionedIndex) parIndex).getNumberOfIndexedBuckets() + " and remote buckets indexed : " + ((PartitionedIndex) parIndex).getNumRemoteBucketsIndexed());
                }
            /*
           * assertIndexDetailsEquals("Max num of buckets in the partiotion regions and the
           * " + "buckets indexed should be equal",
           * ((PartitionedRegion)region).getTotalNumberOfBuckets(),
           * (((PartionedIndex)parIndex).getNumberOfIndexedBucket()+((PartionedIndex)parIndex).
           * getNumRemtoeBucketsIndexed())); should put all the assetion in a seperate function.
           */
            } catch (Exception ex) {
                Assert.fail("Creating Index in this vm failed : ", ex);
            }
        }
    };
    return (CacheSerializableRunnable) prIndexCreator;
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) LogWriter(org.apache.geode.LogWriter) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryExistsException(org.apache.geode.cache.EntryExistsException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) TestException(util.TestException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) Cache(org.apache.geode.cache.Cache)

Example 18 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRPuts.

/**
   * This function puts portfolio objects into the created Region (PR or Local) *
   * 
   * @param regionName
   * @param portfolio
   * @param to
   * @param from
   * @return cacheSerializable object
   */
public CacheSerializableRunnable getCacheSerializableRunnableForPRPuts(final String regionName, final Object[] portfolio, final int from, final int to) {
    SerializableRunnable prPuts = new CacheSerializableRunnable("PRPuts") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            for (int j = from; j < to; j++) region.put(new Integer(j), portfolio[j]);
        }
    };
    return (CacheSerializableRunnable) prPuts;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 19 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults.

/**
   * This function <br>
   * 1. Creates & executes a query with Constants on the given PR Region <br>
   * 2. Executes the same query on the local region <br>
   * 3. Compares the appropriate resultSet <br>
   */
public CacheSerializableRunnable getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults(final String regionName, final String localRegion) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the localRegion and the PR region
            String[] query = { "TRUE", "FALSE", "UNDEFINED", "NULL" };
            Object[][] r = new Object[query.length][2];
            Region local = cache.getRegion(localRegion);
            Region region = cache.getRegion(regionName);
            try {
                for (int j = 0; j < query.length; j++) {
                    r[j][0] = local.query(query[j]);
                    r[j][1] = region.query(query[j]);
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Queries Executed successfully on Local region & PR Region");
                compareTwoQueryResults(r, query.length);
            } catch (QueryException e) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught an Exception while querying Constants" + e, e);
                fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught Exception while querying Constants. Exception is " + e);
            }
        }
    };
    return (CacheSerializableRunnable) PrRegion;
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 20 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForColocatedChildCreate.

/**
   * This function creates the parent region of colocated pair of PR's given the scope & the
   * redundancy parameters for the parent *
   *
   * @param regionName
   * @param redundancy
   * @param constraint
   * @param isPersistent
   * @return cacheSerializable object
   */
public CacheSerializableRunnable getCacheSerializableRunnableForColocatedChildCreate(final String regionName, final int redundancy, final Class constraint, boolean isPersistent) {
    final String childRegionName = regionName + "Child";
    final String diskName = "disk";
    SerializableRunnable createPrRegion;
    createPrRegion = new CacheSerializableRunnable(regionName + "-ChildRegion") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region partitionedregion = null;
            Region childRegion = null;
            AttributesFactory attr = new AttributesFactory();
            attr.setValueConstraint(constraint);
            if (isPersistent) {
                DiskStore ds = cache.findDiskStore(diskName);
                if (ds == null) {
                    // ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs())
                    ds = cache.createDiskStoreFactory().setDiskDirs(org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase.getDiskDirs()).create(diskName);
                }
                attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                attr.setDiskStoreName(diskName);
            } else {
                attr.setDataPolicy(DataPolicy.PARTITION);
                attr.setDiskStoreName(null);
            }
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(redundancy);
            attr.setPartitionAttributes(paf.create());
            // skip parent region creation
            // partitionedregion = cache.createRegion(regionName, attr.create());
            // child region
            attr.setValueConstraint(constraint);
            paf.setColocatedWith(regionName);
            attr.setPartitionAttributes(paf.create());
            childRegion = cache.createRegion(childRegionName, attr.create());
        }
    };
    return (CacheSerializableRunnable) createPrRegion;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Aggregations

SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)741 VM (org.apache.geode.test.dunit.VM)405 Test (org.junit.Test)403 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)353 Region (org.apache.geode.cache.Region)347 Host (org.apache.geode.test.dunit.Host)344 Cache (org.apache.geode.cache.Cache)274 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)259 CacheException (org.apache.geode.cache.CacheException)207 AttributesFactory (org.apache.geode.cache.AttributesFactory)204 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)198 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)166 LocalRegion (org.apache.geode.internal.cache.LocalRegion)160 IOException (java.io.IOException)145 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)120 Properties (java.util.Properties)66 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)66 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)65 IgnoredException (org.apache.geode.test.dunit.IgnoredException)61 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)53