@Test
    public void shouldHandleErrorsInFirstChunkPOSTWithChunkedResponse() throws Exception {
        final CloseableHttpClient httpclient = HttpClients.createDefault();
        final HttpPost httppost = new HttpPost(TestClientFactory.createURLString());
        httppost.addHeader("Content-Type", "application/json");
        // default chunk size is 16, so should be 2 chunks
        httppost.setEntity(new StringEntity(
                "{\"gremlin\":\"g.inject(0,1,2,3,4,5,6,7,8,9,'ten',11,12,13,14,15,16).coalesce(is(lt(0)),fail('some error'))\"}", Consts.UTF_8));

        try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
            assertEquals(200, response.getStatusLine().getStatusCode());
            assertTrue(response.containsHeader(REQUEST_ID_HEADER_NAME));
            assertTrue(response.getEntity().isChunked());

            final String json = EntityUtils.toString(response.getEntity());
            final JsonNode node = mapper.readTree(json);
            assertThat(node.get("status").get("message").textValue(), startsWith("some error"));
            assertEquals(500, node.get("status").get("code").intValue());

            final Header[] footers = getTrailingHeaders(response);
            assertEquals(2, footers.length);
            assertEquals("code", footers[0].getName());
            assertEquals("500", footers[0].getValue());
            assertEquals("exception", footers[1].getName());
            assertThat(footers[1].getValue(), is("ServerFailStepException"));
        }
    }
Configure specific Gremlin Server settings for specific tests.
gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java