Search in sources :

Example 1 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandler method testExists.

@Test
public void testExists() throws TIOError, TException {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = Bytes.toBytes("testExists");
    ByteBuffer table = wrap(tableAname);
    TGet get = new TGet(wrap(rowName));
    assertFalse(handler.exists(table, get));
    List<TColumnValue> columnValues = new ArrayList<>(2);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
    TPut put = new TPut(wrap(rowName), columnValues);
    put.setColumnValues(columnValues);
    handler.put(table, put);
    assertTrue(handler.exists(table, get));
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandler method testExistsAll.

@Test
public void testExistsAll() throws TIOError, TException {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName1 = Bytes.toBytes("testExistsAll1");
    byte[] rowName2 = Bytes.toBytes("testExistsAll2");
    ByteBuffer table = wrap(tableAname);
    List<TGet> gets = new ArrayList<>();
    gets.add(new TGet(wrap(rowName2)));
    gets.add(new TGet(wrap(rowName2)));
    List<Boolean> existsResult1 = handler.existsAll(table, gets);
    assertFalse(existsResult1.get(0));
    assertFalse(existsResult1.get(1));
    List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
    List<TPut> puts = new ArrayList<TPut>();
    puts.add(new TPut(wrap(rowName1), columnValues));
    puts.add(new TPut(wrap(rowName2), columnValues));
    handler.putMultiple(table, puts);
    List<Boolean> existsResult2 = handler.existsAll(table, gets);
    assertTrue(existsResult2.get(0));
    assertTrue(existsResult2.get(1));
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithReadOnly method testCheckAndMutateWithReadOnly.

@Test
public void testCheckAndMutateWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    ByteBuffer row = wrap(Bytes.toBytes("row"));
    ByteBuffer family = wrap(familyAname);
    ByteBuffer qualifier = wrap(qualifierAname);
    ByteBuffer value = wrap(valueAname);
    List<TColumnValue> columnValuesB = new ArrayList<>(1);
    TColumnValue columnValueB = new TColumnValue(family, wrap(qualifierBname), wrap(valueBname));
    columnValuesB.add(columnValueB);
    TPut putB = new TPut(row, columnValuesB);
    putB.setColumnValues(columnValuesB);
    TRowMutations tRowMutations = new TRowMutations(row, Arrays.<TMutation>asList(TMutation.put(putB)));
    boolean exceptionCaught = false;
    try {
        handler.checkAndMutate(table, row, family, qualifier, TCompareOperator.EQUAL, value, tRowMutations);
    } catch (TIOError e) {
        exceptionCaught = true;
        assertTrue(e.getCause() instanceof DoNotRetryIOException);
        assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
    } finally {
        assertTrue(exceptionCaught);
    }
}
Also used : TIOError(org.apache.hadoop.hbase.thrift2.generated.TIOError) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ArrayList(java.util.ArrayList) TRowMutations(org.apache.hadoop.hbase.thrift2.generated.TRowMutations) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithReadOnly method testCheckAndDeleteWithReadOnly.

@Test
public void testCheckAndDeleteWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = Bytes.toBytes("testCheckAndDelete");
    ByteBuffer table = wrap(tableAname);
    TDelete delete = new TDelete(wrap(rowName));
    boolean exceptionCaught = false;
    try {
        handler.checkAndDelete(table, wrap(rowName), wrap(familyAname), wrap(qualifierAname), wrap(valueAname), delete);
    } catch (TIOError e) {
        exceptionCaught = true;
        assertTrue(e.getCause() instanceof DoNotRetryIOException);
        assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
    } finally {
        assertTrue(exceptionCaught);
    }
}
Also used : TIOError(org.apache.hadoop.hbase.thrift2.generated.TIOError) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithReadOnly method testIncrementWithReadOnly.

@Test
public void testIncrementWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = Bytes.toBytes("testIncrement");
    ByteBuffer table = wrap(tableAname);
    List<TColumnIncrement> incrementColumns = new ArrayList<>(1);
    incrementColumns.add(new TColumnIncrement(wrap(familyAname), wrap(qualifierAname)));
    TIncrement increment = new TIncrement(wrap(rowName), incrementColumns);
    boolean exceptionCaught = false;
    try {
        handler.increment(table, increment);
    } catch (TIOError e) {
        exceptionCaught = true;
        assertTrue(e.getCause() instanceof DoNotRetryIOException);
        assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
    } finally {
        assertTrue(exceptionCaught);
    }
}
Also used : TIOError(org.apache.hadoop.hbase.thrift2.generated.TIOError) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TColumnIncrement(org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement) ArrayList(java.util.ArrayList) TIncrement(org.apache.hadoop.hbase.thrift2.generated.TIncrement) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)29 IOException (java.io.IOException)18 ByteBuffer (java.nio.ByteBuffer)17 Test (org.junit.Test)17 TIOError (org.apache.hadoop.hbase.thrift2.generated.TIOError)16 ArrayList (java.util.ArrayList)12 TableName (org.apache.hadoop.hbase.TableName)9 TTableName (org.apache.hadoop.hbase.thrift2.generated.TTableName)9 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)8 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)7 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)6 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)4 TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)4 TTableDescriptor (org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor)4 Pattern (java.util.regex.Pattern)2 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)2 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)2 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 TColumnFamilyDescriptor (org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor)2 TNamespaceDescriptor (org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor)2