aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-testrunner-components/src/test/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandlerTest.java
blob: a91b13080807e1f831fc88273c6090db0a73446f (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
package com.yahoo.vespa.hosted.testrunner;

import com.yahoo.vespa.config.SlimeUtils;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.time.Instant;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import static org.junit.Assert.assertEquals;

/**
 * @author jvenstad
 */
public class TestRunnerHandlerTest {

    @Test
    public void logSerialization() throws IOException {
        LogRecord record = new LogRecord(Level.INFO, "Hello.");
        record.setSequenceNumber(1);
        record.setInstant(Instant.ofEpochMilli(2));
        Exception exception = new RuntimeException();
        record.setThrown(exception);
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        exception.printStackTrace(new PrintStream(buffer));
        String trace = buffer.toString()
                             .replaceAll("\n", "\\\\n")
                             .replaceAll("\t", "\\\\t");
        assertEquals("[{\"id\":1,\"at\":2,\"type\":\"info\",\"message\":\"Hello.\\n" + trace + "\"}]",
                     new String(SlimeUtils.toJsonBytes(TestRunnerHandler.toSlime(Collections.singletonList(record)))));
    }

}