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));
}
}
Aggregations