-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #154 initial set of new TCK test scenarios
Signed-off-by: Nathan Rauh <nathan.rauh@us.ibm.com>
- Loading branch information
Showing
14 changed files
with
2,497 additions
and
0 deletions.
There are no files selected for viewing
559 changes: 559 additions & 0 deletions
559
...rise/concurrent/spec/ContextService/contextPropagate/ContextServiceDefinitionServlet.java
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
.../java/jakarta/enterprise/concurrent/spec/ManagedExecutorService/asynchronous/AppBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package jakarta.enterprise.concurrent.spec.ManagedExecutorService.asynchronous; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionException; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.Exchanger; | ||
import java.util.concurrent.Semaphore; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import jakarta.enterprise.concurrent.Asynchronous; | ||
import jakarta.enterprise.concurrent.spec.context.IntContext; | ||
import jakarta.enterprise.concurrent.spec.context.StringContext; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class AppBean { | ||
private static final long MAX_WAIT_SECONDS = TimeUnit.MINUTES.toSeconds(2); | ||
|
||
@Asynchronous(executor = "java:module/concurrent/ExecutorB") | ||
public CompletionStage<String> addStringContextAndWait(BlockingQueue<String> queue, CountDownLatch blocker) { | ||
String s = StringContext.get(); | ||
try { | ||
queue.add(s); | ||
blocker.await(MAX_WAIT_SECONDS, TimeUnit.SECONDS); | ||
return Asynchronous.Result.complete(s); | ||
} catch (Exception x) { | ||
throw new CompletionException(x); | ||
} | ||
} | ||
|
||
@Asynchronous | ||
public void exchange(Exchanger<String> exchanger, String value) { | ||
try { | ||
exchanger.exchange(value, MAX_WAIT_SECONDS, TimeUnit.SECONDS); | ||
} catch (InterruptedException | TimeoutException x) { | ||
throw new CompletionException(x); | ||
} | ||
} | ||
|
||
@Asynchronous(executor = "java:app/concurrent/ExecutorA") | ||
public CompletableFuture<Integer> waitAndGetIntContext(Semaphore started, CountDownLatch blocker) { | ||
started.release(1); | ||
CompletableFuture<Integer> future = Asynchronous.Result.getFuture(); | ||
try { | ||
while (!future.isDone() && !blocker.await(300, TimeUnit.MILLISECONDS)) | ||
System.out.println(Thread.currentThread().getName() + | ||
": waitAndGetIntContext awaiting signal from caller"); | ||
future.complete(IntContext.get()); | ||
} catch (Exception x) { | ||
future.completeExceptionally(x); | ||
} | ||
return future; | ||
} | ||
} |
559 changes: 559 additions & 0 deletions
559
.../concurrent/spec/ManagedExecutorService/resourcedef/ManagedExecutorDefinitionServlet.java
Large diffs are not rendered by default.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
...arta/enterprise/concurrent/spec/ManagedScheduledExecutorService/asynchronous/ReqBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package jakarta.enterprise.concurrent.spec.ManagedScheduledExecutorService.asynchronous; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionException; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.Semaphore; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.enterprise.concurrent.Asynchronous; | ||
import jakarta.enterprise.concurrent.ContextService; | ||
import jakarta.enterprise.concurrent.spec.context.IntContext; | ||
import jakarta.enterprise.concurrent.spec.context.StringContext; | ||
import jakarta.enterprise.context.RequestScoped; | ||
|
||
import javax.naming.InitialContext; | ||
import javax.naming.NamingException; | ||
|
||
@RequestScoped | ||
public class ReqBean { | ||
private static final long MAX_WAIT_SECONDS = TimeUnit.MINUTES.toSeconds(2); | ||
|
||
@Asynchronous(executor = "java:app/concurrent/ScheduledExecutorA") | ||
public CompletableFuture<String> awaitAndGetThirdPartyContext(Semaphore invocationsStarted, | ||
CountDownLatch blocker) { | ||
invocationsStarted.release(1); | ||
CompletableFuture<String> future = Asynchronous.Result.getFuture(); | ||
try { | ||
blocker.await(MAX_WAIT_SECONDS, TimeUnit.SECONDS); | ||
future.complete(IntContext.get() + StringContext.get()); | ||
} catch (Exception x) { | ||
future.completeExceptionally(x); | ||
} | ||
return future; | ||
} | ||
|
||
@Asynchronous(executor = "java:comp/concurrent/ScheduledExecutorC") | ||
public CompletionStage<ContextService> lookUpAContextService() { | ||
try { | ||
return CompletableFuture.completedFuture(InitialContext.doLookup("java:comp/concurrent/ContextC")); | ||
} catch (NamingException x) { | ||
throw new CompletionException(x); | ||
} | ||
} | ||
|
||
public CompletableFuture<String> notAsynchronous() { | ||
return CompletableFuture.completedFuture(Thread.currentThread().getName()); | ||
} | ||
} |
Oops, something went wrong.