Search in sources :

Example 6 with LogMessage

use of com.yahoo.log.LogMessage in project vespa by vespa-engine.

the class MetricsFilterTestCase method testValueEvents.

@Test
public void testValueEvents() throws InvalidLogFormatException, IOException {
    MetricsFilter filter = new MetricsFilter();
    String filename = "src/test/files/value-events.txt";
    BufferedReader br = new BufferedReader(new FileReader(filename));
    for (String line = br.readLine(); line != null; line = br.readLine()) {
        LogMessage m = LogMessage.parseNativeFormat(line);
        assertNotNull(m);
        try {
            Event event = m.getEvent();
            assertNotNull(event);
        } catch (MalformedEventException e) {
            fail();
        }
        if (filter.isLoggable(m)) {
            assertTrue(true);
        } else {
            fail();
        }
    }
}
Also used : LogMessage(com.yahoo.log.LogMessage) MalformedEventException(com.yahoo.log.event.MalformedEventException) BufferedReader(java.io.BufferedReader) Event(com.yahoo.log.event.Event) FileReader(java.io.FileReader) MetricsFilter(com.yahoo.logserver.filter.MetricsFilter)

Example 7 with LogMessage

use of com.yahoo.log.LogMessage in project vespa by vespa-engine.

the class TextFormatterTestCase method testSpecificMessage.

/**
 * Test that a specific log message is formatted correctly
 */
@Test
public void testSpecificMessage() throws InvalidLogFormatException {
    String l = "1115200798.195568\texample.yahoo.com\t65819\ttopleveldispatch\tfdispatch.queryperf\tevent\tvalue/1 name=\"query_eval_time_avg_s\" value=0.0229635972697721825";
    String result = "2005-05-04 09:59:58 example.yahoo.com 65819 topleveldispatch fdispatch.queryperf EVENT value/1 name=\"query_eval_time_avg_s\" value=0.0229635972697721825\n";
    LogMessage m = LogMessage.parseNativeFormat(l);
    TextFormatter tf = new TextFormatter();
    assertEquals(result, tf.format(m));
}
Also used : TextFormatter(com.yahoo.logserver.formatter.TextFormatter) LogMessage(com.yahoo.log.LogMessage)

Example 8 with LogMessage

use of com.yahoo.log.LogMessage in project vespa by vespa-engine.

the class TextFormatterTestCase method testTextFormatter.

/**
 * Just simple test to make sure it doesn't die on us
 */
@Test
public void testTextFormatter() {
    TextFormatter tf = new TextFormatter();
    LogMessage[] ms = MockLogEntries.getMessages();
    for (int i = 0; i < ms.length; i++) {
        System.out.println(tf.format(ms[i]));
    }
}
Also used : TextFormatter(com.yahoo.logserver.formatter.TextFormatter) LogMessage(com.yahoo.log.LogMessage)

Example 9 with LogMessage

use of com.yahoo.log.LogMessage in project vespa by vespa-engine.

the class ArchiverHandlerTestCase method testFilenameCreation.

/**
 * Test that the ArchiverHandler creates correct filenames.
 */
@Test
public void testFilenameCreation() throws IOException {
    File tmpDir = temporaryFolder.newFolder();
    try {
        ArchiverHandler a = new ArchiverHandler(tmpDir.getAbsolutePath(), 1024);
        LogMessage msg1 = LogMessage.parseNativeFormat("1139322725\thost\tthread\tservice\tcomponent\tinfo\tpayload");
        LogMessage msg2 = LogMessage.parseNativeFormat("1161172200\thost\tthread\tservice\tcomponent\tinfo\tpayload");
        assertEquals(tmpDir.getAbsolutePath() + "/2006/02/07/14", a.getPrefix(msg1));
        assertEquals(tmpDir.getAbsolutePath() + "/2006/10/18/11", a.getPrefix(msg2));
        assertEquals(a.getPrefix(msg1).length(), a.getPrefix(msg2).length());
        a.close();
    } catch (InvalidLogFormatException e) {
        fail(e.toString());
    } finally {
        IOUtils.recursiveDeleteDir(tmpDir);
    }
}
Also used : LogMessage(com.yahoo.log.LogMessage) InvalidLogFormatException(com.yahoo.log.InvalidLogFormatException) File(java.io.File)

Example 10 with LogMessage

use of com.yahoo.log.LogMessage in project vespa by vespa-engine.

the class HandlerThreadTestCase method testHandlerThread.

@Test
public void testHandlerThread() throws InterruptedException, InvalidLogFormatException {
    HandlerThread thread = new HandlerThread("myThread");
    LogDispatcherTestCase.MockHandler h1 = new LogDispatcherTestCase.MockHandler();
    LogDispatcherTestCase.MockHandler h2 = new LogDispatcherTestCase.MockHandler();
    LogDispatcherTestCase.MockHandler h3 = new LogDispatcherTestCase.MockHandler();
    thread.registerHandler(h1);
    thread.registerHandler(h2);
    thread.registerHandler(h3);
    thread.start();
    String msgstr1 = "1098709001\t" + "nalle.puh.com\t" + "23234\t" + "serviceName\t" + "tst\t" + "info\t" + "this is a test";
    String msgstr2 = "1098709002\t" + "nalle.puh.com\t" + "23234\t" + "serviceName1\t" + "tst\t" + "info\t" + "this is a test too";
    String msgstr3 = "1098709003\t" + "nalle.puh.com\t" + "23234\t" + "serviceName3\t" + "tst\t" + "info\t" + "this is a test also";
    final LogMessage msg1 = LogMessage.parseNativeFormat(msgstr1);
    final LogMessage msg2 = LogMessage.parseNativeFormat(msgstr2);
    final LogMessage msg3 = LogMessage.parseNativeFormat(msgstr3);
    thread.handle(msg1);
    while ((h1.messages.size() < 1) || (h2.messages.size() < 1) || (h3.messages.size() < 1)) {
        Thread.sleep(10);
    }
    assertEquals(h1.messages.size(), 1);
    assertEquals(h2.messages.size(), 1);
    assertEquals(h3.messages.size(), 1);
    thread.handle(new ArrayList<LogMessage>() {

        {
            add(msg1);
            add(msg2);
            add(msg3);
        }
    });
    while ((h1.messages.size() < 4) || (h2.messages.size() < 4) || (h3.messages.size() < 4)) {
        Thread.sleep(10);
    }
    assertEquals(h1.messages.size(), 4);
    assertEquals(h2.messages.size(), 4);
    assertEquals(h3.messages.size(), 4);
    assertTrue(thread.getQueue().isEmpty());
    thread.unregisterHandler(h3);
    assertEquals(thread.getHandlers().length, 2);
    thread.flush();
    thread.close();
    thread.interrupt();
    thread.join();
}
Also used : LogMessage(com.yahoo.log.LogMessage) LogDispatcherTestCase(com.yahoo.logserver.test.LogDispatcherTestCase) Test(org.junit.Test)

Aggregations

LogMessage (com.yahoo.log.LogMessage)19 InvalidLogFormatException (com.yahoo.log.InvalidLogFormatException)5 BufferedReader (java.io.BufferedReader)5 MalformedEventException (com.yahoo.log.event.MalformedEventException)4 FileReader (java.io.FileReader)4 Test (org.junit.Test)4 Event (com.yahoo.log.event.Event)3 MetricsFilter (com.yahoo.logserver.filter.MetricsFilter)2 TextFormatter (com.yahoo.logserver.formatter.TextFormatter)2 LogMetricsHandler (com.yahoo.logserver.handlers.logmetrics.LogMetricsHandler)2 LogDispatcherTestCase (com.yahoo.logserver.test.LogDispatcherTestCase)2 File (java.io.File)2 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LogDispatcher (com.yahoo.logserver.LogDispatcher)1 LogFilter (com.yahoo.logserver.filter.LogFilter)1 NoMetricsFilter (com.yahoo.logserver.filter.NoMetricsFilter)1 LogFormatter (com.yahoo.logserver.formatter.LogFormatter)1 NullFormatter (com.yahoo.logserver.formatter.NullFormatter)1 AbstractLogHandler (com.yahoo.logserver.handlers.AbstractLogHandler)1