use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentCacheDestroyCreate.
/**
* Wait for rebalance, cache is destroyed and created again.
*
* @throws Exception If failed.
*/
@Test
public void testDelayAssignmentCacheDestroyCreate() throws Exception {
Ignite ignite0 = startServer(0, 1);
CacheConfiguration ccfg = cacheConfiguration();
ccfg.setName(CACHE_NAME2);
ignite0.createCache(ccfg);
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
((IgniteDiscoverySpi) ignite0.configuration().getDiscoverySpi()).setInternalListener(lsnr);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
blockSupplySend(spi, CACHE_NAME2);
lsnr.blockCustomEvent(CacheAffinityChangeMessage.class);
startServer(1, 2);
startGrid(3);
checkAffinity(3, topVer(3, 0), false);
spi.stopBlock();
lsnr.waitCustomEvent();
ignite0.destroyCache(CACHE_NAME2);
ccfg = cacheConfiguration();
ccfg.setName(CACHE_NAME2);
ccfg.setAffinity(affinityFunction(10));
ignite0.createCache(ccfg);
lsnr.stopBlockCustomEvents();
checkAffinity(3, topVer(3, 1), false);
checkAffinity(3, topVer(3, 2), false);
idealAff.get(2L).remove(CU.cacheId(CACHE_NAME2));
calculateAffinity(3);
checkAffinity(3, topVer(3, 3), true);
}
use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentAffinityChanged2.
/**
* Wait for rebalance, send affinity change message, but affinity already changed (new node joined).
*
* @throws Exception If failed.
*/
@Test
public void testDelayAssignmentAffinityChanged2() throws Exception {
System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
try {
Ignite ignite0 = startServer(0, 1);
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
((IgniteDiscoverySpi) ignite0.configuration().getDiscoverySpi()).setInternalListener(lsnr);
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
startClient(1, 2);
checkAffinity(2, topVer(2, 0), true);
startServer(2, 3);
checkAffinity(3, topVer(3, 1), false);
lsnr.blockCustomEvent(CacheAffinityChangeMessage.class);
stopNode(2, 4);
lsnr.waitCustomEvent();
blockSupplySend(commSpi0, CACHE_NAME1);
final IgniteInternalFuture<?> startedFuture = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startServer(3, 5);
return null;
}
}, 1, "server-starter");
Thread.sleep(2_000);
lsnr.stopBlockCustomEvents();
boolean started = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return startedFuture.isDone();
}
}, 10_000);
if (!started)
startedFuture.cancel();
assertTrue(started);
checkAffinity(3, topVer(5, 0), false);
checkNoExchange(3, topVer(5, 1));
commSpi0.stopBlock();
checkAffinity(3, topVer(5, 1), true);
long nodeJoinTopVer = grid(3).context().discovery().localJoinEvent().topologyVersion();
assertEquals(5, nodeJoinTopVer);
List<GridDhtPartitionsExchangeFuture> exFutures = grid(3).context().cache().context().exchange().exchangeFutures();
for (GridDhtPartitionsExchangeFuture f : exFutures) {
// Shouldn't contains staled futures.
assertTrue(f.initialVersion().topologyVersion() >= nodeJoinTopVer);
}
} finally {
System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
}
}
use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.
the class IgniteWalRecoveryTest method testBinaryRecoverBeforePMEWhenMiddleCheckpoint.
/**
* Check binary recover completes successfully when node stopped at the middle of checkpoint. Destroy cache_data.bin
* file for particular cache to emulate missing {@link DynamicCacheDescriptor} file (binary recovery should complete
* successfully in this case).
*
* @throws Exception if failed.
*/
@Test
public void testBinaryRecoverBeforePMEWhenMiddleCheckpoint() throws Exception {
startGrids(3);
IgniteEx ig2 = grid(2);
ig2.cluster().active(true);
IgniteCache<Object, Object> cache = ig2.cache(CACHE_NAME);
for (int i = 1; i <= 4_000; i++) cache.put(i, new BigObject(i));
BigObject objToCheck;
ig2.getOrCreateCache(CACHE_TO_DESTROY_NAME).put(1, objToCheck = new BigObject(1));
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig2.context().cache().context().database();
IgniteInternalFuture<?> cpFinishFut = dbMgr.forceCheckpoint("force checkpoint").futureFor(FINISHED);
// Delete checkpoint END file to emulate node stopped at the middle of checkpoint.
cpFinishFut.listen(new IgniteInClosureX<IgniteInternalFuture>() {
@Override
public void applyx(IgniteInternalFuture fut0) throws IgniteCheckedException {
try {
CheckpointEntry cpEntry = dbMgr.checkpointHistory().lastCheckpoint();
String cpEndFileName = CheckpointMarkersStorage.checkpointFileName(cpEntry, CheckpointEntryType.END);
Files.delete(Paths.get(dbMgr.checkpointDirectory().getAbsolutePath(), cpEndFileName));
log.info("Checkpoint marker removed [cpEndFileName=" + cpEndFileName + ']');
} catch (IOException e) {
throw new IgniteCheckedException(e);
}
}
});
// Resolve cache directory. Emulating cache destroy in the middle of checkpoint.
IgniteInternalCache<Object, Object> destoryCache = ig2.cachex(CACHE_TO_DESTROY_NAME);
FilePageStoreManager pageStoreMgr = (FilePageStoreManager) destoryCache.context().shared().pageStore();
File destroyCacheWorkDir = pageStoreMgr.cacheWorkDir(destoryCache.configuration());
// Stop the whole cluster
stopAllGrids();
// Delete cache_data.bin file for this cache. Binary recovery should complete successfully after it.
final File[] files = destroyCacheWorkDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.endsWith(CACHE_DATA_FILENAME);
}
});
assertTrue(files.length > 0);
for (final File file : files) assertTrue("Can't remove " + file.getAbsolutePath(), file.delete());
startGrids(2);
// Preprare Ignite instance configuration with additional Discovery checks.
final String ig2Name = getTestIgniteInstanceName(2);
final IgniteConfiguration onJoinCfg = optimize(getConfiguration(ig2Name));
// Check restore beeing called before PME and joining node to cluster.
((IgniteDiscoverySpi) onJoinCfg.getDiscoverySpi()).setInternalListener(new DiscoverySpiTestListener() {
@Override
public void beforeJoin(ClusterNode locNode, IgniteLogger log) {
String nodeName = locNode.attribute(ATTR_IGNITE_INSTANCE_NAME);
GridCacheSharedContext sharedCtx = ((IgniteEx) ignite(getTestIgniteInstanceIndex(nodeName))).context().cache().context();
if (nodeName.equals(ig2Name)) {
// Checkpoint history initialized on node start.
assertFalse(((GridCacheDatabaseSharedManager) sharedCtx.database()).checkpointHistory().checkpoints().isEmpty());
}
super.beforeJoin(locNode, log);
}
});
Ignite restoredIg2 = startGrid(ig2Name, onJoinCfg);
awaitPartitionMapExchange();
assertEquals(restoredIg2.cache(CACHE_TO_DESTROY_NAME).get(1), objToCheck);
}
use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.
the class GridMessagingSelfTest method testAsyncOld.
/**
* @throws Exception If failed.
*/
@Test
public void testAsyncOld() throws Exception {
final AtomicInteger msgCnt = new AtomicInteger();
IgniteDiscoverySpi discoSpi = (IgniteDiscoverySpi) ignite2.configuration().getDiscoverySpi();
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
discoSpi.setInternalListener(lsnr);
assertFalse(ignite2.message().isAsync());
final IgniteMessaging msg = ignite2.message().withAsync();
assertTrue(msg.isAsync());
assertFalse(ignite2.message().isAsync());
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
lsnr.blockCustomEvent(StartRoutineDiscoveryMessage.class, StartRoutineDiscoveryMessageV2.class);
final String topic = "topic";
UUID id = msg.remoteListen(topic, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt.incrementAndGet();
return true;
}
});
Assert.assertNull(id);
IgniteFuture<UUID> starFut = msg.future();
Assert.assertNotNull(starFut);
U.sleep(500);
Assert.assertFalse(starFut.isDone());
lsnr.stopBlockCustomEvents();
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
id = starFut.get();
Assert.assertNotNull(id);
Assert.assertTrue(starFut.isDone());
lsnr.blockCustomEvent(StopRoutineDiscoveryMessage.class);
message(ignite1.cluster().forRemotes()).send(topic, "msg1");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return msgCnt.get() > 0;
}
}, 5000);
assertEquals(1, msgCnt.get());
msg.stopRemoteListen(id);
IgniteFuture<?> stopFut = msg.future();
Assert.assertNotNull(stopFut);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
msg.future();
return null;
}
}, IllegalStateException.class, null);
U.sleep(500);
Assert.assertFalse(stopFut.isDone());
lsnr.stopBlockCustomEvents();
stopFut.get();
Assert.assertTrue(stopFut.isDone());
message(ignite1.cluster().forRemotes()).send(topic, "msg2");
U.sleep(1000);
assertEquals(1, msgCnt.get());
}
use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.
the class GridMessagingSelfTest method testAsync.
/**
* @throws Exception If failed.
*/
@Test
public void testAsync() throws Exception {
final AtomicInteger msgCnt = new AtomicInteger();
IgniteDiscoverySpi discoSpi = (IgniteDiscoverySpi) ignite2.configuration().getDiscoverySpi();
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
discoSpi.setInternalListener(lsnr);
lsnr.blockCustomEvent(StartRoutineDiscoveryMessage.class, StartRoutineDiscoveryMessageV2.class);
final String topic = "topic";
IgniteFuture<UUID> starFut = ignite2.message().remoteListenAsync(topic, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt.incrementAndGet();
return true;
}
});
Assert.assertNotNull(starFut);
U.sleep(500);
Assert.assertFalse(starFut.isDone());
lsnr.stopBlockCustomEvents();
UUID id = starFut.get();
Assert.assertNotNull(id);
Assert.assertTrue(starFut.isDone());
lsnr.blockCustomEvent(StopRoutineDiscoveryMessage.class);
message(ignite1.cluster().forRemotes()).send(topic, "msg1");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return msgCnt.get() > 0;
}
}, 5000);
assertEquals(1, msgCnt.get());
IgniteFuture<?> stopFut = ignite2.message().stopRemoteListenAsync(id);
Assert.assertNotNull(stopFut);
U.sleep(500);
Assert.assertFalse(stopFut.isDone());
lsnr.stopBlockCustomEvents();
stopFut.get();
Assert.assertTrue(stopFut.isDone());
message(ignite1.cluster().forRemotes()).send(topic, "msg2");
U.sleep(1000);
assertEquals(1, msgCnt.get());
}
Aggregations