Search in sources :

Example 26 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceTest method testJSONFlatDataParser.

@Test
public void testJSONFlatDataParser() {
    final String keyField = "keyField";
    final String valueField = "valueField";
    URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(new ObjectMapper(), keyField, valueField);
    Assert.assertEquals(ImmutableMap.of("B", "C"), parser.getParser().parse(String.format("{\"%s\":\"B\", \"%s\":\"C\", \"FOO\":\"BAR\"}", keyField, valueField)));
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 27 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class ImmutableWorkerInfoTest method testSerde.

@Test
public void testSerde() throws Exception {
    ImmutableWorkerInfo workerInfo = new ImmutableWorkerInfo(new Worker("testWorker", "192.0.0.1", 10, "v1"), 2, ImmutableSet.of("grp1", "grp2"), ImmutableSet.of("task1", "task2"), new DateTime("2015-01-01T01:01:01Z"));
    ObjectMapper mapper = new DefaultObjectMapper();
    final ImmutableWorkerInfo serde = mapper.readValue(mapper.writeValueAsString(workerInfo), ImmutableWorkerInfo.class);
    Assert.assertEquals(workerInfo, serde);
}
Also used : Worker(io.druid.indexing.worker.Worker) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DateTime(org.joda.time.DateTime) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 28 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class JavaScriptWorkerSelectStrategyTest method testDisabled.

@Test
public void testDisabled() throws Exception {
    ObjectMapper mapper = new DefaultObjectMapper();
    mapper.setInjectableValues(new InjectableValues.Std().addValue(JavaScriptConfig.class, new JavaScriptConfig(false)));
    final String strategyString = mapper.writeValueAsString(STRATEGY);
    expectedException.expect(JsonMappingException.class);
    expectedException.expectCause(CoreMatchers.<Throwable>instanceOf(IllegalStateException.class));
    expectedException.expectMessage("JavaScript is disabled");
    mapper.readValue(strategyString, JavaScriptWorkerSelectStrategy.class);
}
Also used : JavaScriptConfig(io.druid.js.JavaScriptConfig) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 29 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class WorkerBehaviorConfigTest method testSerde.

@Test
public void testSerde() throws Exception {
    WorkerBehaviorConfig config = new WorkerBehaviorConfig(new FillCapacityWithAffinityWorkerSelectStrategy(new FillCapacityWithAffinityConfig(ImmutableMap.of("foo", Arrays.asList("localhost")))), new EC2AutoScaler(7, 11, new EC2EnvironmentConfig("us-east-1a", new EC2NodeData("amiid", "instanceType", 3, 5, Arrays.asList("securityGroupIds"), "keyNames", "subnetId", null, null), new StringEC2UserData("availZone", "replace", "version")), null, null));
    final ObjectMapper mapper = new DefaultObjectMapper();
    mapper.setInjectableValues(new InjectableValues() {

        @Override
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) {
            return null;
        }
    });
    Assert.assertEquals(config, mapper.readValue(mapper.writeValueAsBytes(config), WorkerBehaviorConfig.class));
}
Also used : EC2EnvironmentConfig(io.druid.indexing.overlord.autoscaling.ec2.EC2EnvironmentConfig) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) EC2AutoScaler(io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) StringEC2UserData(io.druid.indexing.overlord.autoscaling.ec2.StringEC2UserData) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) EC2NodeData(io.druid.indexing.overlord.autoscaling.ec2.EC2NodeData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 30 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class EC2AutoScalerSerdeTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    objectMapper.setInjectableValues(new InjectableValues() {

        @Override
        public Object findInjectableValue(Object o, DeserializationContext deserializationContext, BeanProperty beanProperty, Object o1) {
            return null;
        }
    });
    final EC2AutoScaler autoScaler = objectMapper.readValue(json, EC2AutoScaler.class);
    verifyAutoScaler(autoScaler);
    final EC2AutoScaler roundTripAutoScaler = objectMapper.readValue(objectMapper.writeValueAsBytes(autoScaler), EC2AutoScaler.class);
    verifyAutoScaler(roundTripAutoScaler);
    Assert.assertEquals("Round trip equals", autoScaler, roundTripAutoScaler);
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EC2AutoScaler(io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5262 Test (org.junit.Test)1989 IOException (java.io.IOException)837 JsonNode (com.fasterxml.jackson.databind.JsonNode)724 HashMap (java.util.HashMap)375 Map (java.util.Map)367 ArrayList (java.util.ArrayList)346 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)318 File (java.io.File)282 List (java.util.List)222 Test (org.junit.jupiter.api.Test)205 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 Before (org.junit.Before)202 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)197 InputStream (java.io.InputStream)143 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)137 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Matchers.containsString (org.hamcrest.Matchers.containsString)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)108 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)99