From 9ba04becb16ec5691f3d9415b98483f00611dce3 Mon Sep 17 00:00:00 2001 From: Kyle Aure Date: Fri, 22 Mar 2024 15:55:58 -0500 Subject: [PATCH 1/2] Fix virtual tests for Java 17 --- .../virtual/VirtualThreadServlet.java | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java index b8b4c1fb..3ef8bf7f 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java @@ -79,14 +79,18 @@ public void testPlatformExecutor() throws Exception { assertNotNull(platformManagedExecutorAnno); assertNotNull(platformManagedExecutorDD); + + Thread annoThread = platformManagedExecutorAnno.submit(Thread::currentThread).get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS); + Thread ddThread = platformManagedExecutorDD.submit(Thread::currentThread).get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS); + + if (VERSION == 17) { //TODO remove when Concurrency API supports only 21+ + assertThrows(NoSuchMethodException.class, () -> isVirtual(annoThread), "Should be impossible to get a virtual thread on Java 17"); + assertThrows(NoSuchMethodException.class, () -> isVirtual(ddThread), "Should be impossible to get a virtual thread on Java 17"); + return; + } - Future future; - - future = platformManagedExecutorAnno.submit(Thread::currentThread); - assertFalse(isVirtual(future.get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS))); - - future = platformManagedExecutorDD.submit(Thread::currentThread); - assertFalse(isVirtual(future.get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS))); + assertFalse(isVirtual(annoThread)); + assertFalse(isVirtual(ddThread)); } public void testVirtualExecutor() throws Exception { @@ -178,13 +182,17 @@ public void testPlatformScheduledExecutor() throws Exception { assertNotNull(platformManagedScheduledExecutorAnno); assertNotNull(platformManagedScheduledExecutorDD); - Future future; - - future = platformManagedScheduledExecutorAnno.submit(Thread::currentThread); - assertFalse(isVirtual(future.get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS))); + Thread annoThread = platformManagedScheduledExecutorAnno.submit(Thread::currentThread).get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS); + Thread ddThread = platformManagedScheduledExecutorDD.submit(Thread::currentThread).get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS); + + if (VERSION == 17) { //TODO remove when Concurrency API supports only 21+ + assertThrows(NoSuchMethodException.class, () -> isVirtual(annoThread), "Should be impossible to get a virtual thread on Java 17"); + assertThrows(NoSuchMethodException.class, () -> isVirtual(ddThread), "Should be impossible to get a virtual thread on Java 17"); + return; + } - future = platformManagedScheduledExecutorDD.submit(Thread::currentThread); - assertFalse(isVirtual(future.get(TestConstants.waitTimeout.toMillis(), TimeUnit.MILLISECONDS))); + assertFalse(isVirtual(annoThread)); + assertFalse(isVirtual(ddThread)); } public void testVirtualScheduledExecutor() throws Exception { @@ -300,10 +308,19 @@ public void testPlatformThreadFactory() throws Exception { assertNotNull(platfromThreadFactoryAnno); assertNotNull(platfromThreadFactoryDD); + + Thread annoThread = platfromThreadFactoryAnno.newThread(NOOP_RUNNABLE); + Thread ddThread = platfromThreadFactoryDD.newThread(NOOP_RUNNABLE); + + if (VERSION == 17) { //TODO remove when Concurrency API supports only 21+ + assertThrows(NoSuchMethodException.class, () -> isVirtual(annoThread), "Should be impossible to get a virtual thread on Java 17"); + assertThrows(NoSuchMethodException.class, () -> isVirtual(ddThread), "Should be impossible to get a virtual thread on Java 17"); + return; + } - assertFalse(isVirtual(platfromThreadFactoryAnno.newThread(NOOP_RUNNABLE)), + assertFalse(isVirtual(annoThread), "Thread Factory should not have returned a virtual thread when defined with virtual=false"); - assertFalse(isVirtual(platfromThreadFactoryDD.newThread(NOOP_RUNNABLE)), + assertFalse(isVirtual(ddThread), "Thread Factory should not have returned a virtual thread when defined with virtual=false"); } From bd333d44521ee56352a42be02355f5095f9cae8d Mon Sep 17 00:00:00 2001 From: Kyle Aure Date: Fri, 22 Mar 2024 16:30:21 -0500 Subject: [PATCH 2/2] typo --- .../spec/Platform/virtual/VirtualThreadServlet.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java index 3ef8bf7f..8a75161c 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/Platform/virtual/VirtualThreadServlet.java @@ -301,16 +301,16 @@ public void testVirtualScheduledExecutor() throws Exception { } public void testPlatformThreadFactory() throws Exception { - ManagedThreadFactory platfromThreadFactoryAnno = InitialContext + ManagedThreadFactory platformThreadFactoryAnno = InitialContext .doLookup("java:app/concurrent/ThreadFactoryAnnoPlatform"); - ManagedThreadFactory platfromThreadFactoryDD = InitialContext + ManagedThreadFactory platformThreadFactoryDD = InitialContext .doLookup("java:app/concurrent/ThreadFactoryDDPlatform"); - assertNotNull(platfromThreadFactoryAnno); - assertNotNull(platfromThreadFactoryDD); + assertNotNull(platformThreadFactoryAnno); + assertNotNull(platformThreadFactoryDD); - Thread annoThread = platfromThreadFactoryAnno.newThread(NOOP_RUNNABLE); - Thread ddThread = platfromThreadFactoryDD.newThread(NOOP_RUNNABLE); + Thread annoThread = platformThreadFactoryAnno.newThread(NOOP_RUNNABLE); + Thread ddThread = platformThreadFactoryDD.newThread(NOOP_RUNNABLE); if (VERSION == 17) { //TODO remove when Concurrency API supports only 21+ assertThrows(NoSuchMethodException.class, () -> isVirtual(annoThread), "Should be impossible to get a virtual thread on Java 17");