use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestRange method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
Range range = Range.all(BIGINT);
assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
range = Range.equal(DOUBLE, 0.123);
assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
range = Range.greaterThan(BIGINT, 0L);
assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
range = Range.greaterThanOrEqual(VARCHAR, utf8Slice("abc"));
assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
range = Range.lessThan(BIGINT, Long.MAX_VALUE);
assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
range = Range.lessThanOrEqual(DOUBLE, Double.MAX_VALUE);
assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
}
use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestEquatableValueSet method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
EquatableValueSet set = EquatableValueSet.all(TestingIdType.ID);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.none(TestingIdType.ID);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.of(TestingIdType.ID, 1L);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.of(TestingIdType.ID, 1L, 2L);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.of(TestingIdType.ID, 1L, 2L).complement();
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
}
use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestMarker method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
Marker marker = Marker.above(BIGINT, 0L);
assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
marker = Marker.exactly(VARCHAR, utf8Slice("abc"));
assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
marker = Marker.below(DOUBLE, 0.123);
assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
marker = Marker.exactly(BOOLEAN, true);
assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
marker = Marker.upperUnbounded(BIGINT);
assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
marker = Marker.lowerUnbounded(BIGINT);
assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
}
use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestSetDigest method testHashCounts.
@Test
public void testHashCounts() throws Exception {
SetDigest digest1 = new SetDigest();
digest1.add(0);
digest1.add(0);
digest1.add(1);
SetDigest digest2 = new SetDigest();
digest2.add(0);
digest2.add(0);
digest2.add(2);
digest2.add(2);
ObjectMapper mapper = new JsonObjectMapperProvider().get();
Slice slice = hashCounts(digest1.serialize());
Map<Long, Short> counts = mapper.readValue(slice.toStringUtf8(), new TypeReference<Map<Long, Short>>() {
});
Set<Short> expected = ImmutableSet.of((short) 1, (short) 2);
assertEquals(counts.values(), expected);
digest1.mergeWith(digest2);
slice = hashCounts(digest1.serialize());
counts = mapper.readValue(slice.toStringUtf8(), new TypeReference<Map<Long, Short>>() {
});
expected = ImmutableSet.of((short) 1, (short) 2, (short) 4);
assertEquals(ImmutableSet.copyOf(counts.values()), expected);
}
use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestHeartbeatFailureDetector method testHeartbeatStatsSerialization.
@Test
public void testHeartbeatStatsSerialization() throws Exception {
ObjectMapper objectMapper = new JsonObjectMapperProvider().get();
Stats stats = new Stats(new URI("http://example.com"), 60);
String serialized = objectMapper.writeValueAsString(stats);
JsonNode deserialized = objectMapper.readTree(serialized);
assertFalse(deserialized.has("lastFailureInfo"));
stats.recordFailure(new SocketTimeoutException("timeout"));
serialized = objectMapper.writeValueAsString(stats);
deserialized = objectMapper.readTree(serialized);
assertFalse(deserialized.get("lastFailureInfo").isNull());
assertEquals(deserialized.get("lastFailureInfo").get("type").asText(), SocketTimeoutException.class.getName());
}
Aggregations