Search in sources :

Example 66 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class GridDBClientTest method testReadAll.

@Test
public void testReadAll() {
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    insertToDatabase();
    Status readStatus = myClient.read(TEST_TABLE, DEFAULT_ROW_KEY, null, result);
    assertEquals(readStatus, Status.OK);
    assertEquals(result.size(), FIELD_COUNT);
    for (int i = 0; i < FIELD_COUNT; i++) {
        ByteIterator iter = result.get("field" + i);
        byte[] byteArray1 = iter.toArray();
        String value = new String(byteArray1);
        assertEquals(value, "value" + i);
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 67 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class GridDBClientTest method testDelete.

@Test
public void testDelete() {
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    insertToDatabase();
    Status deleteStatus = myClient.delete(TEST_TABLE, DEFAULT_ROW_KEY);
    assertEquals(deleteStatus, Status.OK);
    Status readStatus = myClient.read(TEST_TABLE, DEFAULT_ROW_KEY, null, result);
    assertEquals(readStatus, Status.ERROR);
    assertEquals(result.size(), 0);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 68 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class HBaseClient1Test method testRead.

@Test
public void testRead() throws Exception {
    final String rowKey = "row1";
    final Put p = new Put(Bytes.toBytes(rowKey));
    p.addColumn(Bytes.toBytes(COLUMN_FAMILY), Bytes.toBytes("column1"), Bytes.toBytes("value1"));
    p.addColumn(Bytes.toBytes(COLUMN_FAMILY), Bytes.toBytes("column2"), Bytes.toBytes("value2"));
    table.put(p);
    final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    final Status status = client.read(tableName, rowKey, null, result);
    assertEquals(Status.OK, status);
    assertEquals(2, result.size());
    assertEquals("value1", result.get("column1").toString());
    assertEquals("value2", result.get("column2").toString());
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 69 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class TimeSeriesWorkload method doTransactionRead.

protected void doTransactionRead(final DB db, Object threadstate) {
    final ThreadState state = (ThreadState) threadstate;
    final String keyname = keys[keychooser.nextValue().intValue()];
    final Random random = ThreadLocalRandom.current();
    int offsets = state.queryOffsetGenerator.nextValue().intValue();
    // int offsets = random.nextInt(maxOffsets - 1);
    final long startTimestamp;
    if (offsets > 0) {
        startTimestamp = state.startTimestamp + state.timestampGenerator.getOffset(offsets);
    } else {
        startTimestamp = state.startTimestamp;
    }
    // rando tags
    Set<String> fields = new HashSet<String>();
    for (int i = 0; i < tagPairs; ++i) {
        if (groupBy && groupBys[i]) {
            fields.add(tagKeys[i]);
        } else {
            fields.add(tagKeys[i] + tagPairDelimiter + tagValues[random.nextInt(tagCardinality[i])]);
        }
    }
    if (queryTimeSpan > 0) {
        final long endTimestamp;
        if (queryRandomTimeSpan) {
            endTimestamp = startTimestamp + (timestampInterval * random.nextInt(queryTimeSpan / timestampInterval));
        } else {
            endTimestamp = startTimestamp + queryTimeSpan;
        }
        fields.add(timestampKey + tagPairDelimiter + startTimestamp + queryTimeSpanDelimiter + endTimestamp);
    } else {
        fields.add(timestampKey + tagPairDelimiter + startTimestamp);
    }
    if (groupBy) {
        fields.add(groupByKey + tagPairDelimiter + groupByFunction);
    }
    if (downsample) {
        fields.add(downsampleKey + tagPairDelimiter + downsampleFunction + downsampleInterval);
    }
    final Map<String, ByteIterator> cells = new HashMap<String, ByteIterator>();
    final Status status = db.read(table, keyname, fields, cells);
    if (dataintegrity && status == Status.OK) {
        verifyRow(keyname, cells);
    }
}
Also used : Status(site.ycsb.Status) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) NumericByteIterator(site.ycsb.NumericByteIterator) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 70 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class TimeSeriesWorkload method doTransactionScan.

protected void doTransactionScan(final DB db, Object threadstate) {
    final ThreadState state = (ThreadState) threadstate;
    final Random random = ThreadLocalRandom.current();
    final String keyname = keys[random.nextInt(keys.length)];
    // choose a random scan length
    int len = scanlength.nextValue().intValue();
    int offsets = random.nextInt(maxOffsets - 1);
    final long startTimestamp;
    if (offsets > 0) {
        startTimestamp = state.startTimestamp + state.timestampGenerator.getOffset(offsets);
    } else {
        startTimestamp = state.startTimestamp;
    }
    // rando tags
    Set<String> fields = new HashSet<String>();
    for (int i = 0; i < tagPairs; ++i) {
        if (groupBy && groupBys[i]) {
            fields.add(tagKeys[i]);
        } else {
            fields.add(tagKeys[i] + tagPairDelimiter + tagValues[random.nextInt(tagCardinality[i])]);
        }
    }
    if (queryTimeSpan > 0) {
        final long endTimestamp;
        if (queryRandomTimeSpan) {
            endTimestamp = startTimestamp + (timestampInterval * random.nextInt(queryTimeSpan / timestampInterval));
        } else {
            endTimestamp = startTimestamp + queryTimeSpan;
        }
        fields.add(timestampKey + tagPairDelimiter + startTimestamp + queryTimeSpanDelimiter + endTimestamp);
    } else {
        fields.add(timestampKey + tagPairDelimiter + startTimestamp);
    }
    if (groupBy) {
        fields.add(groupByKey + tagPairDelimiter + groupByFunction);
    }
    if (downsample) {
        fields.add(downsampleKey + tagPairDelimiter + downsampleFunction + tagPairDelimiter + downsampleInterval);
    }
    final Vector<HashMap<String, ByteIterator>> results = new Vector<HashMap<String, ByteIterator>>();
    db.scan(table, keyname, len, fields, results);
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) NumericByteIterator(site.ycsb.NumericByteIterator) HashMap(java.util.HashMap) Vector(java.util.Vector) HashSet(java.util.HashSet)

Aggregations

ByteIterator (site.ycsb.ByteIterator)131 HashMap (java.util.HashMap)98 StringByteIterator (site.ycsb.StringByteIterator)92 Status (site.ycsb.Status)62 Test (org.junit.Test)53 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)34 DBException (site.ycsb.DBException)30 Map (java.util.Map)20 IOException (java.io.IOException)10 Put (org.apache.hadoop.hbase.client.Put)8 ArrayList (java.util.ArrayList)7 Vector (java.util.Vector)7 ByteBuffer (java.nio.ByteBuffer)6 HashSet (java.util.HashSet)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 NumericByteIterator (site.ycsb.NumericByteIterator)5 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)4 Properties (java.util.Properties)4 Assume.assumeNoException (org.junit.Assume.assumeNoException)4 DB (site.ycsb.DB)4