diff --git a/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java b/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java --- a/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java +++ b/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java @@ -197,19 +197,21 @@ // write to sink to ensure that the source is readable sink.write(messageBuffer()); + // wait for key1 to be readable + sel.select(); + assertTrue(key2.isWritable()); + while (!key1.isReadable()) { + Thread.sleep(20); + sel.select(); + } + var counter = new AtomicInteger(); // select(Consumer) counter.set(0); int n = sel.select(k -> { + assertTrue(k == key1 || k == key2); counter.incrementAndGet(); - if (k == key1) { - assertTrue(k.isReadable()); - } else if (k == key2) { - assertTrue(k.isWritable()); - } else { - assertTrue(false); - } }); assertTrue(n == 2); assertTrue(counter.get() == 2); @@ -217,14 +219,8 @@ // select(Consumer, timeout) counter.set(0); n = sel.select(k -> { + assertTrue(k == key1 || k == key2); counter.incrementAndGet(); - if (k == key1) { - assertTrue(k.isReadable()); - } else if (k == key2) { - assertTrue(k.isWritable()); - } else { - assertTrue(false); - } }, 1000); assertTrue(n == 2); assertTrue(counter.get() == 2); @@ -232,14 +228,8 @@ // selectNow(Consumer) counter.set(0); n = sel.selectNow(k -> { + assertTrue(k == key1 || k == key2); counter.incrementAndGet(); - if (k == key1) { - assertTrue(k.isReadable()); - } else if (k == key2) { - assertTrue(k.isWritable()); - } else { - assertTrue(false); - } }); assertTrue(n == 2); assertTrue(counter.get() == 2);