Gradle test Task - Different behaviour on Virtual Machine than localhost

plugins

(asdf1234.) #1

Problem description:

I am running running the gradle test task on a Grails 3.1.4 project on my Windows 7 Laptop and all tests pass.

I am running the same gradle task on a remote Virtual machine CentOs 7, but some of the tests crash with the following error:

15:06:48.686 [DEBUG] [TestEventLogger] MyClassApplicationVersionControllerTest > MyClass Version Controller Test 1 STARTED
15:06:48.723 [DEBUG] [TestEventLogger] 
15:06:48.723 [DEBUG] [TestEventLogger] MyClassApplicationVersionControllerTest > MyClass Version Controller Test 1 STANDARD_OUT
15:06:48.723 [DEBUG] [TestEventLogger]     ERROR StackTrace - Full Stack Trace:
15:06:48.723 [DEBUG] [TestEventLogger]     java.lang.NullPointerException: null
15:06:48.723 [DEBUG] [TestEventLogger]      at org.grails.web.servlet.mvc.GrailsWebRequest.getControllerClass(GrailsWebRequest.java:333)
15:06:48.723 [DEBUG] [TestEventLogger]      at org.grails.web.servlet.mvc.GrailsWebRequest.isFlowRequest(GrailsWebRequest.java:377)
15:06:48.723 [DEBUG] [TestEventLogger]      at org.grails.orm.hibernate4.support.GrailsOpenSessionInViewInterceptor.preHandle(GrailsOpenSessionInViewInterceptor.java:48)
...
15:06:48.728 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:48.728 [DEBUG] [TestEventLogger]     ERROR StackTrace - Full Stack Trace:
15:06:48.728 [DEBUG] [TestEventLogger]     java.lang.NullPointerException: null
15:06:48.729 [DEBUG] [TestEventLogger]      at org.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:52)
...
15:06:48.729 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:48.736 [DEBUG] [TestEventLogger]     ERROR org.grails.web.errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /MyClass/MyClassVersion/getCurrentVersion
15:06:48.736 [DEBUG] [TestEventLogger]     Stacktrace follows:
15:06:48.736 [DEBUG] [TestEventLogger]     java.lang.NullPointerException: null
15:06:48.736 [DEBUG] [TestEventLogger]      at org.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:52)
...
15:06:48.737 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:50.291 [DEBUG] [TestEventLogger]     ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/MyClass].[grailsDispatcherServlet] - Servlet.service() for servlet [grailsDispatcherServlet] in context with path [/MyClass] threw exception
15:06:50.292 [DEBUG] [TestEventLogger]     java.lang.IllegalArgumentException: This Dispatcher has been shut down.
15:06:50.292 [DEBUG] [TestEventLogger]      at reactor.core.support.Assert.isTrue(Assert.java:61)
15:06:50.292 [DEBUG] [TestEventLogger]      at reactor.core.dispatch.AbstractLifecycleDispatcher.dispatch(AbstractLifecycleDispatcher.java:111)
...
15:06:50.299 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:50.299 [DEBUG] [TestEventLogger]     WARN grails.plugin.cache.web.filter.simple.MemoryPageFragmentCachingFilter - Throwable thrown during doFilter on request with URI: /MyClass/MyClassVersion/getCurrentVersion and Query: null : null
15:06:50.299 [DEBUG] [TestEventLogger]     java.lang.NullPointerException: null
15:06:50.299 [DEBUG] [TestEventLogger]      at grails.plugin.cache.web.ContentCacheParameters.initController(ContentCacheParameters.java:81)
15:06:50.299 [DEBUG] [TestEventLogger]      at grails.plugin.cache.web.ContentCacheParameters.<init>(ContentCacheParameters.java:46)
...
15:06:50.303 [DEBUG] [TestEventLogger]      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
15:06:50.303 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:50.303 [DEBUG] [TestEventLogger]     ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/MyClass].[grailsDispatcherServlet] - Servlet.service() for servlet grailsDispatcherServlet threw exception
15:06:50.303 [DEBUG] [TestEventLogger]     java.lang.NullPointerException: null
15:06:50.303 [DEBUG] [TestEventLogger]      at grails.plugin.cache.web.ContentCacheParameters.initController(ContentCacheParameters.java:81)
...
15:06:50.307 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:50.307 [DEBUG] [TestEventLogger]     ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost] - Exception Processing ErrorPage[errorCode=500, location=/error]
15:06:50.307 [DEBUG] [TestEventLogger]     javax.servlet.ServletException: java.lang.NullPointerException
15:06:50.307 [DEBUG] [TestEventLogger]      at grails.plugin.cache.web.filter.AbstractFilter.logThrowable(AbstractFilter.java:116)
15:06:50.307 [DEBUG] [TestEventLogger]      at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:70)
...
15:06:50.310 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:50.310 [DEBUG] [TestEventLogger]     Caused by: java.lang.NullPointerException: null
15:06:50.310 [DEBUG] [TestEventLogger]      at grails.plugin.cache.web.ContentCacheParameters.initController(ContentCacheParameters.java:81)
...
15:06:50.311 [DEBUG] [TestEventLogger]      at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
15:06:50.311 [DEBUG] [TestEventLogger]      ... 39 common frames omitted
15:06:50.311 [DEBUG] [TestEventLogger]     WARN groovyx.net.http.RESTClient - Error parsing 'text/html;charset=UTF-8' response
15:06:50.311 [DEBUG] [TestEventLogger]     org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected
15:06:50.311 [DEBUG] [TestEventLogger]      at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:268)
...
15:06:50.316 [DEBUG] [TestEventLogger]      at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70)
15:06:50.316 [QUIET] [system.out] 15:06:50.316
15:06:50.316 [DEBUG] [TestEventLogger]      at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
15:06:50.316 [QUIET] [system.out]  [DEBUG] [org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor] Executing test class RequirementsControllerTest
15:06:50.316 [DEBUG] [TestEventLogger]      at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67)
15:06:50.317 [DEBUG] [TestEventLogger]      at MyClassApplicationVersionControllerTest.$spock_feature_0_0(MyClassApplicationVersionControllerTest.groovy)
15:06:50.317 [DEBUG] [TestEventLogger]      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
15:06:50.322 [DEBUG] [TestEventLogger]      at java.lang.Thread.run(Thread.java:745)
15:06:50.368 [DEBUG] [TestEventLogger] 
15:06:50.368 [DEBUG] [TestEventLogger] MyClassApplicationVersionControllerTest > MyClass Version Controller Test 1 FAILED
15:06:50.369 [DEBUG] [TestEventLogger]     groovyx.net.http.ResponseParseException: Internal Server Error
15:06:50.369 [DEBUG] [TestEventLogger]         at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:495)
15:06:50.369 [DEBUG] [TestEventLogger]         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222)
15:06:50.369 [DEBUG] [TestEventLogger]         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
15:06:50.369 [DEBUG] [TestEventLogger]         at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
15:06:50.369 [DEBUG] [TestEventLogger]         at groovyx.net.http.RESTClient.get(RESTClient.java:119)
15:06:50.369 [DEBUG] [TestEventLogger]         at MyClassApplicationVersionControllerTest.$tt__$spock_feature_0_0(MyClassApplicationVersionControllerTest.groovy:18)
15:06:50.369 [DEBUG] [TestEventLogger]         at MyClassApplicationVersionControllerTest.MyClass Version Controller Test 1_closure1(MyClassApplicationVersionControllerTest.groovy)
15:06:50.369 [DEBUG] [TestEventLogger]         at groovy.lang.Closure.call(Closure.java:426)
15:06:50.370 [DEBUG] [TestEventLogger]         at groovy.lang.Closure.call(Closure.java:442)
15:06:50.370 [DEBUG] [TestEventLogger]         at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70)
15:06:50.370 [DEBUG] [TestEventLogger]         at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
15:06:50.370 [DEBUG] [TestEventLogger]         at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67)
15:06:50.370 [DEBUG] [TestEventLogger]         at MyClassApplicationVersionControllerTest.MyClass Version Controller Test 1(MyClassApplicationVersionControllerTest.groovy)
15:06:50.370 [DEBUG] [TestEventLogger] 
15:06:50.370 [DEBUG] [TestEventLogger]         Caused by:
15:06:50.370 [DEBUG] [TestEventLogger]         org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected
15:06:50.370 [DEBUG] [TestEventLogger]             at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:268)
15:06:50.370 [DEBUG] [TestEventLogger]             at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:227)
15:06:50.370 [DEBUG] [TestEventLogger]             at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:186)
15:06:50.370 [DEBUG] [TestEventLogger]             at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137)
15:06:50.370 [DEBUG] [TestEventLogger]             at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
15:06:50.370 [DEBUG] [TestEventLogger]             at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
15:06:50.371 [DEBUG] [TestEventLogger]             at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
15:06:50.371 [DEBUG] [TestEventLogger]             at java.io.InputStreamReader.read(InputStreamReader.java:184)
15:06:50.371 [DEBUG] [TestEventLogger]             at org.cyberneko.html.HTMLScanner$CurrentEntity.load(HTMLScanner.java:1867)
15:06:50.371 [DEBUG] [TestEventLogger]             at org.cyberneko.html.HTMLScanner.skipNewlines(HTMLScanner.java:1602)
15:06:50.371 [DEBUG] [TestEventLogger]             at org.cyberneko.html.HTMLScanner$ContentScanner.scanCharacters(HTMLScanner.java:2334)
15:06:50.371 [DEBUG] [TestEventLogger]             at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2066)
15:06:50.371 [DEBUG] [TestEventLogger]             at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
15:06:50.371 [DEBUG] [TestEventLogger]             at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
15:06:50.371 [DEBUG] [TestEventLogger]             at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
15:06:50.371 [DEBUG] [TestEventLogger]             at groovy.util.XmlSlurper.parse(XmlSlurper.java:207)
15:06:50.371 [DEBUG] [TestEventLogger]             at groovy.util.XmlSlurper.parse(XmlSlurper.java:260)
15:06:50.371 [DEBUG] [TestEventLogger]             at groovyx.net.http.ParserRegistry.parseHTML(ParserRegistry.java:251)
15:06:50.371 [DEBUG] [TestEventLogger]             at groovy.lang.Closure.call(Closure.java:426)
15:06:50.371 [DEBUG] [TestEventLogger]             at groovy.lang.Closure.call(Closure.java:442)
15:06:50.372 [DEBUG] [TestEventLogger]             at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:560)
15:06:50.372 [DEBUG] [TestEventLogger]             at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:489)
15:06:50.372 [DEBUG] [TestEventLogger]             ... 12 more
15:06:50.374 [DEBUG] [TestEventLogger] 
15:06:50.374 [DEBUG] [TestEventLogger] MyClassApplicationVersionControllerTest FAILED

I cropped some portions of the stacktrace. Let me know if you think there are hidden hints.

This is the Test Class:

import grails.test.mixin.integration.Integration
import grails.transaction.Rollback
import groovyx.net.http.RESTClient
import spock.lang.Specification

import java.util.regex.Pattern

import static groovyx.net.http.ContentType.JSON

@Integration
@Rollback
class MyClassApplicationVersionControllerTest extends Specification {
    RESTClient restClient = new RESTClient('http://localhost:6543')

    def 'MyClass Version Controller Test 1'() {

        when: 'version url is called'
        def response = restClient.get(
                path: "/MyClass/MyClassVersion/getCurrentVersion"
        )

        then: ''
        println(response.responseData)
        assert Pattern.matches("01.01.01.*" , response.responseData.toString()) == true
    }
}

This is the underlying Controller Class:


import grails.converters.JSON
import grails.rest.RestfulController
import org.apache.commons.io.FileUtils

import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Paths

class MyClassVersionController extends RestfulController{

    MyClassVersionController() {
        super(MyClassSystem)
    }

    def getCurrentVersion(){
        BufferedReader br = new BufferedReader(new InputStreamReader(this.class.classLoader.getResourceAsStream('version.txt')))
		def version = br.readLine()
		br.close();
        render version
    }
}

I checked the Gradle Versions: on both environments its Gradle 2.12. The JVM-Version is 1.8.

Can you give me hints or the solution?