Search in sources :

Example 1 with GenericKeyValueBuilder

use of org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder in project phoenix by apache.

the class MetaDataUtilTest method testGetMutationKeyValue.

/**
   * Ensure it supports {@link GenericKeyValueBuilder}
   * @throws Exception on failure
   */
@Test
public void testGetMutationKeyValue() throws Exception {
    String version = VersionInfo.getVersion();
    KeyValueBuilder builder = KeyValueBuilder.get(version);
    byte[] row = Bytes.toBytes("row");
    byte[] family = PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
    byte[] qualifier = Bytes.toBytes("qual");
    byte[] value = Bytes.toBytes("generic-value");
    KeyValue kv = builder.buildPut(wrap(row), wrap(family), wrap(qualifier), wrap(value));
    Put put = new Put(row);
    KeyValueBuilder.addQuietly(put, builder, kv);
    // read back out the value
    ImmutableBytesPtr ptr = new ImmutableBytesPtr();
    assertTrue(MetaDataUtil.getMutationValue(put, qualifier, builder, ptr));
    assertEquals("Value returned doesn't match stored value for " + builder.getClass().getName() + "!", 0, ByteUtil.BYTES_PTR_COMPARATOR.compare(ptr, wrap(value)));
    // try again, this time with the clientkeyvalue builder
    if (builder != GenericKeyValueBuilder.INSTANCE) {
        builder = GenericKeyValueBuilder.INSTANCE;
        value = Bytes.toBytes("client-value");
        kv = builder.buildPut(wrap(row), wrap(family), wrap(qualifier), wrap(value));
        put = new Put(row);
        KeyValueBuilder.addQuietly(put, builder, kv);
        // read back out the value
        assertTrue(MetaDataUtil.getMutationValue(put, qualifier, builder, ptr));
        assertEquals("Value returned doesn't match stored value for " + builder.getClass().getName() + "!", 0, ByteUtil.BYTES_PTR_COMPARATOR.compare(ptr, wrap(value)));
        // ensure that we don't get matches for qualifiers that don't match
        assertFalse(MetaDataUtil.getMutationValue(put, Bytes.toBytes("not a match"), builder, ptr));
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) KeyValueBuilder(org.apache.phoenix.hbase.index.util.KeyValueBuilder) GenericKeyValueBuilder(org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Aggregations

KeyValue (org.apache.hadoop.hbase.KeyValue)1 Put (org.apache.hadoop.hbase.client.Put)1 GenericKeyValueBuilder (org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder)1 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)1 KeyValueBuilder (org.apache.phoenix.hbase.index.util.KeyValueBuilder)1 Test (org.junit.Test)1