Search in sources :

Example 11 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testLongValue.

@Test
public void testLongValue() throws Exception {
    final Inspector value = getData().entry(2);
    assertThat(value.valid(), is(true));
    assertThat(value.type(), is(Type.LONG));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(0));
    assertThat(new Try() {

        void f() {
            value.asBool();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asLong(), is(10L));
    assertThat(value.asDouble(), is(10.0));
    assertThat(new Try() {

        void f() {
            value.asString();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asUtf8();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asData();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asBool(true), is(true));
    assertThat(value.asLong(50), is(10L));
    assertThat(value.asDouble(20.25), is(10.0));
    assertThat(value.asString("default"), is("default"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("utf8".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is("data".getBytes("UTF-8")));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields.size(), is(0));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("foo").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields.size(), is(0));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Example 12 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testDoubleValue.

@Test
public void testDoubleValue() throws Exception {
    final Inspector value = getData().entry(3);
    assertThat(value.valid(), is(true));
    assertThat(value.type(), is(Type.DOUBLE));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(0));
    assertThat(new Try() {

        void f() {
            value.asBool();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asLong(), is(5L));
    assertThat(value.asDouble(), is(5.75));
    assertThat(new Try() {

        void f() {
            value.asString();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asUtf8();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asData();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asBool(true), is(true));
    assertThat(value.asLong(50), is(5L));
    assertThat(value.asDouble(20.25), is(5.75));
    assertThat(value.asString("default"), is("default"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("utf8".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is("data".getBytes("UTF-8")));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields.size(), is(0));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("foo").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields.size(), is(0));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Example 13 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class DocsumDefinitionSet method lazyDecode.

/**
 * Makes data available for decoding for the given hit.
 *
 * @param summaryClass the requested summary class
 * @param data docsum data from backend
 * @param hit the Hit corresponding to this document summary
 * @return Error message or null on success.
 * @throws ConfigurationException if the summary class of this hit is missing
 */
public final String lazyDecode(String summaryClass, byte[] data, FastHit hit) {
    ByteBuffer buffer = ByteBuffer.wrap(data);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    long docsumClassId = buffer.getInt();
    if (docsumClassId != SLIME_MAGIC_ID) {
        throw new IllegalArgumentException("Only expecting SchemaLess docsums - summary class:" + summaryClass + " hit:" + hit);
    }
    DocsumDefinition docsumDefinition = lookupDocsum(summaryClass);
    Slime value = BinaryFormat.decode(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
    Inspector docsum = new SlimeAdapter(value.get());
    if (docsum.type() != OBJECT) {
        return "Hit " + hit + " failed: " + docsum.asString();
    }
    hit.addSummary(docsumDefinition, docsum);
    return null;
}
Also used : SlimeAdapter(com.yahoo.data.access.slime.SlimeAdapter) Inspector(com.yahoo.data.access.Inspector) Slime(com.yahoo.slime.Slime) ByteBuffer(java.nio.ByteBuffer)

Example 14 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testDataValue.

@Test
public void testDataValue() throws Exception {
    final Inspector value = getData().entry(4).field("bar");
    assertThat(value.valid(), is(true));
    assertThat(value.type(), is(Type.DATA));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(0));
    assertThat(new Try() {

        void f() {
            value.asBool();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asLong();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asDouble();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asString();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asUtf8();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asData(), is(new byte[] { (byte) 4, (byte) 2 }));
    assertThat(value.asBool(true), is(true));
    assertThat(value.asLong(50), is(50L));
    assertThat(value.asDouble(20.25), is(20.25));
    assertThat(value.asString("default"), is("default"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("utf8".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is(new byte[] { (byte) 4, (byte) 2 }));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields.size(), is(0));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("foo").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields.size(), is(0));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Example 15 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testEmptyValue.

@Test
public void testEmptyValue() throws Exception {
    final Inspector value = getData().entry(0);
    assertThat(value.valid(), is(true));
    assertThat(value.type(), is(Type.EMPTY));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(0));
    assertThat(value.asBool(), is(false));
    assertThat(value.asLong(), is(0L));
    assertThat(value.asDouble(), is(0.0));
    assertThat(value.asString(), is(""));
    assertThat(value.asUtf8(), is(new byte[0]));
    assertThat(value.asData(), is(new byte[0]));
    assertThat(value.asBool(true), is(true));
    assertThat(value.asLong(50), is(50L));
    assertThat(value.asDouble(20.25), is(20.25));
    assertThat(value.asString("default"), is("default"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("utf8".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is("data".getBytes("UTF-8")));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields.size(), is(0));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("foo").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields.size(), is(0));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Aggregations

Inspector (com.yahoo.data.access.Inspector)21 Test (org.junit.Test)19 JSONString (com.yahoo.prelude.hitfield.JSONString)8 Value (com.yahoo.data.access.simple.Value)6 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)1 Slime (com.yahoo.slime.Slime)1 ByteBuffer (java.nio.ByteBuffer)1