question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Random port with jvm-provider-spring and SpringRestPactRunner

See original GitHub issue

The @TestTarget annotation is called before the Spring Boot application starts. This makes it impossible for me to get a random port and this makes us need to find separate port for each and every microservice.

Is there any known solution for this?

@RunWith(SpringRestPactRunner.class)
@Provider("someservice")
@IgnoreNoPactsToVerify
@PactBroker(<something>)
// We need to have random port so that we dont have to manually find available ports for all services
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {

    @LocalServerPort
    int serverPort;

    // When this annotation is invoked, the serverPort variable has not yet been assigned.
    @TestTarget
    public final Target target = new HttpTarget(serverPort);

    (...)
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
uglyogcommented, Mar 12, 2018

I created a new target for you to use:

  @TestTarget
  public final Target target = new SpringBootHttpTarget();

This will result in the server port being setup before the interaction is tested.

0reactions
uglyogcommented, Mar 19, 2018

3.5.14 has been released

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Random port with jvm-provider-spring and ...
This makes it impossible for me to get a random port and this makes us need to find separate port for each and...
Read more >
Pact Spring/JUnit runner
If you use a random port in a springboot test (by setting SpringBootTest.WebEnvironment.RANDOM_PORT ), you need to set it to the TestTarget ....
Read more >
Pact testing using random port with jUnit5 and SpringBoot
I can't get the pact provider tests to run on any other port than 8080 when using jUnit5. I have the following code:...
Read more >
Get the Running Port in Spring Boot
Here, we need to activate the “randomport” Spring profile to load the corresponding properties file.
Read more >
Upgrading to use JUnit 5 for Spring Pact tests
Previously SpringBootHttpTarget set up the target from the random port automatically but now we need to set the PactVerificationContext 's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found