use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class DimensionSelectorHavingSpecTest method testDimSelectorHavingClauseSerde.
@Test
public void testDimSelectorHavingClauseSerde() {
HavingSpec dimHavingSpec = new DimensionSelectorHavingSpec("dim", "v", null);
Map<String, Object> dimSelectMap = ImmutableMap.of("type", "dimSelector", "dimension", "dim", "value", "v");
ObjectMapper mapper = new DefaultObjectMapper();
Assert.assertEquals(dimHavingSpec, mapper.convertValue(dimSelectMap, DimensionSelectorHavingSpec.class));
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class HavingSpecTest method testTypeTypo.
@Test(expected = IllegalArgumentException.class)
public void testTypeTypo() {
Map<String, Object> greaterMap = ImmutableMap.of("type", "nonExistingType", "aggregation", "agg", "value", 1.3);
ObjectMapper mapper = new DefaultObjectMapper();
// noinspection unused
HavingSpec spec = mapper.convertValue(greaterMap, HavingSpec.class);
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class DirectDruidClientTest method testRun.
@Test
public void testRun() throws Exception {
final URL url = new URL(StringUtils.format("http://%s/druid/v2/", hostName));
SettableFuture<InputStream> futureResult = SettableFuture.create();
Capture<Request> capturedRequest = EasyMock.newCapture();
EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(futureResult).times(1);
SettableFuture futureException = SettableFuture.create();
EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(futureException).times(1);
EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(SettableFuture.create()).atLeastOnce();
EasyMock.replay(httpClient);
DirectDruidClient client2 = new DirectDruidClient(new ReflectionQueryToolChestWarehouse(), QueryRunnerTestHelper.NOOP_QUERYWATCHER, new DefaultObjectMapper(), httpClient, "http", "foo2", new NoopServiceEmitter());
QueryableDruidServer queryableDruidServer2 = new QueryableDruidServer(new DruidServer("test1", "localhost", null, 0, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0), client2);
serverSelector.addServerAndUpdateSegment(queryableDruidServer2, serverSelector.getSegment());
TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
query = query.withOverriddenContext(ImmutableMap.of(DirectDruidClient.QUERY_FAIL_TIME, Long.MAX_VALUE));
Sequence s1 = client.run(QueryPlus.wrap(query));
Assert.assertTrue(capturedRequest.hasCaptured());
Assert.assertEquals(url, capturedRequest.getValue().getUrl());
Assert.assertEquals(HttpMethod.POST, capturedRequest.getValue().getMethod());
Assert.assertEquals(1, client.getNumOpenConnections());
// simulate read timeout
client.run(QueryPlus.wrap(query));
Assert.assertEquals(2, client.getNumOpenConnections());
futureException.setException(new ReadTimeoutException());
Assert.assertEquals(1, client.getNumOpenConnections());
// subsequent connections should work
client.run(QueryPlus.wrap(query));
client.run(QueryPlus.wrap(query));
client.run(QueryPlus.wrap(query));
Assert.assertTrue(client.getNumOpenConnections() == 4);
// produce result for first connection
futureResult.set(new ByteArrayInputStream(StringUtils.toUtf8("[{\"timestamp\":\"2014-01-01T01:02:03Z\", \"result\": 42.0}]")));
List<Result> results = s1.toList();
Assert.assertEquals(1, results.size());
Assert.assertEquals(DateTimes.of("2014-01-01T01:02:03Z"), results.get(0).getTimestamp());
Assert.assertEquals(3, client.getNumOpenConnections());
client2.run(QueryPlus.wrap(query));
client2.run(QueryPlus.wrap(query));
Assert.assertEquals(2, client2.getNumOpenConnections());
Assert.assertEquals(serverSelector.pick(null), queryableDruidServer2);
EasyMock.verify(httpClient);
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class ImmutableDruidDataSourceTest method testSerde.
@Test
public void testSerde() throws IOException {
final DataSegment segment = getTestSegment();
final ImmutableDruidDataSource dataSource = getImmutableDruidDataSource(segment);
final ObjectMapper objectMapper = new DefaultObjectMapper().setInjectableValues(new Std().addValue(PruneSpecsHolder.class, PruneSpecsHolder.DEFAULT));
final String json = objectMapper.writeValueAsString(dataSource);
ImmutableDruidDataSourceTestUtils.assertEquals(dataSource, objectMapper.readValue(json, ImmutableDruidDataSource.class));
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class ClientCompactionTaskTransformSpecTest method testSerde.
@Test
public void testSerde() throws IOException {
NullHandling.initializeForTests();
final ClientCompactionTaskTransformSpec expected = new ClientCompactionTaskTransformSpec(new SelectorDimFilter("dim1", "foo", null));
final ObjectMapper mapper = new DefaultObjectMapper();
final byte[] json = mapper.writeValueAsBytes(expected);
final ClientCompactionTaskTransformSpec fromJson = (ClientCompactionTaskTransformSpec) mapper.readValue(json, ClientCompactionTaskTransformSpec.class);
Assert.assertEquals(expected, fromJson);
}
Aggregations