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();
}
}
}
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));
}
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]));
}
}
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);
}
}
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();
}
Aggregations