Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x: LRA testing #8468

Open
danielkec opened this issue Mar 11, 2024 · 0 comments · May be fixed by #8469
Open

4.x: LRA testing #8468

danielkec opened this issue Mar 11, 2024 · 0 comments · May be fixed by #8469
Assignees
Projects
Milestone

Comments

@danielkec
Copy link
Contributor

Create LRA testing feature for running LRA coordinator on random port in @HelidonTest environment .

Example:

@HelidonTest
@AddBean(TestLraCoordinator.class)
@Path("/test")
public class LraTest {

    private final WebTarget target;
    private final Set<String> completedLras;
    private final Set<String> cancelledLras;

    @Inject
    private TestLraCoordinator coordinator;

    @Inject
    public LraTest(WebTarget target) {
        this.target = target;
        this.completedLras = new CopyOnWriteArraySet<>();
        this.cancelledLras = new CopyOnWriteArraySet<>();
    }

    @PUT
    @Path("/withdraw")
    @LRA(LRA.Type.REQUIRES_NEW)
    public Response withdraw(@HeaderParam(LRA.LRA_HTTP_CONTEXT_HEADER) Optional<URI> lraI
        ...
        return Response.ok().build();
    }

    @Complete
    public void complete(URI lraId) {
        completedLras.add(lraId.toString());
    }

    @Compensate
    public void rollback(URI lraId) {
        cancelledLras.add(lraId.toString());
    }

    @Test
    public void testLra() {
        try (Response res = target
                .path("/test/withdraw")
                .request()
                .put(Entity.entity("test", MediaType.TEXT_PLAIN_TYPE))) {
            assertThat(res.getStatus(), is(200));
            String lraId = res.getHeaderString(LRA.LRA_HTTP_CONTEXT_HEADER);
            Lra lra = coordinator.lra(lraId);
            assertThat(lra.status(), is(LRAStatus.Closed));
            assertThat(completedLras, contains(lraId));
        }
    }
}
@github-actions github-actions bot added this to Triage in Backlog Mar 11, 2024
@danielkec danielkec added this to the 4.0.6 milestone Mar 11, 2024
@danielkec danielkec linked a pull request Mar 11, 2024 that will close this issue
@danielkec danielkec self-assigned this Mar 11, 2024
@danielkec danielkec moved this from Triage to Sprint Scope in Backlog Mar 11, 2024
@barchetta barchetta modified the milestones: 4.0.6, 4.0.7 Mar 11, 2024
@barchetta barchetta modified the milestones: 4.0.7, 4.0.8 Apr 4, 2024
@barchetta barchetta modified the milestones: 4.0.8, 4.0.9 Apr 25, 2024
@barchetta barchetta modified the milestones: 4.0.9, 4.1.0 May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Backlog
  
Sprint Scope
Development

Successfully merging a pull request may close this issue.

2 participants