Skip to content

Commit

Permalink
A new Jakarta EE test suite. Tests to reproduce #24059
Browse files Browse the repository at this point in the history
Tests are failing now as expected, need to fix the issue.
Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
  • Loading branch information
OndroMih committed Sep 4, 2022
1 parent 566fceb commit 98f392b
Show file tree
Hide file tree
Showing 11 changed files with 596 additions and 0 deletions.
13 changes: 13 additions & 0 deletions appserver/tests/jakartaee/concurrency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Set of tests that extend Jakarta Concurrency TCK

This test suite is based on the Jakarta Concurrency TCK runner and contains additional tests on top of the TCK. These tests intentionally follow the structure of the TCK so that they can be easily donated to the TCK in the future.

The package `org.glassfish.main.jakartaee.tests.concurrent` in this module matches the package `ee.jakarta.tck.concurrent` in the TCK.

## Running the test suite

```
mvn verify
```

Run in the same way as the Jakarta Concurrency TCK runner. By default, GlassFish Full Profile edition is tested.
257 changes: 257 additions & 0 deletions appserver/tests/jakartaee/concurrency/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.glassfish.main.tests.jakartaee</groupId>
<artifactId>jakartaee</artifactId>
<version>7.0.0-SNAPSHOT</version>
</parent>
<artifactId>jakarta.enterprise.concurrent-tck-ext</artifactId>
<name>GlassFish Concurrency tests</name>
<description>Contains additional tests on top of the Jakarta Concurrency TCK. This module is based on the org.glassfish.main.tests.tck:glassfish-external-tck-concurrency module - the GlassFish Concurrency TCK runner</description>

<properties>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<concurrency.tck-3-0.version>3.0.2</concurrency.tck-3-0.version>

<glassfish.version>${project.version}</glassfish.version>
<glassfish.root>${project.build.directory}</glassfish.root>
<glassfish.home>${glassfish.root}/glassfish7</glassfish.home>
<suiteXmlFile>suite.xml</suiteXmlFile>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.7.0.Alpha10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Jakarta EE APIs -->
<dependency>
<groupId>jakarta.enterprise.concurrent</groupId>
<artifactId>jakarta.enterprise.concurrent-api</artifactId>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>


<!-- The TCK -->
<dependency>
<groupId>jakarta.enterprise.concurrent</groupId>
<artifactId>jakarta.enterprise.concurrent-tck</artifactId>
<version>${concurrency.tck-3-0.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>jakarta.ejb</groupId>
<artifactId>jakarta.ejb-api</artifactId>
<scope>test</scope>
</dependency>

<!-- Utility classes for TestNG and Arquillian, used in suite.xml -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-core-impl</artifactId>
<version>4.0.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.test-audit</groupId>
<artifactId>jboss-test-audit-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.test-audit</groupId>
<artifactId>jboss-test-audit-api</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.faces</groupId>
<artifactId>jakarta.faces-api</artifactId>
</exclusion>
<exclusion>
<artifactId>container-se-api</artifactId>
<groupId>org.jboss.arquillian.container</groupId>
</exclusion>
</exclusions>
</dependency>

<!--
The Arquillian connector that starts GlassFish and deploys archives to it.
-->
<dependency>
<groupId>org.omnifaces.arquillian</groupId>
<artifactId>arquillian-glassfish-server-managed</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-glassfish</id>
<phase>test-compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<markersDirectory>${glassfish.root}/dependency-maven-plugin-markers</markersDirectory>
<artifactItems>
<artifactItem>
<groupId>org.glassfish.main.distributions</groupId>
<artifactId>${glassfish-artifact-id}</artifactId>
<version>${glassfish.version}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${glassfish.root}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${glassfish.root}/glassfish7/glassfish/lib</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.78</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${glassfish.root}/glassfish7/glassfish/lib</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.netbeans.tools</groupId>
<artifactId>sigtest-maven-plugin</artifactId>
<version>1.6</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${glassfish.root}/glassfish7/glassfish/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx768m</argLine>

<!-- Surefire / TestNG Properties -->
<!-- The suite, the exclude and the test dependencies together determine which tests are being run -->
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<dependenciesToScan>
<dependency>jakarta.enterprise.concurrent:jakarta.enterprise.concurrent-tck</dependency>
</dependenciesToScan>
<properties>
<property>
<name>surefire.testng.verbose</name>
<value>1</value>
</property>
</properties>
<forkMode>once</forkMode>

<!-- System Properties -->
<systemPropertyVariables>
<glassfish.home>${glassfish.root}/glassfish7</glassfish.home>
<glassfish.enableDerby>true</glassfish.enableDerby>
<glassfish.maxHeapSize>2048m</glassfish.maxHeapSize>

<!-- Remove comments for logging to file. Following logging with e.g. tail -f ConcurrentTCK00.log -->
<!--
<java.util.logging.config.file>${project.build.directory}/test-classes/logging.properties</java.util.logging.config.file>
-->
<glassfish.systemProperties>
jimage.dir=${project.build.directory}/jimage
</glassfish.systemProperties>

<glassfish.postBootCommands>
create-file-user --groups staff:mgr --passwordfile ${project.build.directory}/test-classes/j2ee.pass j2ee
create-file-user --groups Manager --passwordfile ${project.build.directory}/test-classes/javajoe.pass javajoe
</glassfish.postBootCommands>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M7</version>
<executions>
<execution>
<id>generate-test-report</id>
<phase>verify</phase>
<goals>
<goal>report-only</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/surefire-reports</outputDirectory>
<outputName>test-report</outputName>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>full</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<glassfish-artifact-id>glassfish</glassfish-artifact-id>
</properties>
</profile>
<profile>
<id>web</id>
<properties>
<glassfish-artifact-id>web</glassfish-artifact-id>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2021, 2022 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 org.glassfish.main.jakartaee.tests.concurrent.spec.ManagedExecutorService.resourcedef;

import ee.jakarta.tck.concurrent.spec.ContextService.contextPropagate.ContextServiceDefinitionServlet;

import ee.jakarta.tck.concurrent.common.context.IntContext;
import ee.jakarta.tck.concurrent.common.context.StringContext;
import ee.jakarta.tck.concurrent.framework.TestServlet;
import jakarta.enterprise.concurrent.ManagedExecutorDefinition;
import jakarta.enterprise.concurrent.ManagedExecutorService;
import jakarta.servlet.annotation.WebServlet;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import javax.naming.InitialContext;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

/**
* @ContextServiceDefinitions are defined under {@link ContextServiceDefinitionServlet}
*/
@ManagedExecutorDefinition(name = "java:module/concurrent/ExecutorB",
context = "java:module/concurrent/ContextB",
maxAsync = 1)
@WebServlet("/ManagedExecutorDefinitionServlet")
public class ManagedExecutorDefinitionServlet extends TestServlet {
private static final long serialVersionUID = 1L;
private static final long MAX_WAIT_SECONDS = TimeUnit.MINUTES.toSeconds(2);

/**
* ManagedExecutorService can create a contextualized copy of an unmanaged CompletableFuture (twice in a row).
*/
public void testCopyCompletableFutureTwice() throws Throwable {
copyCompletableFuture(273);
copyCompletableFuture(373);
}

private void copyCompletableFuture(int iContextValue) throws Throwable {
ManagedExecutorService executor = InitialContext.doLookup("java:module/concurrent/ExecutorB");

IntContext.set(iContextValue);
StringContext.set("testCopyCompletableFuture-1");
try {
CompletableFuture<Character> stage1unmanaged = new CompletableFuture<Character>();
CompletableFuture<Character> stage1copy = executor.copy(stage1unmanaged);
CompletableFuture<Character> permanentlyIncompleteStage = new CompletableFuture<Character>();

StringContext.set("testCopyCompletableFuture-2");

CompletableFuture<String> stage2 = stage1copy.applyToEitherAsync(permanentlyIncompleteStage, sep -> {
String s = StringContext.get();
return "StringContext " + ("testCopyCompletableFuture-2".equals(s) ? "propagated" : "incorrect:" + s)
+ sep;
});

StringContext.set("testCopyCompletableFuture-3");

CompletableFuture<String> stage3 = stage2.handleAsync((result, failure) -> {
if (failure == null) {
int i = IntContext.get();
return result + "IntContext " + (i == 0 ? "unchanged" : "incorrect:" + i);
} else {
throw (AssertionError) new AssertionError().initCause(failure);
}
});

assertTrue(stage1unmanaged.complete(';'),
"Completation stage that is supplied to copy must not be modified by the " +
"ManagedExecutorService.");

String result = stage3.get(MAX_WAIT_SECONDS, TimeUnit.SECONDS);
assertEquals(result, "StringContext propagated;IntContext unchanged",
"StringContext must be propagated and Application context and IntContext must be left " +
"unchanged per ManagedExecutorDefinition and ContextServiceDefinition config.");
} finally {
IntContext.set(0);;
StringContext.set(null);
}
}

}

0 comments on commit 98f392b

Please sign in to comment.