Search in sources :

Example 86 with ByteIterator

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

the class RiakUtils method createResultHashMap.

/**
 * Function that retrieves all the fields searched within a read or scan operation and puts them in the result
 * HashMap.
 *
 * @param fields        The list of fields to read, or null for all of them.
 * @param response      A Vector of HashMaps, where each HashMap is a set field/value pairs for one record.
 * @param resultHashMap The HashMap to return as result.
 */
static void createResultHashMap(Set<String> fields, FetchValue.Response response, HashMap<String, ByteIterator> resultHashMap) {
    // If everything went fine, then a result must be given. Such an object is a hash table containing the (field,
    // value) pairs based on the requested fields. Note that in a read operation, ONLY ONE OBJECT IS RETRIEVED!
    // The following line retrieves the previously serialized table which was store with an insert transaction.
    byte[] responseFieldsAndValues = response.getValues().get(0).getValue().getValue();
    // Deserialize the stored response table.
    HashMap<String, ByteIterator> deserializedTable = new HashMap<>();
    deserializeTable(responseFieldsAndValues, deserializedTable);
    // If only specific fields are requested, then only these should be put in the result object!
    if (fields != null) {
        // Populate the HashMap to provide as result.
        for (Object field : fields.toArray()) {
            // Comparison between a requested field and the ones retrieved. If they're equal (i.e. the get() operation
            // DOES NOT return a null value), then  proceed to store the pair in the resultHashMap.
            ByteIterator value = deserializedTable.get(field);
            if (value != null) {
                resultHashMap.put((String) field, value);
            }
        }
    } else {
        // If, instead, no field is specified, then all those retrieved must be provided as result.
        for (String field : deserializedTable.keySet()) {
            resultHashMap.put(field, deserializedTable.get(field));
        }
    }
}
Also used : ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) HashMap(java.util.HashMap)

Example 87 with ByteIterator

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

the class VoltDBClientTest method insertAndReadTest.

@Test
public void insertAndReadTest() {
    Assume.assumeTrue(haveDb);
    try {
        // Create some test data
        final String insertKey = INSERT_TEST_KEY;
        final Set<String> columns = getColumnNameMap();
        // Insert row
        HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
        for (int i = 0; i < NUM_FIELDS; i++) {
            insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
        }
        voltClient.insert(TABLE_NAME, insertKey, insertMap);
        // Create a object to put retrieved row in...
        Map<String, ByteIterator> testResult = new HashMap<String, ByteIterator>();
        // Read row...
        Status s = voltClient.read(TABLE_NAME, insertKey, columns, testResult);
        if (!s.equals(Status.OK)) {
            fail("Didn't get OK on read.");
        }
        if (!compareContents(insertMap, testResult)) {
            fail("Returned data not the same as inserted data");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed insertTest");
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Assume.assumeNoException(org.junit.Assume.assumeNoException) DBException(site.ycsb.DBException)

Example 88 with ByteIterator

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

the class VoltDBClientTest method insertDeleteAndReadTest.

@Test
public void insertDeleteAndReadTest() {
    Assume.assumeTrue(haveDb);
    try {
        // Create some test data
        final String insertKey = INSERT_DELETE_AND_READ_TEST_KEY;
        final Set<String> columns = getColumnNameMap();
        // Insert row
        HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
        for (int i = 0; i < NUM_FIELDS; i++) {
            insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
        }
        voltClient.insert(TABLE_NAME, insertKey, insertMap);
        // Create a object to put retrieved row in...
        Map<String, ByteIterator> testResult = new HashMap<String, ByteIterator>();
        // Read row...
        Status s = voltClient.read(TABLE_NAME, insertKey, columns, testResult);
        if (!s.equals(Status.OK)) {
            fail("Didn't get OK on read.");
        }
        if (!compareContents(insertMap, testResult)) {
            fail("Returned data not the same as inserted data");
        }
        voltClient.delete(TABLE_NAME, insertKey);
        // Create another object to put retrieved row in...
        Map<String, ByteIterator> testResultAfterDelete = new HashMap<String, ByteIterator>();
        // Read row...
        voltClient.read(TABLE_NAME, insertKey, columns, testResultAfterDelete);
        if (testResultAfterDelete.size() > 0) {
            fail("testResultAfterDelete has value.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed insertDeleteAndReadTest");
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Assume.assumeNoException(org.junit.Assume.assumeNoException) DBException(site.ycsb.DBException)

Example 89 with ByteIterator

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

the class VoltDBClientTest method compareContents.

private boolean compareContents(HashMap<String, ByteIterator> inMsg, Map<String, ByteIterator> outMsg) {
    if (inMsg == null) {
        return false;
    }
    if (outMsg == null) {
        return false;
    }
    if (inMsg.size() != outMsg.size()) {
        return false;
    }
    @SuppressWarnings("rawtypes") Iterator it = inMsg.entrySet().iterator();
    while (it.hasNext()) {
        @SuppressWarnings("rawtypes") Map.Entry pair = (Map.Entry) it.next();
        String key = (String) pair.getKey();
        ByteIterator inPayload = inMsg.get(key);
        inPayload.reset();
        ByteIterator outPayload = outMsg.get(key);
        outPayload.reset();
        if (inPayload.bytesLeft() != outPayload.bytesLeft()) {
            return false;
        }
        while (inPayload.hasNext()) {
            byte inByte = inPayload.nextByte();
            byte outByte = outPayload.nextByte();
            if (inByte != outByte) {
                return false;
            }
        }
        it.remove();
    }
    return true;
}
Also used : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) Iterator(java.util.Iterator) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 90 with ByteIterator

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

the class VoltDBClientTest method singleScanReadTest.

private void singleScanReadTest(String startKey, int requestedCount, int expectedCount, String lastKey) {
    Assume.assumeTrue(haveDb);
    try {
        final Set<String> columns = getColumnNameMap();
        // Create a object to put retrieved row in...
        Vector<HashMap<String, ByteIterator>> testResult = new Vector<HashMap<String, ByteIterator>>();
        // Read row...
        Status s = voltClient.scan(TABLE_NAME, startKey, expectedCount, columns, testResult);
        if (!s.equals(Status.OK)) {
            fail("Didn't get OK on read.");
        }
        if (testResult.size() != expectedCount) {
            fail("Failed singleScanReadTest " + startKey + " " + expectedCount + " " + lastKey);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed singleScanReadTest " + startKey + ". Asked for " + requestedCount + ", expected " + expectedCount + " lastkey=" + lastKey);
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Vector(java.util.Vector) Assume.assumeNoException(org.junit.Assume.assumeNoException) DBException(site.ycsb.DBException)

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