Search in sources :

Example 11 with IndexExistsException

use of org.apache.geode.cache.query.IndexExistsException in project geode by apache.

the class MultiIndexCreationJUnitTest method testMultiIndexCreationOnFailure.

@Test
public void testMultiIndexCreationOnFailure() throws Exception {
    Region r = CacheUtils.getRegion(regionName);
    for (int i = 0; i < 10; i++) {
        r.put("" + i, new Portfolio(i));
    }
    QueryService qs = CacheUtils.getQueryService();
    qs.defineIndex("IDIndex1", "ID", r.getFullPath());
    qs.defineIndex("IDIndex2", "ID", r.getFullPath());
    List<Index> indexes = null;
    try {
        indexes = qs.createDefinedIndexes();
        fail("Exception should have been thrown");
    } catch (MultiIndexCreationException me) {
        assertTrue("IndexExistsException should have been thrown ", me.getExceptionsMap().values().iterator().next() instanceof IndexExistsException);
    }
    assertNull("Index should not have been returned", indexes);
    assertEquals("1 index should have been created.", 1, qs.getIndexes().size());
    Index ind = qs.getIndexes().iterator().next();
    assertNotNull("Index should not be null.", ind);
    assertEquals(10, ind.getStatistics().getNumberOfKeys());
    assertEquals(10, ind.getStatistics().getNumberOfValues());
}
Also used : IndexExistsException(org.apache.geode.cache.query.IndexExistsException) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) Region(org.apache.geode.cache.Region) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) HashIndex(org.apache.geode.cache.query.internal.index.HashIndex) PrimaryKeyIndex(org.apache.geode.cache.query.internal.index.PrimaryKeyIndex) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 12 with IndexExistsException

use of org.apache.geode.cache.query.IndexExistsException in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForDuplicatePRIndexCreate.

/**
   * This function creates a duplicate index should throw an IndexNameConflictException and if not
   * the test should fail.
   */
public CacheSerializableRunnable getCacheSerializableRunnableForDuplicatePRIndexCreate(final String prRegionName, final String indexName, final String indexedExpression, final String fromClause, final String alias) {
    SerializableRunnable prIndexCreator = new CacheSerializableRunnable("DuplicatePartitionedIndexCreator") {

        @Override
        public void run2() {
            Cache cache = getCache();
            LogWriter logger = cache.getLogger();
            QueryService qs = cache.getQueryService();
            Region region = cache.getRegion(prRegionName);
            try {
                if (null != fromClause) {
                    qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, fromClause);
                    throw new RuntimeException("Should throw an exception because " + "the index with name : " + indexName + " should already exists");
                } else {
                    qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, region.getFullPath() + " " + alias);
                    throw new RuntimeException("Should throw an exception because " + "the index with name : " + indexName + " should already exists");
                }
            } catch (IndexExistsException e) {
                logger.info("Index Exists Excetpiont righteously throw ", e);
            } catch (IndexNameConflictException ex) {
                logger.info("Gott the right exception");
            } catch (RegionNotFoundException exx) {
                // TODO Auto-generated catch block
                Assert.fail("Region Not found in this vm ", exx);
            }
        }
    };
    return (CacheSerializableRunnable) prIndexCreator;
}
Also used : IndexExistsException(org.apache.geode.cache.query.IndexExistsException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LogWriter(org.apache.geode.LogWriter) QueryService(org.apache.geode.cache.query.QueryService) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) 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

IndexExistsException (org.apache.geode.cache.query.IndexExistsException)12 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)11 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)6 Index (org.apache.geode.cache.query.Index)5 Cache (org.apache.geode.cache.Cache)4 QueryService (org.apache.geode.cache.query.QueryService)4 Region (org.apache.geode.cache.Region)3 IndexInvalidException (org.apache.geode.cache.query.IndexInvalidException)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 FutureTask (java.util.concurrent.FutureTask)2 IndexType (org.apache.geode.cache.query.IndexType)2 MultiIndexCreationException (org.apache.geode.cache.query.MultiIndexCreationException)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1