Search in sources :

Example 36 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class TestPassCustomCellViaRegionObserver method testMutation.

@Test
public void testMutation() throws Exception {
    Put put = new Put(ROW);
    put.addColumn(FAMILY, QUALIFIER, VALUE);
    table.put(put);
    byte[] value = VALUE;
    assertResult(table.get(new Get(ROW)), value, value);
    assertObserverHasExecuted();
    Increment inc = new Increment(ROW);
    inc.addColumn(FAMILY, QUALIFIER, 10L);
    table.increment(inc);
    // QUALIFIER -> 10 (put) + 10 (increment)
    // QUALIFIER_FROM_CP -> 10 (from cp's put) + 10 (from cp's increment)
    value = Bytes.toBytes(20L);
    assertResult(table.get(new Get(ROW)), value, value);
    assertObserverHasExecuted();
    Append append = new Append(ROW);
    append.addColumn(FAMILY, QUALIFIER, APPEND_VALUE);
    table.append(append);
    // 10L + "MB"
    value = ByteBuffer.wrap(new byte[value.length + APPEND_VALUE.length]).put(value).put(APPEND_VALUE).array();
    assertResult(table.get(new Get(ROW)), value, value);
    assertObserverHasExecuted();
    Delete delete = new Delete(ROW);
    delete.addColumns(FAMILY, QUALIFIER);
    table.delete(delete);
    assertTrue(Arrays.asList(table.get(new Get(ROW)).rawCells()).toString(), table.get(new Get(ROW)).isEmpty());
    assertObserverHasExecuted();
    assertTrue(table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifNotExists().thenPut(put));
    assertObserverHasExecuted();
    assertTrue(table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifEquals(VALUE).thenDelete(delete));
    assertObserverHasExecuted();
    assertTrue(table.get(new Get(ROW)).isEmpty());
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Append(org.apache.hadoop.hbase.client.Append) Get(org.apache.hadoop.hbase.client.Get) Increment(org.apache.hadoop.hbase.client.Increment) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 37 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class TestRegionObserverInterface method testCheckAndAppendHooks.

@Test
public void testCheckAndAppendHooks() throws Exception {
    final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
    Table table = util.createTable(tableName, new byte[][] { A, B, C });
    try {
        byte[] row = Bytes.toBytes(0);
        verifyMethodResult(SimpleRegionObserver.class, new String[] { "getPreCheckAndMutate", "getPreCheckAndMutateAfterRowLock", "getPostCheckAndMutate" }, tableName, new Integer[] { 0, 0, 0 });
        table.checkAndMutate(CheckAndMutate.newBuilder(row).ifNotExists(A, A).build(new Append(row).addColumn(A, A, A)));
        verifyMethodResult(SimpleRegionObserver.class, new String[] { "getPreCheckAndMutate", "getPreCheckAndMutateAfterRowLock", "getPostCheckAndMutate" }, tableName, new Integer[] { 1, 1, 1 });
        table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(A, A, A).build(new Append(row).addColumn(A, A, A)));
        verifyMethodResult(SimpleRegionObserver.class, new String[] { "getPreCheckAndMutate", "getPreCheckAndMutateAfterRowLock", "getPostCheckAndMutate" }, tableName, new Integer[] { 2, 2, 2 });
    } finally {
        util.deleteTable(tableName);
        table.close();
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) Append(org.apache.hadoop.hbase.client.Append) Test(org.junit.Test)

Example 38 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class TestPostIncrementAndAppendBeforeWAL method testChangeCellWithDifferntColumnFamily.

@Test
public void testChangeCellWithDifferntColumnFamily() throws Exception {
    TableName tableName = TableName.valueOf(name.getMethodName());
    createTableWithCoprocessor(tableName, ChangeCellWithDifferntColumnFamilyObserver.class.getName());
    try (Table table = connection.getTable(tableName)) {
        Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
        table.increment(increment);
        Get get = new Get(ROW).addColumn(CF2_BYTES, CQ1);
        Result result = table.get(get);
        assertEquals(1, result.size());
        assertEquals(1, Bytes.toLong(result.getValue(CF2_BYTES, CQ1)));
        Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
        table.append(append);
        get = new Get(ROW).addColumn(CF2_BYTES, CQ2);
        result = table.get(get);
        assertEquals(1, result.size());
        assertTrue(Bytes.equals(VALUE, result.getValue(CF2_BYTES, CQ2)));
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) Append(org.apache.hadoop.hbase.client.Append) Increment(org.apache.hadoop.hbase.client.Increment) Get(org.apache.hadoop.hbase.client.Get) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 39 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class TestPostIncrementAndAppendBeforeWAL method testAppendTTLWithACLTag.

@Test
public void testAppendTTLWithACLTag() throws Exception {
    TableName tableName = TableName.valueOf(name.getMethodName());
    createTableWithCoprocessor(tableName, ChangeCellWithACLTagObserver.class.getName());
    try (Table table = connection.getTable(tableName)) {
        // Append without TTL
        Append firstAppend = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE).setACL(USER, PERMS);
        Result result = table.append(firstAppend);
        assertEquals(1, result.size());
        assertTrue(Bytes.equals(VALUE, result.getValue(CF1_BYTES, CQ2)));
        // Check if the new cell can be read
        Get get = new Get(ROW).addColumn(CF1_BYTES, CQ2);
        result = table.get(get);
        assertEquals(1, result.size());
        assertTrue(Bytes.equals(VALUE, result.getValue(CF1_BYTES, CQ2)));
        // Append with TTL
        Append secondAppend = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE).setTTL(1000).setACL(USER, PERMS);
        result = table.append(secondAppend);
        // We should get "valuevalue""
        assertEquals(1, result.size());
        assertTrue(Bytes.equals(VALUE2, result.getValue(CF1_BYTES, CQ2)));
        // Wait 4s to let the second append expire
        Thread.sleep(4000);
        get = new Get(ROW).addColumn(CF1_BYTES, CQ2);
        result = table.get(get);
        // The value should revert to "value"
        assertEquals(1, result.size());
        assertTrue(Bytes.equals(VALUE, result.getValue(CF1_BYTES, CQ2)));
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) Append(org.apache.hadoop.hbase.client.Append) Get(org.apache.hadoop.hbase.client.Get) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 40 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class TestIncrementAndAppendWithNullResult method testAppend.

@Test
public void testAppend() throws Exception {
    testAppend(new Append(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, Bytes.toBytes("value")));
    testAppend(new Append(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, Bytes.toBytes("value")).setReturnResults(false));
}
Also used : Append(org.apache.hadoop.hbase.client.Append) Test(org.junit.Test)

Aggregations

Append (org.apache.hadoop.hbase.client.Append)62 Test (org.junit.Test)31 Result (org.apache.hadoop.hbase.client.Result)26 Increment (org.apache.hadoop.hbase.client.Increment)25 Put (org.apache.hadoop.hbase.client.Put)23 IOException (java.io.IOException)17 Get (org.apache.hadoop.hbase.client.Get)17 Delete (org.apache.hadoop.hbase.client.Delete)16 Table (org.apache.hadoop.hbase.client.Table)15 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)10 TableName (org.apache.hadoop.hbase.TableName)10 RowMutations (org.apache.hadoop.hbase.client.RowMutations)10 Cell (org.apache.hadoop.hbase.Cell)9 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)8 Mutation (org.apache.hadoop.hbase.client.Mutation)7 ArrayList (java.util.ArrayList)5 CheckAndMutate (org.apache.hadoop.hbase.client.CheckAndMutate)5 MutationProto (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)5 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)5 List (java.util.List)4