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());
}
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;
}
Aggregations