aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/logging/LocalDiskLoggerTest.java
blob: 292f0b7d376449f50f82f54318dd6a9bc881990f (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

package com.yahoo.search.logging;

import com.yahoo.io.IOUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Base64;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class LocalDiskLoggerTest {

    @TempDir
    Path tempDir;

    @Test
    public void testLocalDiskLogger() throws InterruptedException, IOException {
        File logFile = tempDir.resolve("localdisklogger.log").toFile();

        LocalDiskLoggerConfig.Builder builder = new LocalDiskLoggerConfig.Builder();
        builder.path(logFile.getAbsolutePath());
        LocalDiskLogger logger = new LocalDiskLogger(builder.build());

        logger.newEntry()
                .blob("my entry blob content".getBytes())
                .track("my-track")
                .send();
        logger.deconstruct();

        String test = IOUtils.readAll(new FileReader(logFile));
        assertTrue(test.contains(Base64.getEncoder().encodeToString("my entry blob content".getBytes())));
        assertTrue(test.contains("my-track"));
    }

}