Skip to content

Commit 372b7f5

Browse files
committed
More tests for @lra defined at the class level are needed
1 parent 18eb64d commit 372b7f5

File tree

3 files changed

+243
-0
lines changed

3 files changed

+243
-0
lines changed

tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTests.java

+62
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import static org.eclipse.microprofile.lra.tck.participant.api.AfterLRAListener.AFTER_LRA_LISTENER_WORK;
2525
import static org.eclipse.microprofile.lra.tck.participant.api.AfterLRAParticipant.AFTER_LRA_PARTICIPANT_PATH;
2626
import static org.eclipse.microprofile.lra.tck.participant.api.AfterLRAParticipant.AFTER_LRA_PARTICIPANT_WORK;
27+
import static org.eclipse.microprofile.lra.tck.participant.api.LRAOnClassParticipant.LRA_PARTICIPANT_PATH;
28+
import static org.eclipse.microprofile.lra.tck.participant.api.LRAOnClassParticipant.LRA_PARTICIPANT_WORK;
29+
import static org.eclipse.microprofile.lra.tck.participant.api.LRAOnClassParticipantCompensate.LRA_PARTICIPANT_PATH_COMPENSATE;
30+
import static org.eclipse.microprofile.lra.tck.participant.api.LRAOnClassParticipantCompensate.LRA_PARTICIPANT_START;
2731
import static org.eclipse.microprofile.lra.tck.participant.api.LraResource.ACCEPT_WORK;
2832
import static org.eclipse.microprofile.lra.tck.participant.api.LraResource.CANCEL_PATH;
2933
import static org.eclipse.microprofile.lra.tck.participant.api.LraResource.LRA_RESOURCE_PATH;
@@ -47,9 +51,12 @@
4751
import java.util.stream.IntStream;
4852

4953
import org.eclipse.microprofile.lra.annotation.AfterLRA;
54+
import org.eclipse.microprofile.lra.annotation.ws.rs.LRA;
5055
import org.eclipse.microprofile.lra.tck.participant.api.AfterLRAListener;
5156
import org.eclipse.microprofile.lra.tck.participant.api.AfterLRAParticipant;
5257
import org.eclipse.microprofile.lra.tck.participant.api.GenericLRAException;
58+
import org.eclipse.microprofile.lra.tck.participant.api.LRAOnClassParticipant;
59+
import org.eclipse.microprofile.lra.tck.participant.api.LRAOnClassParticipantCompensate;
5360
import org.eclipse.microprofile.lra.tck.participant.api.LraResource;
5461
import org.eclipse.microprofile.lra.tck.participant.api.NoLRAResource;
5562
import org.eclipse.microprofile.lra.tck.participant.api.ParticipatingTckResource;
@@ -698,4 +705,59 @@ private void multiLevelNestedActivity(CompletionType how, int nestedCnt) throws
698705
resourcePath.getUri() + ")", 1);
699706
}
700707
}
708+
709+
/**
710+
* TCK test to verify that classes annotated with {@link LRA} are notified correctly the participant has afterLRA
711+
* method
712+
*
713+
* @throws InterruptedException
714+
* when waiting for the finishing the callbacks is interrupted
715+
*/
716+
@Test
717+
public void testLRAParticipantAnnotationOnClass() throws WebApplicationException, InterruptedException {
718+
URI lra = lraClient.startLRA(null, lraClientId(), lraTimeout(), ChronoUnit.MILLIS);
719+
WebTarget resourcePath = tckSuiteTarget.path(LRA_PARTICIPANT_PATH).path(LRA_PARTICIPANT_WORK);
720+
Response response = resourcePath
721+
.request().header(LRA_HTTP_CONTEXT_HEADER, lra).put(Entity.text(""));
722+
checkStatusAndCloseResponse(Response.Status.OK, response, resourcePath);
723+
lraClient.closeLRA(lra);
724+
lraTestService.waitForCallbacks(lra);
725+
726+
// verify that the LRA is now in one of the terminal states
727+
lraMetric.assertFinished("testLRAParticipantAnnotationOnClass: LRA did not finish", lra,
728+
LRAOnClassParticipant.class);
729+
730+
// verify that the resource was notified of the final state of the LRA
731+
lraMetric.assertClosed("testLRAParticipantAnnotationOnClass: end synchronization was not invoked on resource " +
732+
resourcePath.getUri(), lra, LRAOnClassParticipant.class);
733+
}
734+
735+
/**
736+
* TCK test to verify that classes annotated with {@link LRA} are notified correctly the participant has afterLRA
737+
* and compensate methods
738+
*
739+
* @throws InterruptedException
740+
* when waiting for the finishing the callbacks is interrupted
741+
*/
742+
@Test
743+
public void testLRAParticipantAnnotationOnClassWithCompensate()
744+
throws WebApplicationException, InterruptedException {
745+
URI lra = lraClient.startLRA(null, lraClientId(), lraTimeout(), ChronoUnit.MILLIS);
746+
WebTarget resourcePath = tckSuiteTarget.path(LRA_PARTICIPANT_PATH_COMPENSATE).path(LRA_PARTICIPANT_START);
747+
Response response = resourcePath
748+
.request().header(LRA_HTTP_CONTEXT_HEADER, lra).put(Entity.text(""));
749+
checkStatusAndCloseResponse(Response.Status.OK, response, resourcePath);
750+
lraClient.closeLRA(lra);
751+
lraTestService.waitForCallbacks(lra);
752+
753+
// verify that the LRA is now in one of the terminal states
754+
lraMetric.assertFinished("testLRAParticipantAnnotationOnClassWithCompensate: LRA did not finish", lra,
755+
LRAOnClassParticipantCompensate.class);
756+
757+
// verify that the resource was notified of the final state of the LRA
758+
lraMetric.assertClosed(
759+
"testLRAParticipantAnnotationOnClassWithCompensate: end synchronization was not invoked on resource " +
760+
resourcePath.getUri(),
761+
lra, LRAOnClassParticipantCompensate.class);
762+
}
701763
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**********************************************************************
2+
* Copyright (c) 2022 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICES file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
* SPDX-License-Identifier: Apache-2.0
20+
**********************************************************************/package org.eclipse.microprofile.lra.tck.participant.api;
21+
package org.eclipse.microprofile.lra.tck.participant.api;
22+
23+
import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER;
24+
import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_ENDED_CONTEXT_HEADER;
25+
import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER;
26+
27+
import java.net.URI;
28+
29+
import org.eclipse.microprofile.lra.LRAResponse;
30+
import org.eclipse.microprofile.lra.annotation.AfterLRA;
31+
import org.eclipse.microprofile.lra.annotation.Complete;
32+
import org.eclipse.microprofile.lra.annotation.LRAStatus;
33+
import org.eclipse.microprofile.lra.annotation.ws.rs.LRA;
34+
import org.eclipse.microprofile.lra.tck.service.LRAMetricService;
35+
import org.eclipse.microprofile.lra.tck.service.LRAMetricType;
36+
import org.eclipse.microprofile.lra.tck.service.LRATestService;
37+
38+
import jakarta.enterprise.context.ApplicationScoped;
39+
import jakarta.inject.Inject;
40+
import jakarta.ws.rs.HeaderParam;
41+
import jakarta.ws.rs.PUT;
42+
import jakarta.ws.rs.Path;
43+
import jakarta.ws.rs.core.Response;
44+
45+
/**
46+
* resource for testing that methods annotated with {@link AfterLRA} are notified correctly when an LRA terminates
47+
*/
48+
@ApplicationScoped
49+
@LRA(value = LRA.Type.REQUIRED)
50+
@Path(LRAOnClassParticipant.LRA_PARTICIPANT_PATH)
51+
public class LRAOnClassParticipant {
52+
public static final String LRA_PARTICIPANT_PATH = "lra-participant-class-annotation";
53+
public static final String LRA_PARTICIPANT_WORK = "work";
54+
55+
private static final String AFTER_LRA = "/after";
56+
57+
@Inject
58+
private LRAMetricService lraMetricService;
59+
60+
@Inject
61+
private LRATestService lraTestService;
62+
63+
@PUT
64+
@Path("/complete")
65+
@Complete
66+
public Response completeWork(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
67+
lraMetricService.incrementMetric(LRAMetricType.Completed, lraId, LRAOnClassParticipant.class);
68+
return LRAResponse.completed();
69+
}
70+
71+
@PUT
72+
@Path(LRA_PARTICIPANT_WORK)
73+
@LRA(value = LRA.Type.REQUIRED, end = false)
74+
public Response activityWithLRA(@HeaderParam(LRA_HTTP_RECOVERY_HEADER) URI recoveryId,
75+
@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
76+
return Response.ok().build();
77+
}
78+
79+
@PUT
80+
@Path(AFTER_LRA)
81+
@AfterLRA // this method will be called when the LRA associated with the method activityWithLRA finishes
82+
public Response afterEnd(@HeaderParam(LRA_HTTP_ENDED_CONTEXT_HEADER) URI lraId, LRAStatus status) {
83+
return lraTestService.processAfterLRAInfo(lraId, status, LRAOnClassParticipant.class,
84+
LRA_PARTICIPANT_PATH + AFTER_LRA);
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**********************************************************************
2+
* Copyright (c) 2022 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICES file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
* SPDX-License-Identifier: Apache-2.0
20+
**********************************************************************/package org.eclipse.microprofile.lra.tck.participant.api;
21+
import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER;
22+
import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_ENDED_CONTEXT_HEADER;
23+
import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER;
24+
25+
import java.net.URI;
26+
27+
import org.eclipse.microprofile.lra.LRAResponse;
28+
import org.eclipse.microprofile.lra.annotation.AfterLRA;
29+
import org.eclipse.microprofile.lra.annotation.Compensate;
30+
import org.eclipse.microprofile.lra.annotation.Complete;
31+
import org.eclipse.microprofile.lra.annotation.LRAStatus;
32+
import org.eclipse.microprofile.lra.annotation.ws.rs.LRA;
33+
import org.eclipse.microprofile.lra.tck.service.LRAMetricService;
34+
import org.eclipse.microprofile.lra.tck.service.LRAMetricType;
35+
import org.eclipse.microprofile.lra.tck.service.LRATestService;
36+
37+
import jakarta.enterprise.context.ApplicationScoped;
38+
import jakarta.inject.Inject;
39+
import jakarta.ws.rs.HeaderParam;
40+
import jakarta.ws.rs.PUT;
41+
import jakarta.ws.rs.Path;
42+
import jakarta.ws.rs.core.Response;
43+
44+
/**
45+
* resource for testing that methods annotated with {@link AfterLRA} are notified correctly when an LRA terminates
46+
*/
47+
@ApplicationScoped
48+
@LRA(value = LRA.Type.REQUIRES_NEW)
49+
@Path(LRAOnClassParticipantCompensate.LRA_PARTICIPANT_PATH_COMPENSATE)
50+
public class LRAOnClassParticipantCompensate {
51+
public static final String LRA_PARTICIPANT_PATH_COMPENSATE = "lra-participant-compensate-class-annotation";
52+
public static final String LRA_PARTICIPANT_START = "work";
53+
54+
private static final String AFTER_LRA = "/after";
55+
56+
@Inject
57+
private LRAMetricService lraMetricService;
58+
59+
@Inject
60+
private LRATestService lraTestService;
61+
62+
@PUT
63+
@Path("/complete")
64+
@Complete
65+
public Response completeWork(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
66+
lraMetricService.incrementMetric(LRAMetricType.Completed, lraId, LRAOnClassParticipantCompensate.class);
67+
return LRAResponse.completed();
68+
}
69+
70+
@PUT
71+
@Path("/compensate")
72+
@Compensate
73+
public Response compensateWork(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
74+
lraMetricService.incrementMetric(LRAMetricType.Compensated, lraId, LRAOnClassParticipant.class);
75+
76+
return LRAResponse.compensated();
77+
}
78+
79+
@PUT
80+
@Path(LRA_PARTICIPANT_START)
81+
@LRA(value = LRA.Type.REQUIRED, end = false)
82+
public Response activityWithLRA(@HeaderParam(LRA_HTTP_RECOVERY_HEADER) URI recoveryId,
83+
@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
84+
return Response.ok().build();
85+
}
86+
87+
@PUT
88+
@Path(AFTER_LRA)
89+
@AfterLRA // this method will be called when the LRA associated with the method
90+
// activityWithLRA finishes
91+
public Response afterEnd(@HeaderParam(LRA_HTTP_ENDED_CONTEXT_HEADER) URI lraId, LRAStatus status) {
92+
return lraTestService.processAfterLRAInfo(lraId, status, LRAOnClassParticipantCompensate.class,
93+
LRA_PARTICIPANT_PATH_COMPENSATE + AFTER_LRA);
94+
}
95+
}

0 commit comments

Comments
 (0)