Search in sources :

Example 11 with ScanResult

use of org.apache.accumulo.proxy.thrift.ScanResult in project accumulo by apache.

the class TestProxyClient method main.

public static void main(String[] args) throws Exception {
    TestProxyClient tpc = new TestProxyClient("localhost", 42424);
    String principal = "root";
    Map<String, String> props = new TreeMap<>();
    props.put("password", "secret");
    System.out.println("Logging in");
    ByteBuffer login = tpc.proxy.login(principal, props);
    System.out.println("Creating user: ");
    if (!tpc.proxy().listLocalUsers(login).contains("testuser")) {
        tpc.proxy().createLocalUser(login, "testuser", ByteBuffer.wrap("testpass".getBytes(UTF_8)));
    }
    System.out.println("UserList: " + tpc.proxy().listLocalUsers(login));
    System.out.println("Listing: " + tpc.proxy().listTables(login));
    System.out.println("Deleting: ");
    String testTable = "testtableOMGOMGOMG";
    System.out.println("Creating: ");
    if (tpc.proxy().tableExists(login, testTable))
        tpc.proxy().deleteTable(login, testTable);
    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
    System.out.println("Listing: " + tpc.proxy().listTables(login));
    System.out.println("Writing: ");
    Date start = new Date();
    Date then = new Date();
    int maxInserts = 1000000;
    String format = "%1$05d";
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    for (int i = 0; i < maxInserts; i++) {
        String result = String.format(format, i);
        ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(UTF_8)), ByteBuffer.wrap(("cq" + i).getBytes(UTF_8)));
        update.setValue(Util.randStringBuffer(10));
        mutations.put(ByteBuffer.wrap(result.getBytes(UTF_8)), Collections.singletonList(update));
        if (i % 1000 == 0) {
            tpc.proxy().updateAndFlush(login, testTable, mutations);
            mutations.clear();
        }
    }
    tpc.proxy().updateAndFlush(login, testTable, mutations);
    Date end = new Date();
    System.out.println(" End of writing: " + (end.getTime() - start.getTime()));
    tpc.proxy().deleteTable(login, testTable);
    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
    // Thread.sleep(1000);
    System.out.println("Writing async: ");
    start = new Date();
    then = new Date();
    mutations.clear();
    String writer = tpc.proxy().createWriter(login, testTable, null);
    for (int i = 0; i < maxInserts; i++) {
        String result = String.format(format, i);
        Key pkey = new Key();
        pkey.setRow(result.getBytes(UTF_8));
        ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(UTF_8)), ByteBuffer.wrap(("cq" + i).getBytes(UTF_8)));
        update.setValue(Util.randStringBuffer(10));
        mutations.put(ByteBuffer.wrap(result.getBytes(UTF_8)), Collections.singletonList(update));
        tpc.proxy().update(writer, mutations);
        mutations.clear();
    }
    end = new Date();
    System.out.println(" End of writing: " + (end.getTime() - start.getTime()));
    start = end;
    System.out.println("Closing...");
    tpc.proxy().closeWriter(writer);
    end = new Date();
    System.out.println(" End of closing: " + (end.getTime() - start.getTime()));
    System.out.println("Reading: ");
    String regex = "cf1.*";
    IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class);
    RegExFilter.setRegexs(is, null, regex, null, null, false);
    String cookie = tpc.proxy().createScanner(login, testTable, null);
    int i = 0;
    start = new Date();
    then = new Date();
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        Date now = new Date();
        System.out.println(i + " " + (now.getTime() - then.getTime()));
        then = now;
        i += kvList.getResultsSize();
        // for (TKeyValue kv:kvList.getResults()) System.out.println(new Key(kv.getKey()));
        hasNext = kvList.isMore();
    }
    end = new Date();
    System.out.println("Total entries: " + i + " total time " + (end.getTime() - start.getTime()));
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) List(java.util.List) Key(org.apache.accumulo.proxy.thrift.Key)

Example 12 with ScanResult

use of org.apache.accumulo.proxy.thrift.ScanResult in project accumulo by apache.

the class TestProxyReadWrite method readWriteBatchOneShotWithColumnFamilyOnly.

/**
 * Insert 100000 cells which have as the row [0..99999] (padded with zeros). Set a columnFamily so only the entries with specified column family come back
 * (there should be 50,000)
 */
@Test
public void readWriteBatchOneShotWithColumnFamilyOnly() throws Exception {
    int maxInserts = 100000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    for (int i = 0; i < maxInserts; i++) {
        addMutation(mutations, String.format(format, i), "cf" + (i % 2), "cq" + (i % 2), Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().updateAndFlush(userpass, testtable, mutations);
            mutations.clear();
        }
    }
    BatchScanOptions options = new BatchScanOptions();
    ScanColumn sc = new ScanColumn();
    sc.colFamily = ByteBuffer.wrap("cf0".getBytes());
    options.columns = Collections.singletonList(sc);
    String cookie = tpc.proxy().createBatchScanner(userpass, testtable, options);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        i += kvList.getResultsSize();
        hasNext = kvList.isMore();
    }
    assertEquals(i, 50000);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) HashMap(java.util.HashMap) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) List(java.util.List) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 13 with ScanResult

use of org.apache.accumulo.proxy.thrift.ScanResult in project accumulo by apache.

the class TestProxyReadWrite method manyWritesAndReads.

// @Test
// This test takes kind of a long time. Enable it if you think you may have memory issues.
public void manyWritesAndReads() throws Exception {
    int maxInserts = 1000000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$06d";
    String writer = tpc.proxy().createWriter(userpass, testtable, null);
    for (int i = 0; i < maxInserts; i++) {
        addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().update(writer, mutations);
            mutations.clear();
        }
    }
    tpc.proxy().flush(writer);
    tpc.proxy().closeWriter(writer);
    String cookie = tpc.proxy().createScanner(userpass, testtable, null);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        for (KeyValue kv : kvList.getResults()) {
            assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
            i++;
        }
        hasNext = kvList.isMore();
        if (hasNext)
            assertEquals(k, kvList.getResults().size());
    }
    assertEquals(maxInserts, i);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) HashMap(java.util.HashMap) List(java.util.List) ByteBuffer(java.nio.ByteBuffer)

Example 14 with ScanResult

use of org.apache.accumulo.proxy.thrift.ScanResult in project accumulo by apache.

the class TestProxyReadWrite method readWriteOneShotWithRange.

@Test
public void readWriteOneShotWithRange() throws Exception {
    int maxInserts = 100000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    for (int i = 0; i < maxInserts; i++) {
        addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().updateAndFlush(userpass, testtable, mutations);
            mutations.clear();
        }
    }
    Key stop = new Key();
    stop.setRow("5".getBytes());
    ScanOptions opts = new ScanOptions();
    opts.range = new Range(null, false, stop, false);
    String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        i += kvList.getResultsSize();
        hasNext = kvList.isMore();
    }
    assertEquals(i, 50000);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) HashMap(java.util.HashMap) List(java.util.List) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) Range(org.apache.accumulo.proxy.thrift.Range) ByteBuffer(java.nio.ByteBuffer) Key(org.apache.accumulo.proxy.thrift.Key) Test(org.junit.Test)

Example 15 with ScanResult

use of org.apache.accumulo.proxy.thrift.ScanResult in project accumulo by apache.

the class TestProxyReadWrite method readWriteBatchOneShotWithRange.

/**
 * Insert 100000 cells which have as the row [0..99999] (padded with zeros). Set a range so only the entries between -Inf...5 come back (there should be
 * 50,000)
 */
@Test
public void readWriteBatchOneShotWithRange() throws Exception {
    int maxInserts = 100000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    for (int i = 0; i < maxInserts; i++) {
        addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().updateAndFlush(userpass, testtable, mutations);
            mutations.clear();
        }
    }
    Key stop = new Key();
    stop.setRow("5".getBytes());
    BatchScanOptions options = new BatchScanOptions();
    options.ranges = Collections.singletonList(new Range(null, false, stop, false));
    String cookie = tpc.proxy().createBatchScanner(userpass, testtable, options);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        i += kvList.getResultsSize();
        hasNext = kvList.isMore();
    }
    assertEquals(i, 50000);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) HashMap(java.util.HashMap) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) List(java.util.List) Range(org.apache.accumulo.proxy.thrift.Range) ByteBuffer(java.nio.ByteBuffer) Key(org.apache.accumulo.proxy.thrift.Key) Test(org.junit.Test)

Aggregations

ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)16 ByteBuffer (java.nio.ByteBuffer)13 HashMap (java.util.HashMap)12 List (java.util.List)12 Test (org.junit.Test)11 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)10 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)8 ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)8 Key (org.apache.accumulo.proxy.thrift.Key)5 ColumnUpdate (org.apache.accumulo.proxy.thrift.ColumnUpdate)3 IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)3 Range (org.apache.accumulo.proxy.thrift.Range)3 ScanColumn (org.apache.accumulo.proxy.thrift.ScanColumn)3 Value (org.apache.accumulo.core.data.Value)2 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1