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

Not listening on HTTP port. The WireMock server is most likely stopped #22

Closed
nik24 opened this issue Apr 8, 2019 · 5 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@nik24
Copy link

nik24 commented Apr 8, 2019

I am facing an error while running tests with Schema Registry mock along with JUnit4

alertIsGeneratedWithCorrectTimestampForDeviceCoordinates(com.loconav.IgnitionAlertTest)  Time elapsed: 0.038 sec  <<< ERROR!
java.lang.IllegalStateException: Not listening on HTTP port. The WireMock server is most likely stopped
        at com.google.common.base.Preconditions.checkState(Preconditions.java:508)
        at com.github.tomakehurst.wiremock.WireMockServer.port(WireMockServer.java:177)
        at com.bakdata.schemaregistrymock.SchemaRegistryMock.getUrl(SchemaRegistryMock.java:131)
        at com.loconav.IgnitionAlertTest.setup(IgnitionAlertTest.java:48)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

alertIsGeneratedWithCorrectTimestampForDeviceCoordinates(com.loconav.IgnitionAlertTest)  Time elapsed: 0.038 sec  <<< ERROR!
java.lang.NullPointerException
        at com.loconav.IgnitionAlertTest.tearDown(IgnitionAlertTest.java:59)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Tests in error: 
  alertIsGeneratedWithCorrectTimestampForDeviceCoordinates(com.loconav.IgnitionAlertTest): Not listening on HTTP port. The WireMock server is most likely stopped
  alertIsGeneratedWithCorrectTimestampForDeviceCoordinates(com.loconav.IgnitionAlertTest)

Code looks like below:

public class IgnitionAlertTest {

  private TopologyTestDriver topologyTestDriver;

  @RegisterExtension final SchemaRegistryMock schemaRegistry = new SchemaRegistryMock();

  @Before
  public void setup() {

    // setup test driver
    Properties props = new Properties();
    props.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, "test");
    props.setProperty(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234");
    props.setProperty(
        StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.topicPrefix(TopicConfig.COMPRESSION_TYPE_CONFIG), "snappy");
    props.setProperty(
        AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistry.getUrl());

    Topology topology =
        IgnitionAlertService.generateTopology(
            props.getProperty(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG));

    topologyTestDriver = new TopologyTestDriver(topology, props);
  }

  @After
  public void tearDown() {
    topologyTestDriver.close();
  }

  @Test
  public void alertIsGeneratedWithCorrectTimestampForDeviceCoordinates() {

    Serializer<String> keySerializer = Topics.DEVICE_COORDINATES.keySerde().serializer();

    Serializer<DeviceLocations> valueSerializer =
        Topics.DEVICE_COORDINATES.valueSerde().serializer();

    long currentTime = System.currentTimeMillis();
    ConsumerRecordFactory<String, DeviceLocations> consumerRecordFactory =
        new ConsumerRecordFactory<>(
            Topics.DEVICE_COORDINATES.name(), keySerializer, valueSerializer, currentTime);

    // ...other data generation code to test
  }
}

Can there be some issue with dependency management as this test is executing in a module that is inheriting testing dependencies fom the parent project.
I tried to run this using Junit 5 and can see logs of running jetty server
but it keeps giving me an error java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonMerge while executing test

@AHeise
Copy link
Contributor

AHeise commented Apr 8, 2019

Hi @nik24 ,

if you are running with JUnit 4, you need to start and stop the schema registry mock manually (in setup and teardown). RegisterExtension is not doing anything. If you really want to use JUnit4 for some reason, then it's best to fork and replace Extension with a rule (should be pretty straight-forward substitution). I could merge your fork as a separate module.

If you rather want to use JUnit 5, please open a new ticket with the respective stack trace and the maven/gradle dependency tree. It looks like you have two conflicting versions, which may also be a bad setup on our end and needs to be addressed.

@nik24
Copy link
Author

nik24 commented Apr 9, 2019

Thanks for the reply @AHeise . I have raised another ticket with relevant logs for Junit5. However, if I were to use Junit4 and do as you suggested, should I create entirely another class that implements TestRule with the same contents as Extension?

@AHeise
Copy link
Contributor

AHeise commented Apr 9, 2019

Fair point. That will result in quite a bit duplicated code. Probably easier to make the mock framework agnostic and add extension/rule as trivial subprojects.

I could look at it tomorrow if that's soon enough for you.

@nik24
Copy link
Author

nik24 commented Apr 10, 2019

I have gone with Junit5 finally. The tests are running fine now.

@AHeise AHeise added the question Further information is requested label Apr 30, 2019
@AHeise AHeise self-assigned this Apr 30, 2019
@AHeise
Copy link
Contributor

AHeise commented Apr 30, 2019

Opened #25 for junit4 support and closing this as a question.

@AHeise AHeise closed this as completed Apr 30, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants