Package org.graylog2.plugin

Examples of org.graylog2.plugin.Message


        assertEquals("somesubsystem", msg.getField("our_result"));
    }

    @Test
    public void testBasicExtractionWithCutStrategyCanOverwriteSameField() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "message", "message", config(4, 17), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertEquals("short message", msg.getField("message"));
    }
View Full Code Here


        assertEquals("short message", msg.getField("message"));
    }

    @Test
    public void testBasicExtractionDoesNotFailOnNonMatch() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001");

        SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config(100, 200), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertNull(msg.getField("our_result"));
        assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001", msg.getField("somefield"));
    }
View Full Code Here

    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
    }

    public void testAlwaysIncludeDefaultOutput() throws Exception {
        final Message message = mock(Message.class);
        final OutputRouter outputRouter = new OutputRouter(defaultMessageOutput, outputRegistry);

        final Collection<MessageOutput> messageOutputs = outputRouter.getOutputsForMessage(message);

        assertEquals(messageOutputs.size(), 1);
View Full Code Here

    public void testGetOutputFromSingleStreams() throws Exception {
        final Stream stream = mock(Stream.class);
        List<Stream> streamList = new ArrayList<Stream>() {{
            add(stream);
        }};
        final Message message = mock(Message.class);
        when(message.getStreams()).thenReturn(streamList);

        final MessageOutput messageOutput = mock(MessageOutput.class);
        final Set<MessageOutput> messageOutputList = new HashSet<MessageOutput>() {{ add(messageOutput); }};

        final OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
View Full Code Here

        assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001", msg.getField("somefield"));
    }

    @Test
    public void testBasicExtractionDoesNotFailOnNonMatchWithCutStrategy() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001");

        SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "somefield", "our_result", config(100, 200), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertNull(msg.getField("our_result"));
        assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001", msg.getField("somefield"));
    }
View Full Code Here

        final Stream stream2 = mock(Stream.class);
        final MessageOutput messageOutput1 = mock(MessageOutput.class);
        final Set<MessageOutput> messageOutputSet1 = new HashSet<MessageOutput>() {{ add(messageOutput1); }};
        final MessageOutput messageOutput2 = mock(MessageOutput.class);
        final Set<MessageOutput> messageOutputSet2 = new HashSet<MessageOutput>() {{ add(messageOutput2); }};
        final Message message = mock(Message.class);
        final List<Stream> streamList = new ArrayList<Stream>() {{ add(stream1); add(stream2); }};
        when(message.getStreams()).thenReturn(streamList);

        OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
        doReturn(messageOutputSet1).when(outputRouter).getMessageOutputsForStream(eq(stream1));
        doReturn(messageOutputSet2).when(outputRouter).getMessageOutputsForStream(eq(stream2));
View Full Code Here

    public void testGetOutputsWithIdenticalMessageOutputs() throws Exception {
        final Stream stream1 = mock(Stream.class);
        final Stream stream2 = mock(Stream.class);
        final MessageOutput messageOutput = mock(MessageOutput.class);
        final Set<MessageOutput> messageOutputSet = new HashSet<MessageOutput>() {{ add(messageOutput); }};
        final Message message = mock(Message.class);
        final List<Stream> streamList = new ArrayList<Stream>() {{ add(stream1); add(stream2); }};
        when(message.getStreams()).thenReturn(streamList);

        OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
        doReturn(messageOutputSet).when(outputRouter).getMessageOutputsForStream(eq(stream1));
        doReturn(messageOutputSet).when(outputRouter).getMessageOutputsForStream(eq(stream2));
View Full Code Here

    @Test
    public void shouldSerializeMessageCorrectly() throws Exception {
        final MessageToJsonSerializer serializer = new MessageToJsonSerializer(objectMapper, streamService, inputService);
        final DateTime now = Tools.iso8601();
        final Message message = new Message("test", "localhost", now);

        message.setSourceInput(messageInput);
        message.setStreams(Lists.newArrayList(stream));
        message.addField("test1", "hello");
        message.addField("test2", 1);
        message.addField("test3", 1.2);
        message.addField("test4", false);

        final String s = serializer.serializeToString(message);

        final Message newMessage = serializer.deserialize(s);

        assertEquals(newMessage.getField("timestamp"), now);
        assertEquals(newMessage.getMessage(), message.getMessage());
        assertEquals(newMessage.getSource(), message.getSource());
        assertEquals(newMessage.getSourceInput(), messageInput);
        assertEquals(newMessage.getStreams(), Lists.newArrayList(stream));
        assertEquals(newMessage.getField("test1"), "hello");
        assertEquals(newMessage.getField("test2"), 1);
        assertEquals(newMessage.getField("test3"), 1.2);
        assertEquals(newMessage.getField("test4"), false);

        // Just assert that the message id is not null because we cannot set the _id field on deserialize because the
        // Message object does not allow the _id field to be set.
        assertNotNull(newMessage.getId());

        // Make sure the injected ObjectMapper instance is copied before adding custom config.
        verify(objectMapper, times(1)).copy();
    }
View Full Code Here

        assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001", msg.getField("somefield"));
    }

    @Test
    public void testDoesNotFailOnNonExistentSourceField() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "LOLIDONTEXIST", "our_result", config(0,1), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);
    }
View Full Code Here

        x.runExtractor(msg);
    }

    @Test
    public void testDoesNotFailOnSourceFieldThatIsNotOfTypeString() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        msg.addField("somefield", 9001);

        SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "somefield", "our_result", config(0,1), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);
    }
View Full Code Here

TOP

Related Classes of org.graylog2.plugin.Message

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.