aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/test/java/com/yahoo/vespa/config/LZ4PayloadCompressorTest.java
blob: a1957a439698f6f632a747d88f4f4a5548c0fb08 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config;

import com.yahoo.text.Utf8;
import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;

/**
 * @author Ulf Lilleengen
 */
public class LZ4PayloadCompressorTest {

    @Test
    public void testCompression() {
        assertCompression("hei hallo der");
        assertCompression("");
        assertCompression("{}");
    }

    private void assertCompression(String input) {
        LZ4PayloadCompressor compressor = new LZ4PayloadCompressor();
        byte[] data = Utf8.toBytes(input);
        byte[] compressed = compressor.compress(data);
        byte[] output = compressor.decompress(compressed, data.length);
        assertArrayEquals(output, data);
    }
}