use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.
the class DynamicEnableIndexingConcurrentSelfTest method testConcurrentEnableIndexing.
/**
* Test concurrent enabling indexing. Only one attempt should succeed.
*/
@Test
public void testConcurrentEnableIndexing() throws Exception {
// Start several nodes.
IgniteEx srv1 = ignitionStart(serverConfiguration(1));
ignitionStart(serverConfiguration(2));
ignitionStart(clientConfiguration(3));
ignitionStart(clientConfiguration(4));
srv1.cluster().state(ClusterState.ACTIVE);
createCache(srv1);
loadData(srv1, 0, LARGE_NUM_ENTRIES);
// Start enable indexing from several threads.
final AtomicBoolean stopped = new AtomicBoolean();
final AtomicInteger success = new AtomicInteger();
final CountDownLatch iterations = new CountDownLatch(1000);
IgniteInternalFuture<?> task = multithreadedAsync(() -> {
while (!stopped.get()) {
IgniteEx node = grid(ThreadLocalRandom.current().nextInt(1, 4));
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
enableIndexing(node).chain((fut) -> {
try {
fut.get();
success.incrementAndGet();
} catch (IgniteCheckedException e) {
assertTrue(e.hasCause(SchemaOperationException.class));
SchemaOperationException opEx = e.getCause(SchemaOperationException.class);
assertEquals(SchemaOperationException.CODE_CACHE_ALREADY_INDEXED, opEx.code());
assertEquals("Cache is already indexed: " + POI_CACHE_NAME, opEx.getMessage());
}
return null;
});
iterations.countDown();
}
return null;
}, 4);
// Do attempts.
iterations.await(2, TimeUnit.SECONDS);
// Start more server nodes..
ignitionStart(serverConfiguration(5));
ignitionStart(serverConfiguration(6));
// Stop task.
stopped.set(true);
task.get();
// Check that only one successful attempt.
assertEquals(1, success.get());
awaitPartitionMapExchange();
for (Ignite g : G.allGrids()) {
assertEquals(LARGE_NUM_ENTRIES, query(g, SELECT_ALL_QUERY).size());
performQueryingIntegrityCheck(g);
checkQueryParallelism((IgniteEx) g, cacheMode);
}
}
use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.
the class DynamicIndexAbstractBasicSelfTest method checkCreateNotCache.
/**
* Check create when cache doesn't exist.
*
* @param mode Mode.
* @param atomicityMode Atomicity mode.
* @param near Near flag.
* @throws Exception If failed.
*/
private void checkCreateNotCache(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
initialize(mode, atomicityMode, near);
final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
try {
String cacheName = randomString();
queryProcessor(node()).dynamicIndexCreate(cacheName, cacheName, TBL_NAME, idx, false, 0).get();
} catch (SchemaOperationException e) {
assertEquals(SchemaOperationException.CODE_CACHE_NOT_FOUND, e.code());
assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
return;
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
fail(SchemaOperationException.class.getSimpleName() + " is not thrown.");
}
Aggregations