Search in sources :

Example 31 with ByteIterator

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

the class GridDBClient method insert.

public Status insert(String table, String key, Map<String, ByteIterator> values) {
    try {
        Object rowKey = makeRowKey(key);
        String containerKey = makeContainerKey(key);
        final Container<Object, Row> container = store.getContainer(containerKey);
        if (container == null) {
            LOGGER.severe("[ERROR]getCollection " + containerKey + " in insert()");
        }
        Row row = container.createRow();
        row.setValue(ROW_KEY_COLUMN_POS, rowKey);
        for (int i = 1; i < containerInfo.getColumnCount(); i++) {
            ByteIterator byteIterator = values.get(containerInfo.getColumnInfo(i).getName());
            Object value = makeValue(byteIterator);
            row.setValue(i, value);
        }
        container.put(row);
    } catch (GSException e) {
        LOGGER.severe("Exception: " + e.getMessage());
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) Row(com.toshiba.mwcloud.gs.Row) GSException(com.toshiba.mwcloud.gs.GSException)

Example 32 with ByteIterator

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

the class GridDBClientTest method insertToDatabase.

/**
 * Insert data to GridbDB database for testing
 */
private void insertToDatabase() {
    HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
    // The number of field in container info is 10
    for (int i = 0; i < FIELD_COUNT; i++) {
        values.put(VALUE_COLUMN_NAME_PREFIX + i, new StringByteIterator("value" + i));
    }
    myClient.insert(TEST_TABLE, DEFAULT_ROW_KEY, values);
}
Also used : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator)

Example 33 with ByteIterator

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

the class GridDBClientTest method testReadSingleRow.

@Test
public void testReadSingleRow() {
    Set<String> fields = Collections.singleton("field1");
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    insertToDatabase();
    Status readStatus = myClient.read(TEST_TABLE, DEFAULT_ROW_KEY, fields, result);
    assertEquals(readStatus, Status.OK);
    assertNotEquals(result.entrySet(), 0);
    for (String key : fields) {
        ByteIterator iter = result.get(key);
        byte[] byteArray1 = iter.toArray();
        String value = new String(byteArray1);
        assertEquals(value, "value1");
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 34 with ByteIterator

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

the class GridDBClientTest method testReadNoExistedRow.

@Test
public void testReadNoExistedRow() {
    Set<String> fields = Collections.singleton("field0");
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    insertToDatabase();
    Status readStatus = myClient.read(TEST_TABLE, "Missing row", fields, 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 35 with ByteIterator

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

the class GridDBClientTest method testInsert.

@Test
public void testInsert() {
    HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    // The number of field in container info is 10
    for (int i = 0; i < FIELD_COUNT; i++) {
        values.put("field" + i, new StringByteIterator("value" + i));
    }
    Status insertStatus = myClient.insert(TEST_TABLE, DEFAULT_ROW_KEY, values);
    assertEquals(insertStatus, Status.OK);
    myClient.read(TEST_TABLE, DEFAULT_ROW_KEY, null, result);
    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) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

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