use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto in project hbase by apache.
the class TestProtobufUtil method testDelete.
/**
* Test Delete Mutate conversions.
*
* @throws IOException if the conversion to a {@link Delete} or a
* {@link org.apache.hadoop.hbase.client.Mutation} fails
*/
@Test
public void testDelete() throws IOException {
MutationProto.Builder mutateBuilder = MutationProto.newBuilder();
mutateBuilder.setRow(ByteString.copyFromUtf8("row"));
mutateBuilder.setMutateType(MutationType.DELETE);
mutateBuilder.setTimestamp(111111);
ColumnValue.Builder valueBuilder = ColumnValue.newBuilder();
valueBuilder.setFamily(ByteString.copyFromUtf8("f1"));
QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder();
qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1"));
qualifierBuilder.setDeleteType(DeleteType.DELETE_ONE_VERSION);
qualifierBuilder.setTimestamp(111222);
valueBuilder.addQualifierValue(qualifierBuilder.build());
qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c2"));
qualifierBuilder.setDeleteType(DeleteType.DELETE_MULTIPLE_VERSIONS);
qualifierBuilder.setTimestamp(111333);
valueBuilder.addQualifierValue(qualifierBuilder.build());
mutateBuilder.addColumnValue(valueBuilder.build());
MutationProto proto = mutateBuilder.build();
// default fields
assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability());
// set the default value for equal comparison
mutateBuilder = MutationProto.newBuilder(proto);
mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT);
Delete delete = ProtobufUtil.toDelete(proto);
// add empty value to the original mutate
for (ColumnValue.Builder column : mutateBuilder.getColumnValueBuilderList()) {
for (QualifierValue.Builder qualifier : column.getQualifierValueBuilderList()) {
qualifier.setValue(ByteString.EMPTY);
}
}
assertEquals(mutateBuilder.build(), ProtobufUtil.toMutation(MutationType.DELETE, delete));
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto in project hbase by apache.
the class TestProtobufUtil method testAppend.
/**
* Test Append Mutate conversions.
*
* @throws IOException if converting to an {@link Append} fails
*/
@Test
public void testAppend() throws IOException {
MutationProto proto = getAppendMutation(111111L);
// default fields
assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability());
// set the default value for equal comparison
MutationProto.Builder mutateBuilder = MutationProto.newBuilder(proto);
mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT);
Append append = ProtobufUtil.toAppend(proto, null);
// append always use the latest timestamp,
// reset the timestamp to the original mutate
mutateBuilder.setTimestamp(append.getTimestamp());
mutateBuilder.setTimeRange(ProtobufUtil.toTimeRange(append.getTimeRange()));
assertEquals(mutateBuilder.build(), ProtobufUtil.toMutation(MutationType.APPEND, append));
}
Aggregations