BAEL-3326, "Optimizing JSON Schema for production use":

Added percentages, fixed formatting.
This commit is contained in:
Karsten Silz 2020-09-06 13:48:39 +01:00
parent 9d326b55bc
commit 2c78247c95
4 changed files with 16 additions and 10 deletions

View File

@ -32,10 +32,14 @@ class JsonOptimizationUnitTest {
private static DecimalFormat LENGTH_FORMATTER = new DecimalFormat("###,###,###");
private static Customer[] customers;
private ObjectMapper mapper;
private static int defaultJsonLength;
@BeforeAll
static void setUpOnce() throws Exception {
customers = Customer.fromMockFile();
ObjectMapper oneTimeMapper = new ObjectMapper();
byte[] feedback = oneTimeMapper.writeValueAsBytes(customers);
defaultJsonLength = feedback.length;
}
@BeforeEach
@ -135,7 +139,8 @@ class JsonOptimizationUnitTest {
gzipStream.write(plainJson);
gzipStream.close();
byte[] gzippedJson = outpuStream.toByteArray();
System.out.println(label + " GZIPped length: " + LENGTH_FORMATTER.format(gzippedJson.length));
int percent = gzippedJson.length * 100 / defaultJsonLength;
System.out.println(label + " GZIPped length: " + LENGTH_FORMATTER.format(gzippedJson.length / 1024) + "kB (" + percent + "%)");
assertTrue(plainJson.length > gzippedJson.length, label + " should be longer than GZIPped data");
}
@ -145,7 +150,8 @@ class JsonOptimizationUnitTest {
System.out.println(prettyWritter.writeValueAsString(customers[0]));
byte[] feedback = mapper.writeValueAsBytes(customers);
System.out.println(label + " length: " + LENGTH_FORMATTER.format(feedback.length));
int percent = feedback.length * 100 / defaultJsonLength;
System.out.println(label + " length: " + LENGTH_FORMATTER.format(feedback.length / 1024) + "kB (" + percent + "%)");
assertTrue(feedback.length > 1, label + " should be there");
String prefix = label.replaceAll(" ", "-")