Search in sources :

Example 6 with MultiIndexCreationException

use of org.apache.geode.cache.query.MultiIndexCreationException 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 7 with MultiIndexCreationException

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

the class CreateDefinedIndexesFunction method execute.

@Override
public void execute(FunctionContext context) {
    String memberId = null;
    List<Index> indexes = null;
    Cache cache = null;
    try {
        cache = CacheFactory.getAnyInstance();
        memberId = cache.getDistributedSystem().getDistributedMember().getId();
        QueryService queryService = cache.getQueryService();
        Set<IndexInfo> indexDefinitions = (Set<IndexInfo>) context.getArguments();
        for (IndexInfo indexDefinition : indexDefinitions) {
            String indexName = indexDefinition.getIndexName();
            String indexedExpression = indexDefinition.getIndexedExpression();
            String regionPath = indexDefinition.getRegionPath();
            if (indexDefinition.getIndexType() == IndexInfo.KEY_INDEX) {
                queryService.defineKeyIndex(indexName, indexedExpression, regionPath);
            } else if (indexDefinition.getIndexType() == IndexInfo.HASH_INDEX) {
                queryService.defineHashIndex(indexName, indexedExpression, regionPath);
            } else {
                queryService.defineIndex(indexName, indexedExpression, regionPath);
            }
        }
        indexes = queryService.createDefinedIndexes();
        context.getResultSender().lastResult(new CliFunctionResult(memberId));
    } catch (MultiIndexCreationException e) {
        StringBuffer sb = new StringBuffer();
        sb.append("Index creation failed for indexes: ").append("\n");
        for (Map.Entry<String, Exception> failedIndex : e.getExceptionsMap().entrySet()) {
            sb.append(failedIndex.getKey()).append(" : ").append(failedIndex.getValue().getMessage()).append("\n");
        }
        context.getResultSender().lastResult(new CliFunctionResult(memberId, e, sb.toString()));
    } catch (Exception e) {
        String exceptionMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, e, exceptionMessage));
    }
}
Also used : Set(java.util.Set) Index(org.apache.geode.cache.query.Index) IndexInfo(org.apache.geode.management.internal.cli.domain.IndexInfo) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) QueryService(org.apache.geode.cache.query.QueryService) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) Cache(org.apache.geode.cache.Cache)

Example 8 with MultiIndexCreationException

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

the class RollingUpgrade2DUnitTest method createIndexes.

public static void createIndexes(String regionPath, GemFireCache cache) {
    try {
        QueryService service = cache.getQueryService();
        service.defineIndex("statusIndex", "status", regionPath);
        service.defineIndex("IDIndex", "ID", regionPath);
        service.defineIndex("secIdIndex", "pos.secId", regionPath + " p, p.positions.values pos");
        try {
            service.createDefinedIndexes();
            fail("Index creation should have failed");
        } catch (Exception e) {
            Assert.assertTrue("Only MultiIndexCreationException should have been thrown and not " + e.getClass(), e instanceof MultiIndexCreationException);
            Assert.assertEquals("3 exceptions should have be present in the exceptionsMap.", 3, ((MultiIndexCreationException) e).getExceptionsMap().values().size());
            for (Exception ex : ((MultiIndexCreationException) e).getExceptionsMap().values()) {
                Assert.assertTrue("Index creation should have been failed with IndexCreationException ", ex instanceof IndexCreationException);
                Assert.assertEquals("Incorrect exception message ", LocalizedStrings.PartitionedRegion_INDEX_CREATION_FAILED_ROLLING_UPGRADE.toLocalizedString(), ((IndexCreationException) ex).getMessage());
            }
        }
    } catch (Exception e) {
        throw new Error("Exception ", e);
    }
}
Also used : QueryService(org.apache.geode.cache.query.QueryService) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) RMIException(org.apache.geode.test.dunit.RMIException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

MultiIndexCreationException (org.apache.geode.cache.query.MultiIndexCreationException)8 Index (org.apache.geode.cache.query.Index)7 HashMap (java.util.HashMap)4 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)4 QueryService (org.apache.geode.cache.query.QueryService)4 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CancelException (org.apache.geode.CancelException)3 CacheException (org.apache.geode.cache.CacheException)3 Region (org.apache.geode.cache.Region)3 FunctionException (org.apache.geode.cache.execute.FunctionException)3 IndexCreationException (org.apache.geode.cache.query.IndexCreationException)3 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)3 QueryException (org.apache.geode.cache.query.QueryException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 ExecutionException (java.util.concurrent.ExecutionException)2