Skip to content

Commit fa560e8

Browse files
committed
Fix tests and test skaffolding
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent aadc6eb commit fa560e8

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

server/src/internalClusterTest/java/org/opensearch/discovery/ClusterManagerDisruptionIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858

5959
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
6060
import static org.hamcrest.Matchers.equalTo;
61+
import static org.hamcrest.Matchers.lessThan;
6162
import static org.hamcrest.Matchers.not;
63+
import static org.junit.Assume.assumeThat;
6264

6365
/**
6466
* Tests relating to the loss of the cluster-manager.
@@ -71,6 +73,7 @@ public class ClusterManagerDisruptionIT extends AbstractDisruptionTestCase {
7173
*/
7274
public void testClusterManagerNodeGCs() throws Exception {
7375
List<String> nodes = startCluster(3);
76+
assumeThat("Thread::resume / Thread::suspend are not supported anymore", Runtime.version(), lessThan(Runtime.Version.parse("20")));
7477

7578
String oldClusterManagerNode = internalCluster().getClusterManagerName();
7679
// a very long GC, but it's OK as we remove the disruption when it has had an effect

server/src/internalClusterTest/java/org/opensearch/discovery/StableClusterManagerDisruptionIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171

7272
import static java.util.Collections.singleton;
7373
import static org.hamcrest.Matchers.equalTo;
74+
import static org.hamcrest.Matchers.lessThan;
75+
import static org.junit.Assume.assumeThat;
7476

7577
/**
7678
* Tests relating to the loss of the cluster-manager, but which work with the default fault detection settings which are rather lenient and will
@@ -195,6 +197,8 @@ private void testFollowerCheckerAfterClusterManagerReelection(NetworkLinkDisrupt
195197
* following another elected cluster-manager node. These nodes should reject this cluster state and prevent them from following the stale cluster-manager.
196198
*/
197199
public void testStaleClusterManagerNotHijackingMajority() throws Exception {
200+
assumeThat("Thread::resume / Thread::suspend are not supported anymore", Runtime.version(), lessThan(Runtime.Version.parse("20")));
201+
198202
final List<String> nodes = internalCluster().startNodes(
199203
3,
200204
Settings.builder()

server/src/main/java/org/opensearch/common/util/concurrent/BaseFuture.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public abstract class BaseFuture<V> implements Future<V> {
7474
*
7575
* @throws InterruptedException if the current thread was interrupted before
7676
* or during the call (optional but recommended).
77-
* @throws CancellationException {@inheritDoc}
77+
* @throws CancellationException if the computation was cancelled
7878
*/
7979
@Override
8080
public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException {
@@ -96,7 +96,7 @@ public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutEx
9696
*
9797
* @throws InterruptedException if the current thread was interrupted before
9898
* or during the call (optional but recommended).
99-
* @throws CancellationException {@inheritDoc}
99+
* @throws CancellationException if the computation was cancelled
100100
*/
101101
@Override
102102
public V get() throws InterruptedException, ExecutionException {

test/framework/src/main/java/org/opensearch/cluster/coordination/MockSinglePrioritizingExecutor.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,30 @@
4444
public class MockSinglePrioritizingExecutor extends PrioritizedOpenSearchThreadPoolExecutor {
4545

4646
public MockSinglePrioritizingExecutor(String name, DeterministicTaskQueue deterministicTaskQueue, ThreadPool threadPool) {
47-
super(name, 0, 1, 0L, TimeUnit.MILLISECONDS, r -> new Thread() {
48-
@Override
49-
public void start() {
50-
deterministicTaskQueue.scheduleNow(new Runnable() {
51-
@Override
52-
public void run() {
53-
try {
54-
r.run();
55-
} catch (KillWorkerError kwe) {
56-
// hacks everywhere
57-
}
47+
super(name, 0, 1, 0L, TimeUnit.MILLISECONDS, r -> {
48+
// This executor used to override Thread::start method so the actual runnable is
49+
// being scheduled in the scope of current thread of execution. In JDK-19, the Thread::start
50+
// is not called anymore (https://bugs.openjdk.org/browse/JDK-8292027) and there is no
51+
// suitable option to alter the executor's behavior in the similar way. The closest we
52+
// could get to is to schedule the runnable once the ThreadFactory is being asked to
53+
// allocate the new thread.
54+
deterministicTaskQueue.scheduleNow(new Runnable() {
55+
@Override
56+
public void run() {
57+
try {
58+
r.run();
59+
} catch (KillWorkerError kwe) {
60+
// hacks everywhere
5861
}
62+
}
5963

60-
@Override
61-
public String toString() {
62-
return r.toString();
63-
}
64-
});
65-
}
64+
@Override
65+
public String toString() {
66+
return r.toString();
67+
}
68+
});
69+
70+
return new Thread(() -> {});
6671
}, threadPool.getThreadContext(), threadPool.scheduler());
6772
}
6873

test/framework/src/test/java/org/opensearch/test/disruption/LongGCDisruptionTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import static org.hamcrest.Matchers.containsString;
4949
import static org.hamcrest.Matchers.equalTo;
5050
import static org.hamcrest.Matchers.greaterThan;
51+
import static org.hamcrest.Matchers.lessThan;
52+
import static org.junit.Assume.assumeThat;
5153

5254
public class LongGCDisruptionTests extends OpenSearchTestCase {
5355

@@ -65,6 +67,8 @@ public void executeLocked(Runnable r) {
6567
}
6668

6769
public void testBlockingTimeout() throws Exception {
70+
assumeThat("Thread::resume / Thread::suspend are not supported anymore", Runtime.version(), lessThan(Runtime.Version.parse("20")));
71+
6872
final String nodeName = "test_node";
6973
LongGCDisruption disruption = new LongGCDisruption(random(), nodeName) {
7074
@Override
@@ -125,6 +129,8 @@ protected long getSuspendingTimeoutInMillis() {
125129
* but does keep retrying until all threads can be safely paused
126130
*/
127131
public void testNotBlockingUnsafeStackTraces() throws Exception {
132+
assumeThat("Thread::resume / Thread::suspend are not supported anymore", Runtime.version(), lessThan(Runtime.Version.parse("20")));
133+
128134
final String nodeName = "test_node";
129135
LongGCDisruption disruption = new LongGCDisruption(random(), nodeName) {
130136
@Override
@@ -179,6 +185,8 @@ protected Pattern[] getUnsafeClasses() {
179185
}
180186

181187
public void testBlockDetection() throws Exception {
188+
assumeThat("Thread::resume / Thread::suspend are not supported anymore", Runtime.version(), lessThan(Runtime.Version.parse("20")));
189+
182190
final String disruptedNodeName = "disrupted_node";
183191
final String blockedNodeName = "blocked_node";
184192
CountDownLatch waitForBlockDetectionResult = new CountDownLatch(1);

0 commit comments

Comments
 (0)