Source:
<code>public void testCookie() throws SQLException, InterruptedException { server.enqueue(new MockResponse() .setResponseCode(307) .addHeader(LOCATION, server.url("/v1/statement")) .addHeader(SET_COOKIE, "a=apple")); server.enqueue(new MockResponse() .addHeader(CONTENT_TYPE, "application/json") .setBody(createResults())); server.enqueue(new MockResponse() .addHeader(CONTENT_TYPE, "application/json") .setBody(createResults())); <START> <END> QueryRunner queryRunner = new QueryRunner( new ClientSession( server.url("/").uri(), "user", "source", ImmutableSet.of(), "clientInfo", "catalog", "schema", "America/Los_Angeles", Locale.ENGLISH, ImmutableMap.of(), ImmutableMap.of(), null, false, new io.airlift.units.Duration(2, MINUTES)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), false, false); try (Query query = queryRunner.startQuery("first query will introduce a cookie")) { ByteArrayOutputStream out = new ByteArrayOutputStream(); query.renderOutput(new PrintStream(out), CSV, false); String result = new String(out.toByteArray(), UTF_8); } try (Query query = queryRunner.startQuery("first query should carry the cookie")) { ByteArrayOutputStream out = new ByteArrayOutputStream(); query.renderOutput(new PrintStream(out), CSV, false); String result = new String(out.toByteArray(), UTF_8); } assertEquals(server.takeRequest().getHeader("Cookie"), null); assertEquals(server.takeRequest().getHeader("Cookie"), "a=apple"); assertEquals(server.takeRequest().getHeader("Cookie"), "a=apple"); }</code><technical_language>Wow..</technical_language>

Target:
public void testCookie() throws SQLException, InterruptedException { server.enqueue(new MockResponse() .setResponseCode(307) .addHeader(LOCATION, server.url("/v1/statement")) .addHeader(SET_COOKIE, "a=apple")); server.enqueue(new MockResponse() .addHeader(CONTENT_TYPE, "application/json") .setBody(createResults())); server.enqueue(new MockResponse() .addHeader(CONTENT_TYPE, "application/json") .setBody(createResults())); QueryRunner queryRunner = new QueryRunner( new ClientSession( server.url("/").uri(), "user", "source", ImmutableSet.of(), "clientInfo", "catalog", "schema", "America/Los_Angeles", Locale.ENGLISH, ImmutableMap.of(), ImmutableMap.of(), null, false, new io.airlift.units.Duration(2, MINUTES)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), false, false); try (Query query = queryRunner.startQuery("first query will introduce a cookie")) { query.renderOutput(new PrintStream(nullOutputStream()), CSV, false); } try (Query query = queryRunner.startQuery("second query should carry the cookie")) { query.renderOutput(new PrintStream(nullOutputStream()), CSV, false); } assertEquals(server.takeRequest().getHeader("Cookie"), null); assertEquals(server.takeRequest().getHeader("Cookie"), "a=apple"); assertEquals(server.takeRequest().getHeader("Cookie"), "a=apple"); }