Skip to content

Commit

Permalink
fix JSON flaky tests (apache#15261)
Browse files Browse the repository at this point in the history
Co-authored-by: simonh5 <[email protected]>
  • Loading branch information
hofi1 and simonh5 authored Oct 27, 2023
1 parent f1132d2 commit e9b7e4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ protected ListenableFuture<Response> go(Request request) throws JsonProcessingEx
request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE)
);
Assert.assertEquals(
StringUtils.format(
JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1))
),
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
);

return GoHandlers.immediateFuture(okResponse());
Expand Down Expand Up @@ -282,12 +284,14 @@ protected ListenableFuture<Response> go(Request request) throws JsonProcessingEx
request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE)
);
Assert.assertEquals(
StringUtils.format(
JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1))
),
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
);

return GoHandlers.immediateFuture(okResponse());
Expand Down Expand Up @@ -467,12 +471,14 @@ protected ListenableFuture<Response> go(Request request) throws JsonProcessingEx
request.getHeaders().get(HttpHeaders.Names.AUTHORIZATION)
);
Assert.assertEquals(
StringUtils.format(
JSON_MAPPER.readTree(StringUtils.format(
"%s\n%s\n",
JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1))
),
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
);

return GoHandlers.immediateFuture(okResponse());
Expand Down Expand Up @@ -521,12 +527,14 @@ protected ListenableFuture<Response> go(Request request) throws JsonProcessingEx
request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE)
);
Assert.assertEquals(
StringUtils.format(
JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(counter.getAndIncrement())),
JSON_MAPPER.writeValueAsString(events.get(counter.getAndIncrement()))
),
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
);

return GoHandlers.immediateFuture(okResponse());
Expand Down Expand Up @@ -584,12 +592,14 @@ protected ListenableFuture<Response> go(Request request) throws IOException
CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos);

Assert.assertEquals(
StringUtils.format(
JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1))
),
)),
JSON_MAPPER.readTree(
baos.toString(StandardCharsets.UTF_8.name())
)
);

return GoHandlers.immediateFuture(okResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ protected ListenableFuture<Response> go(Request request)
"http://example.com/test1", StringUtils.format("[%s]\n", JSON_MAPPER.writeValueAsString(events.get(0))),
"http://example.com/test2", StringUtils.format("[%s]\n", JSON_MAPPER.writeValueAsString(events.get(1)))
);
Assert.assertEquals(expected, results);
for (Map.Entry<String, String> entry : expected.entrySet()) {
Assert.assertEquals(JSON_MAPPER.readTree(expected.get(entry.getKey())), JSON_MAPPER.readTree(results.get(entry.getKey())));
}
}

@Test
Expand Down

0 comments on commit e9b7e4a

Please sign in to comment.