Search in sources :

Example 6 with TIllegalArgument

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

the class TestThriftHBaseServiceHandler method testScan.

@Test
public void testScan() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    // insert data
    TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(columnValue);
    for (int i = 0; i < 10; i++) {
        TPut put = new TPut(wrap(("testScan" + i).getBytes()), columnValues);
        handler.put(table, put);
    }
    // create scan instance
    TScan scan = new TScan();
    List<TColumn> columns = new ArrayList<>(1);
    TColumn column = new TColumn();
    column.setFamily(familyAname);
    column.setQualifier(qualifierAname);
    columns.add(column);
    scan.setColumns(columns);
    scan.setStartRow("testScan".getBytes());
    scan.setStopRow("testScan￿".getBytes());
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = handler.getScannerRows(scanId, 10);
    assertEquals(10, results.size());
    for (int i = 0; i < 10; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testScan" + i).getBytes(), results.get(i).getRow());
    }
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 10);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 10);
        fail("Scanner id should be invalid");
    } catch (TIllegalArgument e) {
    }
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 7 with TIllegalArgument

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

the class TestThriftHBaseServiceHandler method testReverseScan.

@Test
public void testReverseScan() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    // insert data
    TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(columnValue);
    for (int i = 0; i < 10; i++) {
        TPut put = new TPut(wrap(("testReverseScan" + i).getBytes()), columnValues);
        handler.put(table, put);
    }
    // create reverse scan instance
    TScan scan = new TScan();
    scan.setReversed(true);
    List<TColumn> columns = new ArrayList<>(1);
    TColumn column = new TColumn();
    column.setFamily(familyAname);
    column.setQualifier(qualifierAname);
    columns.add(column);
    scan.setColumns(columns);
    scan.setStartRow("testReverseScan￿".getBytes());
    scan.setStopRow("testReverseScan".getBytes());
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = handler.getScannerRows(scanId, 10);
    assertEquals(10, results.size());
    for (int i = 0; i < 10; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testReverseScan" + (9 - i)).getBytes(), results.get(i).getRow());
    }
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 10);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 10);
        fail("Scanner id should be invalid");
    } catch (TIllegalArgument e) {
    }
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 8 with TIllegalArgument

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

the class TestThriftHBaseServiceHandlerWithLabels method testScanWithVisibilityLabels.

@Test
public void testScanWithVisibilityLabels() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    // insert data
    TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(columnValue);
    for (int i = 0; i < 10; i++) {
        TPut put = new TPut(wrap(("testScan" + i).getBytes()), columnValues);
        if (i == 5) {
            put.setCellVisibility(new TCellVisibility().setExpression(PUBLIC));
        } else {
            put.setCellVisibility(new TCellVisibility().setExpression("(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET));
        }
        handler.put(table, put);
    }
    // create scan instance
    TScan scan = new TScan();
    List<TColumn> columns = new ArrayList<>(1);
    TColumn column = new TColumn();
    column.setFamily(familyAname);
    column.setQualifier(qualifierAname);
    columns.add(column);
    scan.setColumns(columns);
    scan.setStartRow("testScan".getBytes());
    scan.setStopRow("testScan￿".getBytes());
    TAuthorization tauth = new TAuthorization();
    List<String> labels = new ArrayList<>(2);
    labels.add(SECRET);
    labels.add(PRIVATE);
    tauth.setLabels(labels);
    scan.setAuthorizations(tauth);
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = handler.getScannerRows(scanId, 10);
    assertEquals(9, results.size());
    Assert.assertFalse(Bytes.equals(results.get(5).getRow(), ("testScan" + 5).getBytes()));
    for (int i = 0; i < 9; i++) {
        if (i < 5) {
            assertArrayEquals(("testScan" + i).getBytes(), results.get(i).getRow());
        } else if (i == 5) {
            continue;
        } else {
            assertArrayEquals(("testScan" + (i + 1)).getBytes(), results.get(i).getRow());
        }
    }
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 9);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 9);
        fail("Scanner id should be invalid");
    } catch (TIllegalArgument e) {
    }
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TAuthorization(org.apache.hadoop.hbase.thrift2.generated.TAuthorization) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Aggregations

TIllegalArgument (org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument)8 ByteBuffer (java.nio.ByteBuffer)6 ArrayList (java.util.ArrayList)6 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)6 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)6 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)6 TScan (org.apache.hadoop.hbase.thrift2.generated.TScan)6 Test (org.junit.Test)6 TColumn (org.apache.hadoop.hbase.thrift2.generated.TColumn)5 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 TAuthorization (org.apache.hadoop.hbase.thrift2.generated.TAuthorization)1 TCellVisibility (org.apache.hadoop.hbase.thrift2.generated.TCellVisibility)1 TTimeRange (org.apache.hadoop.hbase.thrift2.generated.TTimeRange)1