Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
package org.apache.ignite.internal.table;

import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.time.Duration;
import java.util.Objects;
import org.apache.ignite.internal.app.IgniteImpl;
import org.apache.ignite.internal.catalog.Catalog;
Expand Down Expand Up @@ -86,18 +90,31 @@ static void enableStats(String tableName) {
for (int p = 0; p < table.partsCount; p++) {
String metricName = PartitionTableStatsMetricSource.formatSourceName(table.id, p);

for (int i = 0; i < CLUSTER.nodes().size(); i++) {
enableMetricSource(metricName, i);
}
// Wait for at least one node to have the metric source enabled.
await().pollDelay(Duration.ZERO).untilAsserted(() -> {
boolean found = false;

for (int i = 0; i < CLUSTER.nodes().size(); i++) {
if (tryEnableMetricSource(metricName, i)) {
found = true;
}
}

assertThat("Metric source not found on any node: " + metricName, found, is(true));
});
}
}

static void enableMetricSource(String sourceName, int nodeIdx) {
private static boolean tryEnableMetricSource(String sourceName, int nodeIdx) {
IgniteImpl node = unwrapIgniteImpl(node(nodeIdx));
node.metricManager().metricSources().stream()
return node.metricManager().metricSources().stream()
.filter(ms -> sourceName.equals(ms.name()))
.findAny()
.ifPresent(ms -> node.metricManager().enable(ms));
.map(ms -> {
node.metricManager().enable(ms);
return true;
})
.orElse(false);
}

static final class TableTuple {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.apache.ignite.internal.table.distributed.PartitionTableStatsMetricSource.METRIC_COUNTER;
import static org.apache.ignite.internal.table.distributed.PartitionTableStatsMetricSource.METRIC_LAST_MILESTONE_TIMESTAMP;
import static org.apache.ignite.internal.table.distributed.PartitionTableStatsMetricSource.METRIC_NEXT_MILESTONE;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
Expand All @@ -31,7 +32,6 @@
import org.apache.ignite.internal.table.distributed.PartitionTableStatsMetricSource;
import org.apache.ignite.table.KeyValueView;
import org.apache.ignite.tx.Transaction;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -265,27 +265,18 @@ void reachMilestoneUpdateTest() {
expectModsCount(tableWithReplicas, expectedModsCount * replicas);

// Timestamp should change because we reached the threshold.
Awaitility.await().untilAsserted(() ->
assertThat(metricFromAnyNode(tableNoReplicas, 0, METRIC_LAST_MILESTONE_TIMESTAMP), greaterThan(initTsNoReplicas))
);
Awaitility.await().untilAsserted(() ->
assertThat(metricFromAnyNode(tableWithReplicas, 0, METRIC_LAST_MILESTONE_TIMESTAMP),
greaterThan(initTsWithReplicas))
);

Awaitility.await().untilAsserted(() ->
assertThat(metricFromAnyNode(tableNoReplicas, 0, METRIC_NEXT_MILESTONE), is(DEFAULT_MIN_STALE_ROWS_COUNT * 2))
);
Awaitility.await().untilAsserted(() ->
assertThat(metricFromAnyNode(tableWithReplicas, 0, METRIC_NEXT_MILESTONE), is(DEFAULT_MIN_STALE_ROWS_COUNT * 2))
);
await().until(() -> metricFromAnyNode(tableNoReplicas, 0, METRIC_LAST_MILESTONE_TIMESTAMP), greaterThan(initTsNoReplicas));
await().until(() -> metricFromAnyNode(tableWithReplicas, 0, METRIC_LAST_MILESTONE_TIMESTAMP), greaterThan(initTsWithReplicas));

await().until(() -> metricFromAnyNode(tableNoReplicas, 0, METRIC_NEXT_MILESTONE), is(DEFAULT_MIN_STALE_ROWS_COUNT * 2));
await().until(() -> metricFromAnyNode(tableWithReplicas, 0, METRIC_NEXT_MILESTONE), is(DEFAULT_MIN_STALE_ROWS_COUNT * 2));
}
}

private static void expectAggregatedMetricValue(String tableName, long value, String metricName) {
TableTuple table = TableTuple.of(tableName);

Awaitility.await().untilAsserted(() -> {
await().untilAsserted(() -> {
long aggregatedValue = 0;

for (int part = 0; part < table.partsCount; part++) {
Expand Down