cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot run test methods related with Neo4j in Spring Boot

sngermiyanoglu
Node Clone

Hi, I have a problem about running all tests regarding Neo4j in my Spring Boot App.

When I try to run any method of AppApplicationTests, I only see an infinite loop on the console and the method cannot work.

How can I fix it?

Here is the link : Test Class 

1 ACCEPTED SOLUTION

Please be aware that this is just a _debug_ message coming from the Docker java library. It has no impact on the testing.

For me setting also the password correct will run all tests (there is one failing but this is discussed in another thread)

@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.neo4j.authentication.username", () -> "neo4j");
registry.add("spring.neo4j.authentication.password", () -> container.getAdminPassword());
registry.add("spring.neo4j.uri", () -> container.getBoltUrl());
}

The changes can be found in my fork https://github.com/meistermeier/SpringBootNeo4jShortestPath

View solution in original post

9 REPLIES 9

glilienfield
Ninja
Ninja

I will just make a few notes that may help. Looking at one of my Junit 5 tests that uses a test container, I have the following: 

  1. I have the Neo4JContainer variable annotated with '@Container'
  2. I have the class using it annotated with '@Testcontainers'
  3. I then create a Neo4j driver using the test container's Url

Is your test container getting spun up?  Also, you are auto wiring a driver into your test class. You need to use one pointing your test container. 

You don't get an exceptions? What behavior are you getting?

Here is my issue when I try to run any test method in AppApplicationTests

screenshot_28.PNG

Can you post the entire trace stack.  Have you tried disabling all your test in this class and create one simple not that allow you go break to see if your test harness is coming up correctly? 

It is too long to share it here.

Then, can you include the enclosing exception above what you included, or as much as you are comfortable pasting? 

The issue maybe related with this line defined in docker-compose .yml.

NEO4JLABS_PLUGINS: '["apoc"]'

I cannot detect it. I get this error shown below.

org.neo4j.driver.exceptions.ClientException: There is no procedure with the name `apoc.algo.dijkstra` registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.

Here is my error information shown below.

java.io.IOException: java.nio.channels.ClosedChannelException
at java.base/java.nio.channels.Channels$2.read(Channels.java:241)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.io.LoggingInputStream.read(LoggingInputStream.java:81)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:149)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:261)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:147)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:314)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.io.Closer.close(Closer.java:48)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.IncomingHttpEntity.close(IncomingHttpEntity.java:111)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.io.entity.HttpEntityWrapper.close(HttpEntityWrapper.java:120)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.io.Closer.close(Closer.java:48)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.message.BasicClassicHttpResponse.close(BasicClassicHttpResponse.java:93)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpResponse.close(CloseableHttpResponse.java:200)
at com.github.dockerjava.zerodep.ApacheDockerHttpClientImpl$ApacheResponse.close(ApacheDockerHttpClientImpl.java:256)
at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:277)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.nio.channels.ClosedChannelException: null
at java.base/sun.nio.ch.WindowsAsynchronousFileChannelImpl.implRead(WindowsAsynchronousFileChannelImpl.java:516)
at java.base/sun.nio.ch.AsynchronousFileChannelImpl.read(AsynchronousFileChannelImpl.java:229)
at com.github.dockerjava.transport.NamedPipeSocket$AsynchronousFileByteChannel.read(NamedPipeSocket.java:117)
at java.base/java.nio.channels.Channels$2.read(Channels.java:239)
... 16 common frames omitted
22:12:12.609 [ducttape-0] DEBUG com.github.dockerjava.zerodep.ApacheDockerHttpClientImpl$ApacheResponse - Failed to close the response
java.io.IOException: java.nio.channels.ClosedChannelException
at java.base/java.nio.channels.Channels$2.read(Channels.java:241)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.io.LoggingInputStream.read(LoggingInputStream.java:81)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:149)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:261)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:147)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:314)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.io.Closer.close(Closer.java:48)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.impl.io.IncomingHttpEntity.close(IncomingHttpEntity.java:111)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.io.entity.HttpEntityWrapper.close(HttpEntityWrapper.java:120)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.io.Closer.close(Closer.java:48)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.message.BasicClassicHttpResponse.close(BasicClassicHttpResponse.java:93)
at com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpResponse.close(CloseableHttpResponse.java:200)
at com.github.dockerjava.zerodep.ApacheDockerHttpClientImpl$ApacheResponse.close(ApacheDockerHttpClientImpl.java:256)
at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$null$0(DefaultInvocationBuilder.java:272)
at com.github.dockerjava.api.async.ResultCallbackTemplate.close(ResultCallbackTemplate.java:77)
at org.testcontainers.containers.output.FrameConsumerResultCallback.close(FrameConsumerResultCallback.java:100)
at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:51)
at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:51)
at org.testcontainers.containers.wait.strategy.WaitAllStrategy.waitUntilNestedStrategiesAreReady(WaitAllStrategy.java:61)
at org.testcontainers.containers.wait.strategy.WaitAllStrategy.lambda$waitUntilReady$0(WaitAllStrategy.java:54)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.nio.channels.ClosedChannelException: null
at java.base/sun.nio.ch.WindowsAsynchronousFileChannelImpl.implRead(WindowsAsynchronousFileChannelImpl.java:516)
at java.base/sun.nio.ch.AsynchronousFileChannelImpl.read(AsynchronousFileChannelImpl.java:229)
at com.github.dockerjava.transport.NamedPipeSocket$AsynchronousFileByteChannel.read(NamedPipeSocket.java:117)
at java.base/java.nio.channels.Channels$2.read(Channels.java:239)
... 26 common frames omitted

Please be aware that this is just a _debug_ message coming from the Docker java library. It has no impact on the testing.

For me setting also the password correct will run all tests (there is one failing but this is discussed in another thread)

@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.neo4j.authentication.username", () -> "neo4j");
registry.add("spring.neo4j.authentication.password", () -> container.getAdminPassword());
registry.add("spring.neo4j.uri", () -> container.getBoltUrl());
}

The changes can be found in my fork https://github.com/meistermeier/SpringBootNeo4jShortestPath

I'll ask it in another thread but could you tell me where is the issue in a test class. I also added some test methods there.

glilienfield
Ninja
Ninja

Did you try upgrading to Neo4j 4.4.x as suggested by @koji in your other post?