Skip to content

Commit

Permalink
Merge pull request jakartaee#422 from KyleAure/404-qualifier-app-defi…
Browse files Browse the repository at this point in the history
…ned-producer

Finalize tck qualifer tests
  • Loading branch information
KyleAure authored Feb 5, 2024
2 parents 8df4fdc + 2289d05 commit 454d466
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,23 @@ protected String getServletPath() {
return "AnnotationServlet";
}

@Assertion(id = "GIT:404", strategy = "Tests injection of concurrent resources defined in a annotation with qualifier(s).")
public void testAnnotationDefinesQualifiers() {
@Assertion(id = "GIT:404", strategy = "Tests injection of context service defined in an annotation with qualifier(s).")
public void testAnnoDefinedContextServiceQualifiers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed executor service defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedExecutorSvcQualifiers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed scheduled exectuor service defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedScheduledExecutorSvcQualifers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed thread factory defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedThreadFactoryQualifers() {
runTest(baseURL, testname);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,6 @@ public class AnnotationServlet extends TestServlet {

@Resource
private UserTransaction tx;

// Context Services
@Inject
private ContextService injectedDefContextSvc;

@Inject
@CustomQualifier1
private ContextService injectedContextD;

// Managed Executor Services
@Inject
private ManagedExecutorService injectedDefMES;

@Inject
@CustomQualifier2
private ManagedExecutorService injectedMESD;

// Managed Scheduled Executor Services
@Inject
private ManagedScheduledExecutorService injectedDefMSES;

@Inject
@CustomQualifier1
@CustomQualifier2
private ManagedScheduledExecutorService injectedMSESD;

// Managed Thread Factory
@Inject
private ManagedThreadFactory injectedDefMTF;

@Resource(lookup = "java:app/concurrent/ThreadFactoryE")
private ManagedThreadFactory resourceMTFD;

private Integer executeCallableWithContext(final ContextService svc, final int value) throws Exception {
try {
Expand All @@ -136,73 +104,145 @@ private Integer executeCallableWithContext(final ContextService svc, final int v
IntContext.set(0);
}
}

// Context Services
@Inject
private ContextService injectedDefContextSvc;

@SuppressWarnings("unused")
public void testAnnotationDefinesQualifiers() throws Throwable {
@Inject
@CustomQualifier1
private ContextService injectedContextE;

public void testAnnoDefinedContextServiceQualifiers() throws Throwable {
assertAll("Context Service Tests",
() -> assertNotNull(injectedDefContextSvc,
"Default contextService was not registered with default qualifier."),
() -> assertNotNull(injectedContextD,
() -> assertNotNull(injectedContextE,
"Annotation defined contextService was not registered with required qualifier."),
() -> assertTrue(CDI.current().select(ContextService.class, InvalidQualifier3.Literal.get()).isUnsatisfied(),
"A contextService was satisfied with a qualifier which was not defined in it's annotation")
);

// Verify injected and lookup default context service are the same
// Verify injected and looked up default context service are the same
ContextService lookupDefContextSvc = InitialContext.doLookup("java:comp/DefaultContextService");

Integer expected1 = executeCallableWithContext(lookupDefContextSvc, 95);
Integer actual1 = executeCallableWithContext(injectedDefContextSvc, 95);

assertEquals(expected1, actual1, "Default Context Service behavior differed between injection and lookup");

// Verify injected and lookup annotation defined context service are the same
ContextService lookupContextD = InitialContext.doLookup("java:app/concurrent/ContextD");
// Verify injected and looked up annotation defined context service are the same
ContextService lookupContextE = InitialContext.doLookup("java:app/concurrent/ContextE");

assertEquals(Integer.valueOf(0), executeCallableWithContext(lookupContextD, 65),
assertEquals(Integer.valueOf(0), executeCallableWithContext(lookupContextE, 65),
"Annotation defined Context Service that was looked up did not clear the IntContext as configured.");
assertEquals(Integer.valueOf(0), executeCallableWithContext(injectedContextD, 85),
assertEquals(Integer.valueOf(0), executeCallableWithContext(injectedContextE, 85),
"Annotation defined Context Service that was injected based on a qualifier did not clear the IntContext as configured.");
}

// Managed Executor Services
@Inject
private ManagedExecutorService injectedDefMES;

ManagedExecutorService lookupDefMES = InitialContext.doLookup("java:comp/DefaultManagedExecutorService");
ManagedExecutorService lookupMESD = InitialContext.doLookup("java:app/concurrent/ExecutorE");

@Inject
@CustomQualifier2
private ManagedExecutorService injectedMESE;

public void testAnnoDefinedManagedExecutorSvcQualifiers() throws Throwable {
assertAll("Managed Executor Service Tests",
() -> assertNotNull(injectedDefMES,
"Default managedExecutorService was not registered with default qualifier."),
() -> assertNotNull(injectedMESD,
() -> assertNotNull(injectedMESE,
"Annotation defined managedExecutorService was not registered with required qualifiers."),
() -> assertTrue(CDI.current().select(ManagedExecutorService.class, CustomQualifier2.Literal.get(), InvalidQualifier3.Literal.get()).isUnsatisfied(),
"A managedExecutorService was satisfied with both a required and non-required qualifier.")
);

//TODO verify injected vs lookup services behave the same
// Verify injected and looked up default ManagedExecutorService behave the same
ManagedExecutorService lookupDefMES = InitialContext.doLookup("java:comp/DefaultManagedExecutorService");

ManagedScheduledExecutorService lookupDefMSES = InitialContext.doLookup("java:comp/DefaultManagedScheduledExecutorService");
ManagedScheduledExecutorService lookupMSESD = InitialContext.doLookup("java:app/concurrent/ScheduledExecutorE");
ContextService lookupDefContextSvc = lookupDefMES.getContextService();
ContextService extractedDefContextSvc = injectedDefMES.getContextService();

Integer expected1 = executeCallableWithContext(lookupDefContextSvc, 95);
Integer actual1 = executeCallableWithContext(extractedDefContextSvc, 95);

assertEquals(expected1, actual1, "Default ManagedExecutorService behavior via context service differed between injection and lookup");

// Verify injected and looked up annotation defined ManagedExecutorService behave the same
ManagedExecutorService lookupMESE = InitialContext.doLookup("java:app/concurrent/ExecutorE");

ContextService lookupContextE = lookupMESE.getContextService();
ContextService extractedContextE = injectedMESE.getContextService();

assertEquals(Integer.valueOf(0), executeCallableWithContext(lookupContextE, 65),
"Annotation defined and looked up ManagedExecutorService was configured with a context service that did not clear the IntContext as configured.");
assertEquals(Integer.valueOf(0), executeCallableWithContext(extractedContextE, 85),
"Annotation defined and injected ManagedExecutorService was configured with a context service that did not clear the IntContext as configured.");
}

// Managed Scheduled Executor Services
@Inject
private ManagedScheduledExecutorService injectedDefMSES;

@Inject
@CustomQualifier1
@CustomQualifier2
private ManagedScheduledExecutorService injectedMSESE;

public void testAnnoDefinedManagedScheduledExecutorSvcQualifers() throws Throwable {
assertAll("Managed Scheduled Executor Service Tests",
() -> assertNotNull(injectedDefMSES,
"Default managedScheduledExecutorService was not registered with default qualifier."),
() -> assertNotNull(injectedMSESD,
() -> assertNotNull(injectedMSESE,
"Annotation defined managedScheduledExecutorService was not registered with required qualifiers."),
() -> assertTrue(CDI.current().select(ManagedScheduledExecutorService.class, CustomQualifier1.Literal.get()).isResolvable(),
"A managedScheduledExecutorService was not satisfied with one of two configured qualifiers.")
);

//TODO verify injected vs lookup services behave the same
// Verify injected and looked up default ManagedScheduledExecutorService behave the same
ManagedScheduledExecutorService lookupDefMSES = InitialContext.doLookup("java:comp/DefaultManagedScheduledExecutorService");

ManagedThreadFactory lookupDefMTF = InitialContext.doLookup("java:comp/DefaultManagedThreadFactory");
ManagedThreadFactory lookupMTFD = InitialContext.doLookup("java:app/concurrent/ThreadFactoryE");
ContextService lookupDefContextSvc = lookupDefMSES.getContextService();
ContextService extractedDefContextSvc = injectedDefMSES.getContextService();

Integer expected1 = executeCallableWithContext(lookupDefContextSvc, 95);
Integer actual1 = executeCallableWithContext(extractedDefContextSvc, 95);

assertEquals(expected1, actual1, "Default ManagedScheduledExecutorService behavior via context service differed between injection and lookup");

// Verify injected and looked up annotation defined ManagedExecutorService behave the same
ManagedScheduledExecutorService lookupMSESE = InitialContext.doLookup("java:app/concurrent/ScheduledExecutorE");

ContextService lookupContextE = lookupMSESE.getContextService();
ContextService extractedContextE = injectedMSESE.getContextService();

assertEquals(Integer.valueOf(0), executeCallableWithContext(lookupContextE, 65),
"Annotation defined and looked up ManagedScheduledExecutorService was configured with a context service that did not clear the IntContext as configured.");
assertEquals(Integer.valueOf(0), executeCallableWithContext(extractedContextE, 85),
"Annotation defined and injected ManagedScheduledExecutorService was configured with a context service that did not clear the IntContext as configured.");
}

// Managed Thread Factory
@Inject
private ManagedThreadFactory injectedDefMTF;

@Resource(lookup = "java:app/concurrent/ThreadFactoryE")
private ManagedThreadFactory resourceMTFE;

public void testAnnoDefinedManagedThreadFactoryQualifers() throws Throwable {

ManagedThreadFactory lookupDefMTF = InitialContext.doLookup("java:comp/DefaultManagedThreadFactory");
ManagedThreadFactory lookupMTFE = InitialContext.doLookup("java:app/concurrent/ThreadFactoryD");

assertAll("Thread Factory Tests",
() -> assertNotNull(injectedDefMTF,
"Default managedThreadFactory was not registered with default qualifier."),
() -> assertEquals(lookupDefMTF.newThread(NOOP_RUNNABLE).getPriority(), injectedDefMTF.newThread(NOOP_RUNNABLE).getPriority(),
"Default managedThreadFactory from injection and lookup did not have the same priority."),
() -> assertNotNull(resourceMTFD,
() -> assertNotNull(resourceMTFE,
"Annotation defined managedThreadFactory with no qualifiers could not be found via @Resource."),
() -> assertEquals(lookupMTFD.newThread(NOOP_RUNNABLE).getPriority(), resourceMTFD.newThread(NOOP_RUNNABLE).getPriority(),
() -> assertEquals(lookupMTFE.newThread(NOOP_RUNNABLE).getPriority(), resourceMTFE.newThread(NOOP_RUNNABLE).getPriority(),
"The managedThreadFactory from resource injection and lookup did not have the same priority."),
() -> assertTrue(CDI.current().select(ManagedThreadFactory.class, InvalidQualifier3.Literal.get()).isUnsatisfied(),
"A managedThreadFactory was satisfied with a required qualifier that should have been overriden by the deployment descriptor.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,23 @@ protected String getServletPath() {
return "AnnotationServlet";
}

@Assertion(id = "GIT:404", strategy = "Tests injection of concurrent resources defined in a annotation with qualifier(s).")
public void testAnnotationDefinesQualifiers() {
@Assertion(id = "GIT:404", strategy = "Tests injection of context service defined in an annotation with qualifier(s).")
public void testAnnoDefinedContextServiceQualifiers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed executor service defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedExecutorSvcQualifiers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed scheduled exectuor service defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedScheduledExecutorSvcQualifers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed thread factory defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedThreadFactoryQualifers() {
runTest(baseURL, testname);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<!-- TODO update to 11 -->
<application version="10"
<application version="11"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_10.xsd">
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_11.xsd">

<module>
<web>
Expand All @@ -34,7 +33,7 @@
</module>

<managed-thread-factory>
<name>java:app/concurrent/ThreadFactoryD</name>
<name>java:app/concurrent/ThreadFactoryE</name>
<qualifier></qualifier> <!-- Overrides qualifiers defined in ManagedThreadFactoryDefinition -->
</managed-thread-factory>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<!-- TODO update to 11 once schema is released -->
<web-app
version="6.0"
version="6.1"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_1.xsd">

<managed-thread-factory>
<name>java:app/concurrent/ThreadFactoryD</name>
<name>java:app/concurrent/ThreadFactoryE</name>
<qualifier></qualifier> <!-- Overrides qualifiers defined in ManagedThreadFactoryDefinition -->
</managed-thread-factory>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class DeploymentDescriptorFullTests extends TestClient {
public static EnterpriseArchive createDeployment() {

WebArchive war = ShrinkWrap.create(WebArchive.class, "DeploymentDescriptorTests_web.war")
.addClasses(DeploymentDescriptorServlet.class);
.addClasses(DeploymentDescriptorServlet.class, ManagedThreadFactoryProducer.class);

JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "DeploymentDescriptorTests_ejb.jar")
.addClasses(DeploymentDescriptorTestBean.class, DeploymentDescriptorTestBeanInterface.class)
Expand All @@ -77,8 +77,23 @@ protected String getServletPath() {
return "DeploymentDescriptorServlet";
}

@Assertion(id = "GIT:404", strategy = "Tests injection of concurrent resources defined in a deployment descriptor with qualifier(s).")
public void testDeploymentDescriptorDefinesQualifiers() {
@Assertion(id = "GIT:404", strategy = "Tests injection of context service defined in a deployment descriptor with qualifier(s).")
public void testDeploymentDescriptorDefinedContextServiceQualifiers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed executor service defined in a deployment descriptor with qualifier(s).")
public void testDeploymentDescriptorDefinedManagedExecutorSvcQualifiers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed scheduled exectuor service defined in a deployment descriptor with qualifier(s).")
public void testDeploymentDescriptorDefinedManagedScheduledExecutorSvcQualifers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed thread factory defined in a deployment descriptor with qualifier(s).")
public void testDeploymentDescriptorDefinedManagedThreadFactoryQualifers() {
runTest(baseURL, testname);
}

Expand Down
Loading

0 comments on commit 454d466

Please sign in to comment.