use of org.apache.ignite.internal.cdc.CdcMain in project ignite by apache.
the class CdcSelfTest method testReReadWhenStateWasNotStored.
/**
*/
@Test
public void testReReadWhenStateWasNotStored() throws Exception {
IgniteEx ign = startGrid(getConfiguration("ignite-0"));
ign.cluster().state(ACTIVE);
IgniteCache<Integer, User> cache = ign.getOrCreateCache(DEFAULT_CACHE_NAME);
addData(cache, 0, KEYS_CNT);
for (int i = 0; i < 3; i++) {
UserCdcConsumer cnsmr = new UserCdcConsumer() {
@Override
protected boolean commit() {
return false;
}
};
CdcMain cdc = createCdc(cnsmr, getConfiguration(ign.name()));
IgniteInternalFuture<?> fut = runAsync(cdc);
waitForSize(KEYS_CNT, DEFAULT_CACHE_NAME, UPDATE, cnsmr);
checkMetrics(cdc, KEYS_CNT);
fut.cancel();
assertTrue(cnsmr.stopped());
}
AtomicBoolean consumeHalf = new AtomicBoolean(true);
AtomicBoolean halfCommitted = new AtomicBoolean(false);
int half = KEYS_CNT / 2;
UserCdcConsumer cnsmr = new UserCdcConsumer() {
@Override
public boolean onEvents(Iterator<CdcEvent> evts) {
if (consumeHalf.get() && F.size(data(UPDATE, cacheId(DEFAULT_CACHE_NAME))) == half) {
// This means that state committed as a result of the previous call.
halfCommitted.set(true);
return false;
}
while (evts.hasNext()) {
CdcEvent evt = evts.next();
if (!evt.primary())
continue;
data.computeIfAbsent(F.t(evt.value() == null ? DELETE : UPDATE, evt.cacheId()), k -> new ArrayList<>()).add((Integer) evt.key());
if (consumeHalf.get())
return F.size(data(UPDATE, cacheId(DEFAULT_CACHE_NAME))) == half;
}
return true;
}
};
CdcMain cdc = createCdc(cnsmr, getConfiguration(ign.name()));
IgniteInternalFuture<?> fut = runAsync(cdc);
waitForSize(half, DEFAULT_CACHE_NAME, UPDATE, cnsmr);
checkMetrics(cdc, half);
waitForCondition(halfCommitted::get, getTestTimeout());
fut.cancel();
assertTrue(cnsmr.stopped());
removeData(cache, 0, KEYS_CNT);
consumeHalf.set(false);
cdc = createCdc(cnsmr, getConfiguration(ign.name()));
fut = runAsync(cdc);
waitForSize(KEYS_CNT, DEFAULT_CACHE_NAME, UPDATE, cnsmr);
waitForSize(KEYS_CNT, DEFAULT_CACHE_NAME, DELETE, cnsmr);
checkMetrics(cdc, KEYS_CNT * 2 - half);
fut.cancel();
assertTrue(cnsmr.stopped());
}
use of org.apache.ignite.internal.cdc.CdcMain in project ignite by apache.
the class CdcConfigurationTest method testLoadConfig.
/**
*/
@Test
public void testLoadConfig() throws Exception {
assertThrows(null, () -> loadCdc("modules/spring/src/test/config/cdc/double-ignite-config.xml"), IgniteCheckedException.class, "Exact 1 IgniteConfiguration should be defined. Found 2");
assertThrows(null, () -> loadCdc("modules/spring/src/test/config/cdc/double-cdc-config.xml"), IgniteCheckedException.class, "Exact 1 CaptureDataChangeConfiguration configuration should be defined. Found 2");
CdcMain cdc = loadCdc("modules/spring/src/test/config/cdc/cdc-config-without-persistence.xml");
assertNotNull(cdc);
assertThrows(null, cdc::run, IgniteException.class, ERR_MSG);
}
use of org.apache.ignite.internal.cdc.CdcMain in project ignite by apache.
the class CdcSelfTest method readAll.
/**
*/
private void readAll(UserCdcConsumer cnsmr, boolean offsetCommit) throws Exception {
IgniteConfiguration cfg = getConfiguration("ignite-0");
Ignite ign = startGrid(cfg);
ign.cluster().state(ACTIVE);
IgniteCache<Integer, User> cache = ign.getOrCreateCache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, User> txCache = ign.getOrCreateCache(TX_CACHE_NAME);
addAndWaitForConsumption(cnsmr, cfg, cache, txCache, CdcSelfTest::addData, 0, KEYS_CNT + 3, offsetCommit);
removeData(cache, 0, KEYS_CNT);
CdcMain cdcMain = createCdc(cnsmr, cfg);
IgniteInternalFuture<?> rmvFut = runAsync(cdcMain);
waitForSize(KEYS_CNT, DEFAULT_CACHE_NAME, DELETE, cnsmr);
checkMetrics(cdcMain, offsetCommit ? KEYS_CNT : ((KEYS_CNT + 3) * 2 + KEYS_CNT));
rmvFut.cancel();
assertTrue(cnsmr.stopped());
stopAllGrids();
cleanPersistenceDir();
}
use of org.apache.ignite.internal.cdc.CdcMain in project ignite by apache.
the class AbstractCdcTest method addAndWaitForConsumption.
/**
*/
protected void addAndWaitForConsumption(UserCdcConsumer cnsmr, IgniteConfiguration cfg, IgniteCache<Integer, CdcSelfTest.User> cache, IgniteCache<Integer, CdcSelfTest.User> txCache, CI3<IgniteCache<Integer, CdcSelfTest.User>, Integer, Integer> addData, int from, int to, boolean waitForCommit) throws Exception {
GridAbsPredicate cachePredicate = sizePredicate(to - from, cache.getName(), UPDATE, cnsmr);
GridAbsPredicate txPredicate = txCache == null ? null : sizePredicate(to - from, txCache.getName(), UPDATE, cnsmr);
CdcMain cdc;
CountDownLatch latch = new CountDownLatch(1);
if (waitForCommit) {
cdc = txCache == null ? createCdc(cnsmr, cfg, latch, cachePredicate) : createCdc(cnsmr, cfg, latch, cachePredicate, txPredicate);
} else
cdc = createCdc(cnsmr, cfg);
IgniteInternalFuture<?> fut = runAsync(cdc);
addData.apply(cache, from, to);
if (txCache != null)
addData.apply(txCache, from, to);
if (waitForCommit)
latch.await(getTestTimeout(), MILLISECONDS);
else {
assertTrue(waitForCondition(cachePredicate, getTestTimeout()));
if (txCache != null)
assertTrue(waitForCondition(txPredicate, getTestTimeout()));
}
checkMetrics(cdc, txCache == null ? to : to * 2);
fut.cancel();
List<Integer> keys = cnsmr.data(UPDATE, cacheId(cache.getName()));
assertEquals(to - from, keys.size());
for (int i = from; i < to; i++) assertTrue(Integer.toString(i), keys.contains(i));
assertTrue(cnsmr.stopped());
}
use of org.apache.ignite.internal.cdc.CdcMain in project ignite by apache.
the class CdcConfigurationTest method testInjectResources.
/**
*/
@Test
public void testInjectResources() throws Exception {
CdcMain cdc = loadCdc("modules/spring/src/test/config/cdc/correct-cdc-config.xml");
try (IgniteEx ign = startGrid((IgniteConfiguration) getFieldValue(cdc, "igniteCfg"))) {
TestCdcConsumer cnsmr = (TestCdcConsumer) ((WalRecordsConsumer<?, ?>) getFieldValue(cdc, "consumer")).consumer();
assertNotNull(cnsmr);
CountDownLatch startLatch = cnsmr.startLatch;
IgniteInternalFuture<?> fut = runAsync(cdc::run);
startLatch.await(getTestTimeout(), MILLISECONDS);
assertEquals("someString", cnsmr.springString);
assertEquals("someString2", cnsmr.springString2);
assertNotNull(cnsmr.log);
assertNotNull(cnsmr.ctx);
fut.cancel();
}
}
Aggregations