8220479: java/nio/channels/Selector/SelectWithConsumer.java failed at testTwoChannels()
Reviewed-by: bpb
Contributed-by: alan.bateman@oracle.com
--- a/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java Fri Nov 08 09:51:18 2019 -0500
+++ b/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java Fri Nov 08 08:12:04 2019 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -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);