Search in sources :

Example 1 with LZ4PayloadCompressor

use of com.yahoo.vespa.config.LZ4PayloadCompressor in project vespa by vespa-engine.

the class PayloadTest method testEquals.

@Test
public void testEquals() {
    final String foo1 = "foo 1";
    final String foo2 = "foo 2";
    Payload a = Payload.from(foo1);
    Payload b = Payload.from(foo1);
    Payload c = Payload.from(foo2);
    Slime slime = new Slime();
    slime.setString(foo1);
    Payload d = Payload.from(new ConfigPayload(slime));
    slime.setString(foo1);
    Payload e = Payload.from(new ConfigPayload(slime));
    slime.setString("foo 2");
    Payload f = Payload.from(new ConfigPayload(slime));
    Payload g = null;
    Payload h = null;
    Payload i = null;
    Payload j = null;
    try {
        g = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        h = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        LZ4PayloadCompressor compressor = new LZ4PayloadCompressor();
        CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, foo2.length());
        Utf8Array compressed = new Utf8Array(compressor.compress(foo2.getBytes()));
        i = Payload.from(compressed, info);
        j = Payload.from(compressed, info);
    } catch (UnsupportedEncodingException e1) {
        fail();
    }
    new EqualsTester().addEqualityGroup(a, b, g, h).addEqualityGroup(c).addEqualityGroup(d, e).addEqualityGroup(f).addEqualityGroup(i, j).testEquals();
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) EqualsTester(com.google.common.testing.EqualsTester) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) LZ4PayloadCompressor(com.yahoo.vespa.config.LZ4PayloadCompressor) Slime(com.yahoo.slime.Slime) Utf8Array(com.yahoo.text.Utf8Array) Test(org.junit.Test)

Example 2 with LZ4PayloadCompressor

use of com.yahoo.vespa.config.LZ4PayloadCompressor in project vespa by vespa-engine.

the class ConfigResponseTest method require_that_slime_response_decompresses_on_serialize.

@Test
public void require_that_slime_response_decompresses_on_serialize() throws IOException {
    ConfigPayload configPayload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
    InnerCNode targetDef = dParser.getTree();
    Utf8Array data = configPayload.toUtf8Array(true);
    Utf8Array bytes = new Utf8Array(new LZ4PayloadCompressor().compress(data.getBytes()));
    ConfigResponse response = new SlimeConfigResponse(bytes, targetDef, 3, "mymd5", CompressionInfo.create(CompressionType.LZ4, data.getByteLength()));
    List<String> payload = response.getLegacyPayload();
    assertNotNull(payload);
    assertThat(payload.size(), is(6));
    assertThat(payload.get(0), is("boolval false"));
    assertThat(response.getGeneration(), is(3L));
    assertThat(response.getConfigMd5(), is("mymd5"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.serialize(baos, CompressionType.UNCOMPRESSED);
    assertThat(baos.toString(), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
Also used : SimpletypesConfig(com.yahoo.foo.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) StringReader(java.io.StringReader) LZ4PayloadCompressor(com.yahoo.vespa.config.LZ4PayloadCompressor) Utf8Array(com.yahoo.text.Utf8Array) Test(org.junit.Test)

Aggregations

Utf8Array (com.yahoo.text.Utf8Array)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 LZ4PayloadCompressor (com.yahoo.vespa.config.LZ4PayloadCompressor)2 Test (org.junit.Test)2 EqualsTester (com.google.common.testing.EqualsTester)1 DefParser (com.yahoo.config.codegen.DefParser)1 InnerCNode (com.yahoo.config.codegen.InnerCNode)1 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)1 Slime (com.yahoo.slime.Slime)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1