Package com.netflix.suro.jackson

Examples of com.netflix.suro.jackson.DefaultObjectMapper


                "    \"request.required.acks\": 1,\n" +
                "    \"batchSize\": 10,\n" +
                "    \"jobQueueSize\": 3\n" +
                "}";

        ObjectMapper jsonMapper = new DefaultObjectMapper();
        jsonMapper.registerSubtypes(new NamedType(KafkaSink.class, "kafka"));
        KafkaSink sink = jsonMapper.readValue(description, new TypeReference<Sink>(){});
        sink.open();
        int msgCount = 10000;
        for (int i = 0; i < msgCount; ++i) {
            Map<String, Object> msgMap = new ImmutableMap.Builder<String, Object>()
                    .put("key", Integer.toString(i))
                    .put("value", "message:" + i).build();
            sink.writeTo(new DefaultMessageContainer(
                    new Message(TOPIC_NAME_MULTITHREAD, jsonMapper.writeValueAsBytes(msgMap)),
                    jsonMapper));
        }
        assertTrue(sink.getNumOfPendingMessages() > 0);
        sink.close();
        System.out.println(sink.getStat());
View Full Code Here


                "    \"request.required.acks\": 1,\n" +
                fileQueue + ",\n" +
                keyTopicMap + "\n" +
                "}";

        ObjectMapper jsonMapper = new DefaultObjectMapper();
        jsonMapper.registerSubtypes(new NamedType(KafkaSink.class, "kafka"));
        KafkaSink sink = jsonMapper.readValue(description, new TypeReference<Sink>(){});
        sink.open();

        int messageCount = 10;
        for (int i = 0; i < messageCount; ++i) {
            Map<String, Object> msgMap = new ImmutableMap.Builder<String, Object>()
                    .put("key", Integer.toString(i % numPartitions))
                    .put("value", "message:" + i).build();
            sink.writeTo(new DefaultMessageContainer(
                    new Message(TOPIC_NAME_PARTITION_BY_KEY, jsonMapper.writeValueAsBytes(msgMap)),
                    jsonMapper));
        }
        sink.close();
        System.out.println(sink.getStat());

        ConsumerConnector consumer = kafka.consumer.Consumer.createJavaConsumerConnector(
                createConsumerConfig("localhost:" + zk.getServerPort(), "gropuid"));
        Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
        topicCountMap.put(TOPIC_NAME_PARTITION_BY_KEY, 1);
        Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
        KafkaStream<byte[], byte[]> stream = consumerMap.get(TOPIC_NAME_PARTITION_BY_KEY).get(0);
        Map<Integer, Set<Map<String, Object>>> resultSet = new HashMap<Integer, Set<Map<String, Object>>>();
        for (int i = 0; i < messageCount; ++i) {
            MessageAndMetadata<byte[], byte[]> msgAndMeta = stream.iterator().next();
            System.out.println(new String(msgAndMeta.message()));

            Map<String, Object> msg = jsonMapper.readValue(new String(msgAndMeta.message()), new TypeReference<Map<String, Object>>() {});
            Set<Map<String, Object>> s = resultSet.get(msgAndMeta.partition());
            if (s == null) {
                s = new HashSet<Map<String, Object>>();
                resultSet.put(msgAndMeta.partition(), s);
            }
View Full Code Here

import static org.junit.Assert.fail;

public class TestJsonLine {
    @Test
    public void shouldReturnStaticRoutingKey() throws Exception {
        ObjectMapper jsonMapper = new DefaultObjectMapper();

        JsonLine jsonLine = new JsonLine(
                "staticRoutingKey",
                null,
                new DefaultObjectMapper());

        Map<String, Object> msgMap = new ImmutableMap.Builder<String, Object>().put("f1", "v1").put("f2", "v2").build();
        List<MessageContainer> messages = jsonLine.parse(jsonMapper.writeValueAsString(msgMap));
        assertEquals(messages.size(), 1);
        assertEquals(messages.get(0).getRoutingKey(), "staticRoutingKey");
        assertEquals(messages.get(0).getEntity(S3Consumer.typeReference), msgMap);
    }
View Full Code Here

        when(event.getLevel()).thenReturn(Level.INFO);
        when(event.getLoggerName()).thenReturn("TestLogger");
        when(event.getMessage()).thenReturn(logEvent);
        when(event.getThrowableStrRep()).thenReturn(new String[]{"StackTrace0", "StackTrace1"});

        Map<String, Object> formattedEvent = new DefaultObjectMapper().readValue(
                formatter.format(event),
                new TypeReference<Map<String, Object>>(){});

        assertEquals(formattedEvent.get("field1"), "value1");
        assertEquals(formattedEvent.get("field2"), 100);
View Full Code Here

        assertEquals(messages.get(0).getEntity(S3Consumer.typeReference), msgMap);
    }

    @Test
    public void shouldReturnRoutingKeyField() throws Exception {
        ObjectMapper jsonMapper = new DefaultObjectMapper();

        JsonLine jsonLine = new JsonLine(
                null,
                "f1",
                new DefaultObjectMapper());

        Map<String, Object> msgMap = new ImmutableMap.Builder<String, Object>().put("f1", "v1").put("f2", "v2").build();
        List<MessageContainer> messages = jsonLine.parse(jsonMapper.writeValueAsString(msgMap));
        assertEquals(messages.size(), 1);
        assertEquals(messages.get(0).getRoutingKey(), "v1");
        assertEquals(messages.get(0).getEntity(S3Consumer.typeReference), msgMap);
    }
View Full Code Here

        assertEquals(messages.get(0).getEntity(S3Consumer.typeReference), msgMap);
    }

    @Test
    public void shouldReturnStaticRoutingKeyOnNonExistingRoutingKeyField() throws Exception {
        ObjectMapper jsonMapper = new DefaultObjectMapper();

        JsonLine jsonLine = new JsonLine(
                "defaultRoutingKey",
                "f1",
                new DefaultObjectMapper());

        Map<String, Object> msgMap = new ImmutableMap.Builder<String, Object>().put("f3", "v3").put("f2", "v2").build();
        List<MessageContainer> messages = jsonLine.parse(jsonMapper.writeValueAsString(msgMap));
        assertEquals(messages.size(), 1);
        assertEquals(messages.get(0).getRoutingKey(), "defaultRoutingKey");
        assertEquals(messages.get(0).getEntity(S3Consumer.typeReference), msgMap);
    }
View Full Code Here

    @Test
    public void testWithNonParseableMessage() throws Exception {
        JsonLine jsonLine = new JsonLine(
                "defaultRoutingKey",
                "f1",
                new DefaultObjectMapper());

        List<MessageContainer> messages = jsonLine.parse("non_parseable_msg");
        assertEquals(messages.size(), 1);
        assertEquals(messages.get(0).getRoutingKey(), "defaultRoutingKey");
        try {
            messages.get(0).getEntity(S3Consumer.typeReference);
            assertEquals(messages.get(0).getEntity(String.class), "non_parseable_msg");
            fail("exception should be thrown");
        } catch (Exception e) {}

        jsonLine = new JsonLine(
                null,
                "f1",
                new DefaultObjectMapper());
        assertEquals(jsonLine.parse("non_parseable_msg").size(), 0);
    }
View Full Code Here

   
    @Inject
    public JsonLog4jFormatter(ClientConfig config, ObjectMapper jsonMapper) {
        this.config     = config;
        if (jsonMapper == null)
            this.jsonMapper = new DefaultObjectMapper();
        else
            this.jsonMapper = jsonMapper;
        fmt = DateTimeFormat.forPattern(config.getLog4jDateTimeFormat());
        stringFormatter = new StringLog4jFormatter(config);
View Full Code Here

        TopicCommand.createTopic(zk.getZkClient(),
                new TopicCommand.TopicCommandOptions(new String[]{
                        "--zookeeper", "dummy", "--create", "--topic", TOPIC_NAME,
                        "--replication-factor", "2", "--partitions", "1"}));

        final ObjectMapper jsonMapper = new DefaultObjectMapper();

        final KafkaSink kafkaSink = createKafkaProducer(jsonMapper, kafkaServer.getBrokerListStr());

        Client client = createMockedESClient();
View Full Code Here

                "    \"client.id\": \"kafkasink\",\n" +
                "    \"metadata.broker.list\": \"" + kafkaServer.getBrokerListStr() + "\",\n" +
                "    \"request.required.acks\": 1\n" +
                "}";

        ObjectMapper jsonMapper = new DefaultObjectMapper();
        jsonMapper.registerSubtypes(new NamedType(KafkaSinkV2.class, "kafka"));
        KafkaSinkV2 sink = jsonMapper.readValue(description, new TypeReference<Sink>(){});
        sink.open();
        // create send test messages to Kafka
        Iterator<Message> msgIterator = new MessageSetReader(createMessageSet(TOPIC_NAME, 2)).iterator();
        HashSet<String> sentPayloads = new HashSet<String>(); // track sent messages for comparison later
        while (msgIterator.hasNext()) {
View Full Code Here

TOP

Related Classes of com.netflix.suro.jackson.DefaultObjectMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.