BAEL-3326, "Optimizing JSON Schema for production use"
Percentages now rounded.
This commit is contained in:
parent
2c78247c95
commit
09e0e958bc
@ -29,7 +29,8 @@ class JsonOptimizationUnitTest {
|
|||||||
private static final String TEST_LABEL_SLIM_CUSTOM_SERIALIZER = "Slim custom serializer";
|
private static final String TEST_LABEL_SLIM_CUSTOM_SERIALIZER = "Slim custom serializer";
|
||||||
private static final String TEST_LABEL_SLIM_CUSTOMER = "Slim customer";
|
private static final String TEST_LABEL_SLIM_CUSTOMER = "Slim customer";
|
||||||
private static final String TEST_LABEL_SLIM_CUSTOMER_SHORT_NAMES = "Slim customer with shorter attribute names";
|
private static final String TEST_LABEL_SLIM_CUSTOMER_SHORT_NAMES = "Slim customer with shorter attribute names";
|
||||||
private static DecimalFormat LENGTH_FORMATTER = new DecimalFormat("###,###,###");
|
private static DecimalFormat LENGTH_FORMATTER = new DecimalFormat("###,###");
|
||||||
|
private static DecimalFormat PERCENT_FORMATTER = new DecimalFormat("###");
|
||||||
private static Customer[] customers;
|
private static Customer[] customers;
|
||||||
private ObjectMapper mapper;
|
private ObjectMapper mapper;
|
||||||
private static int defaultJsonLength;
|
private static int defaultJsonLength;
|
||||||
@ -139,8 +140,9 @@ class JsonOptimizationUnitTest {
|
|||||||
gzipStream.write(plainJson);
|
gzipStream.write(plainJson);
|
||||||
gzipStream.close();
|
gzipStream.close();
|
||||||
byte[] gzippedJson = outpuStream.toByteArray();
|
byte[] gzippedJson = outpuStream.toByteArray();
|
||||||
int percent = gzippedJson.length * 100 / defaultJsonLength;
|
double percent = Math.round(gzippedJson.length * 100d / defaultJsonLength);
|
||||||
System.out.println(label + " GZIPped length: " + LENGTH_FORMATTER.format(gzippedJson.length / 1024) + "kB (" + percent + "%)");
|
System.out.println(label + " GZIPped length: " + LENGTH_FORMATTER.format(gzippedJson.length / 1024)
|
||||||
|
+ "kB (" + PERCENT_FORMATTER.format(percent) + "%)");
|
||||||
assertTrue(plainJson.length > gzippedJson.length, label + " should be longer than GZIPped data");
|
assertTrue(plainJson.length > gzippedJson.length, label + " should be longer than GZIPped data");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,8 +152,9 @@ class JsonOptimizationUnitTest {
|
|||||||
System.out.println(prettyWritter.writeValueAsString(customers[0]));
|
System.out.println(prettyWritter.writeValueAsString(customers[0]));
|
||||||
|
|
||||||
byte[] feedback = mapper.writeValueAsBytes(customers);
|
byte[] feedback = mapper.writeValueAsBytes(customers);
|
||||||
int percent = feedback.length * 100 / defaultJsonLength;
|
double percent = Math.round(feedback.length * 100d / defaultJsonLength);
|
||||||
System.out.println(label + " length: " + LENGTH_FORMATTER.format(feedback.length / 1024) + "kB (" + percent + "%)");
|
System.out.println(label + " length: " + LENGTH_FORMATTER.format(feedback.length / 1024)
|
||||||
|
+ "kB (" + PERCENT_FORMATTER.format(percent) + "%)");
|
||||||
assertTrue(feedback.length > 1, label + " should be there");
|
assertTrue(feedback.length > 1, label + " should be there");
|
||||||
|
|
||||||
String prefix = label.replaceAll(" ", "-")
|
String prefix = label.replaceAll(" ", "-")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user