aboutsummaryrefslogtreecommitdiffstats
path: root/vespalog/src/test/java/com/yahoo/log/LogMessageTestCase.java
blob: 5c6474314fc194c54f11e28e4fc0497788b54941 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.log;

import com.yahoo.log.event.Event;
import com.yahoo.log.event.MalformedEventException;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static org.junit.Assert.assertNotNull;

/**
 * Unit tests for the LogMessage class.
 *
 * @author Bjorn Borud
 * @author bjorncs
 */
public class LogMessageTestCase {

    @Test
    public void testLogParsing () throws IOException, InvalidLogFormatException {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(LogMessageTestCase.class.getResourceAsStream("/logEntries.txt")))) {
            for (String line = br.readLine(); line != null; line = br.readLine()) {
                LogMessage.parseNativeFormat(line);
            }
        }
    }

    /**
     * Read in some events and make sure we are able to identify
     * them as such.
     */
    @Test
    public void testEvents () throws IOException, InvalidLogFormatException, MalformedEventException {
        try (BufferedReader br =
                     new BufferedReader(
                             new InputStreamReader(
                                     LogMessageTestCase.class.getResourceAsStream("/event.txt")))) {
            for (String line = br.readLine(); line != null; line = br.readLine()) {
                LogMessage m = LogMessage.parseNativeFormat(line);
                Event event = m.getEvent();
                assertNotNull(event);
            }
        }

    }
}