Search in sources :

Example 36 with DefaultObjectMapper

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));
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 37 with DefaultObjectMapper

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);
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 38 with DefaultObjectMapper

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);
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) Request(org.apache.druid.java.util.http.client.Request) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Sequence(org.apache.druid.java.util.common.guava.Sequence) URL(java.net.URL) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) Result(org.apache.druid.query.Result) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) ReflectionQueryToolChestWarehouse(org.apache.druid.query.ReflectionQueryToolChestWarehouse) Test(org.junit.Test)

Example 39 with DefaultObjectMapper

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));
}
Also used : Std(com.fasterxml.jackson.databind.InjectableValues.Std) PruneSpecsHolder(org.apache.druid.timeline.DataSegment.PruneSpecsHolder) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) DataSegment(org.apache.druid.timeline.DataSegment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 40 with DefaultObjectMapper

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);
}
Also used : SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)287 Test (org.junit.Test)245 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)177 File (java.io.File)26 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)25 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)21 Before (org.junit.Before)21 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)20 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)16 DataSegment (org.apache.druid.timeline.DataSegment)16 Period (org.joda.time.Period)16 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)14 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)13 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)12 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)11 TaskStatus (org.apache.druid.indexer.TaskStatus)11 AvroStreamInputRowParserTest (org.apache.druid.data.input.AvroStreamInputRowParserTest)10 ImmutableList (com.google.common.collect.ImmutableList)9 Injector (com.google.inject.Injector)9 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)9