Skip to content
Merged
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 @@ -17,14 +17,33 @@

package org.apache.ignite.internal;

import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

import static java.util.stream.Collectors.joining;

/**
*
*/
public class IgniteThreadGroupNodeRestartTest extends GridCommonAbstractTest {
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();

stopAllGrids();
}

/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
super.afterTest();

stopAllGrids();
}

/**
* @throws Exception if failed.
*/
Expand All @@ -36,9 +55,7 @@

Thread t = new Thread(tg, () -> {
try {
startGrid(0);

stopGrid(0);
startStopGrid(0);
}
catch (Exception e) {
err.set(e);
Expand All @@ -47,13 +64,58 @@

t.start();
t.join(getTestTimeout());
assertFalse(t.isAlive());

if (err.get() != null)
throw err.get();

tg.destroy();
destroyWithWaitAllThreadIsComplete(tg, getTestTimeout());

startStopGrid(0);
}

/** */
private void startStopGrid(int idx) throws Exception {
startGrid(idx);
stopGrid(idx);
}

/** */
private static void destroyWithWaitAllThreadIsComplete(ThreadGroup tg, long millis) throws Exception {
if (GridTestUtils.waitForCondition(() -> tg.activeCount() == 0, millis, 10) || tg.activeCount() == 0) {
tg.destroy();

return;
}

Thread[] threads = new Thread[tg.activeCount() + 256];
int copied = tg.enumerate(threads, true);

if (copied == 0) {
tg.destroy();

Check warning on line 95 in modules/core/src/test/java/org/apache/ignite/internal/IgniteThreadGroupNodeRestartTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this call to a deprecated method, it has been marked for removal.

See more on https://sonarcloud.io/project/issues?id=apache_ignite&issues=AZ1SV-D2WzwQiKxZSjTI&open=AZ1SV-D2WzwQiKxZSjTI&pullRequest=12977

return;
}

fail(String.format(
"Thread group still has active threads: [count=%s, threads=%s]",
copied, threadInfos(threads)
));
}

/** */
private static String threadInfos(Thread... threads) {
return Arrays.stream(threads)
.filter(Objects::nonNull)
.map(IgniteThreadGroupNodeRestartTest::threadInfo)
.collect(joining(", ", "[", "]"));
}

startGrid(0);
stopGrid(0);
/** */
private static String threadInfo(Thread t) {
return String.format(
"[id=%s, name=%s, alive=%s, deamon=%s, state=%s]",
t.getId(), t.getName(), t.isAlive(), t.isDaemon(), t.getState()
);
}
}
Loading