use of org.apache.ignite.testframework.CallbackExecutorLogListener in project ignite by apache.
the class RebalanceStatisticsTest method testRebalanceStatistics.
/**
* Test statistics of a rebalance.
*
* Steps:
* 1)Creating and filling a cluster;
* 2)Starting a new node with listening for logs and supply messages;
* 3)Check that number of supply messages is equal to number of logs received +1;
* 4)Find corresponding message in log for each supply message;
* 5)Find log message after all of groups and to check its correctness.
*
* @throws Exception if any error occurs.
*/
@Test
public void testRebalanceStatistics() throws Exception {
createCluster(3);
ListeningTestLogger listeningTestLog = new ListeningTestLogger(log);
IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(3)).setGridLogger(listeningTestLog);
// Collect log messages with rebalance statistics.
Collection<String> logMsgs = new ConcurrentLinkedQueue<>();
listeningTestLog.registerListener(new CallbackExecutorLogListener("Completed( \\(final\\))? rebalanc(ing|e chain).*", logMsgs::add));
Map<Ignite, Collection<T2<ClusterNode, Message>>> recordMsgs = new ConcurrentHashMap<>();
G.allGrids().forEach(n -> TestRecordingCommunicationSpi.spi(n).record((node, msg) -> {
if (GridDhtPartitionSupplyMessage.class.isInstance(msg))
recordMsgs.computeIfAbsent(n, n1 -> new ConcurrentLinkedQueue<>()).add(new T2<>(node, msg));
return false;
}));
IgniteEx node = startGrid(cfg);
awaitPartitionMapExchange();
// Collect supply messages only for new node.
Map<Ignite, List<GridDhtPartitionSupplyMessage>> supplyMsgs = G.allGrids().stream().filter(n -> !n.equals(node)).collect(toMap(identity(), n -> recordMsgs.get(n).stream().filter(t2 -> t2.get1().id().equals(node.localNode().id())).map(IgniteBiTuple::get2).map(GridDhtPartitionSupplyMessage.class::cast).collect(toList())));
// +1 because one message about end of rebalance for all groups.
assertEquals(supplyMsgs.values().stream().mapToInt(List::size).sum() + 1, logMsgs.size());
IgniteClosure2X<GridCacheEntryInfo, CacheObjectContext, Long> getSize = new IgniteClosure2X<GridCacheEntryInfo, CacheObjectContext, Long>() {
/**
* {@inheritDoc}
*/
@Override
public Long applyx(GridCacheEntryInfo info, CacheObjectContext ctx) throws IgniteCheckedException {
return (long) info.marshalledSize(ctx);
}
};
for (Map.Entry<Ignite, List<GridDhtPartitionSupplyMessage>> supplyMsg : supplyMsgs.entrySet()) {
List<String> supplierMsgs = logMsgs.stream().filter(s -> s.contains("supplier=" + supplyMsg.getKey().cluster().localNode().id())).collect(toList());
List<GridDhtPartitionSupplyMessage> msgs = supplyMsg.getValue();
assertEquals(msgs.size(), supplierMsgs.size());
for (GridDhtPartitionSupplyMessage msg : msgs) {
Map<Integer, CacheEntryInfoCollection> infos = U.field(msg, "infos");
CacheGroupContext grpCtx = node.context().cache().cacheGroup(msg.groupId());
long bytes = 0;
for (CacheEntryInfoCollection c : infos.values()) {
for (GridCacheEntryInfo i : c.infos()) bytes += getSize.apply(i, grpCtx.cacheObjectContext());
}
String[] checVals = { "grp=" + grpCtx.cacheOrGroupName(), "partitions=" + infos.size(), "entries=" + infos.values().stream().mapToInt(i -> i.infos().size()).sum(), "topVer=" + msg.topologyVersion(), "rebalanceId=" + U.field(msg, "rebalanceId"), "bytesRcvd=" + U.humanReadableByteCount(bytes), "fullPartitions=" + infos.size(), "fullEntries=" + infos.values().stream().mapToInt(i -> i.infos().size()).sum(), "fullBytesRcvd=" + U.humanReadableByteCount(bytes), "histPartitions=0", "histEntries=0", "histBytesRcvd=0" };
assertTrue("msgs=" + supplierMsgs.toString() + ", checVals=" + asList(checVals).toString(), supplierMsgs.stream().anyMatch(s -> Stream.of(checVals).allMatch(s::contains)));
}
}
String rebChainMsg = logMsgs.stream().filter(s -> s.startsWith("Completed rebalance chain")).findAny().get();
long rebId = -1;
int parts = 0;
int entries = 0;
long bytes = 0;
for (List<GridDhtPartitionSupplyMessage> msgs : supplyMsgs.values()) {
for (GridDhtPartitionSupplyMessage msg : msgs) {
Map<Integer, CacheEntryInfoCollection> infos = U.field(msg, "infos");
rebId = U.field(msg, "rebalanceId");
parts += infos.size();
entries += infos.values().stream().mapToInt(i -> i.infos().size()).sum();
CacheObjectContext cacheObjCtx = node.context().cache().cacheGroup(msg.groupId()).cacheObjectContext();
for (CacheEntryInfoCollection c : infos.values()) {
for (GridCacheEntryInfo i : c.infos()) bytes += getSize.apply(i, cacheObjCtx);
}
}
}
String[] checVals = { "partitions=" + parts, "entries=" + entries, "rebalanceId=" + rebId, "bytesRcvd=" + U.humanReadableByteCount(bytes) };
assertTrue(rebChainMsg, Stream.of(checVals).allMatch(rebChainMsg::contains));
}
use of org.apache.ignite.testframework.CallbackExecutorLogListener in project ignite by apache.
the class LongDestroyDurableBackgroundTaskTest method testRemoveIndexesOnTableDrop.
/**
* Tests that index is correctly deleted when corresponding SQL table is deleted.
*
* @throws Exception If failed.
*/
@Test
public void testRemoveIndexesOnTableDrop() throws Exception {
IgniteEx ignite = startGrids(1);
ignite.cluster().state(ACTIVE);
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(DEFAULT_CACHE_NAME);
query(cache, "create table t1 (id integer primary key, p integer, f integer) " + "with \"BACKUPS=1, CACHE_GROUP=grp_test_table\"");
query(cache, "create table t2 (id integer primary key, p integer, f integer) " + "with \"BACKUPS=1, CACHE_GROUP=grp_test_table\"");
query(cache, "create index t2_idx on t2 (p)");
batchQuery(ignite, "insert into t2 (id, p, f) values (?, ?, ?)", batchInsertArgs(5_000, 3));
forceCheckpoint();
CountDownLatch inxDelInAsyncTaskLatch = new CountDownLatch(1);
LogListener lsnr = new CallbackExecutorLogListener(".*?Execution of durable background task completed: drop-sql-index-SQL_PUBLIC_T2-T2_IDX-.*", inxDelInAsyncTaskLatch::countDown);
testLog.registerListener(lsnr);
ignite.destroyCache("SQL_PUBLIC_T2");
awaitLatch(inxDelInAsyncTaskLatch, "Failed to await for index deletion in async task " + "(either index failed to delete in 1 minute or async task not started)");
}
Aggregations