Search in sources :

Example 16 with StringByteIterator

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

the class VoltDBClientTest method scanReadTest.

@Test
public void scanReadTest() {
    Assume.assumeTrue(haveDb);
    try {
        for (int z = 0; z < SCAN_RECORD_COUNT; z++) {
            // Create some test data
            final String insertKey = SCAN_KEY_PREFIX + z;
            // 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("Data for " + SCAN_KEY_PREFIX + z + " element " + i));
            }
            voltClient.insert(TABLE_NAME, insertKey, insertMap);
        }
        final String firstInsertKey = SCAN_KEY_PREFIX + 0;
        final String lastInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 1);
        final String beyondLastInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT + 1);
        final String oneHundredFromEndInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 101);
        final String fiftyFromEndInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 101);
        // test non existent records
        singleScanReadTest(NON_EXISTENT_KEY, 1000, 0, NON_EXISTENT_KEY);
        // test single record
        singleScanReadTest(firstInsertKey, 1, 1, firstInsertKey);
        // test scan of SCAN_RECORD_COUNT records
        singleScanReadTest(firstInsertKey, SCAN_RECORD_COUNT, SCAN_RECORD_COUNT, lastInsertKey);
        // test single record in middle
        singleScanReadTest(oneHundredFromEndInsertKey, 1, 1, oneHundredFromEndInsertKey);
        // test request of 100 starting 50 from end.
        singleScanReadTest(fiftyFromEndInsertKey, 100, 50, lastInsertKey);
        // test request of 100 starting beyond the end
        singleScanReadTest(beyondLastInsertKey, 100, 0, lastInsertKey);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed scanReadTest");
    }
}
Also used : 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 17 with StringByteIterator

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

the class RestClientTest method insert_404.

@Test
public void insert_404() {
    HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
    data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
    Status status = rc.insert(null, ABSENT_RESOURCE, data);
    assertEquals(Status.NOT_FOUND, status);
}
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)

Example 18 with StringByteIterator

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

the class RestClientTest method update_500.

@Test
public void update_500() {
    HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
    data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
    Status status = rc.update(null, INVALID_RESOURCE, data);
    assertEquals(Status.ERROR, status);
}
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)

Example 19 with StringByteIterator

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

the class GoogleDatastoreClient method read.

@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    LookupRequest.Builder lookupRequest = LookupRequest.newBuilder();
    lookupRequest.addKeys(buildPrimaryKey(table, key));
    lookupRequest.getReadOptionsBuilder().setReadConsistency(this.readConsistency);
    // Note above, datastore lookupRequest always reads the entire entity, it
    // does not support reading a subset of "fields" (properties) of an entity.
    logger.debug("Built lookup request as: " + lookupRequest.toString());
    LookupResponse response = null;
    try {
        response = datastore.lookup(lookupRequest.build());
    } catch (DatastoreException exception) {
        logger.error(String.format("Datastore Exception when reading (%s): %s %s", exception.getMessage(), exception.getMethodName(), exception.getCode()));
        // will bubble up to the user as part of the YCSB Status "name".
        return new Status("ERROR-" + exception.getCode(), exception.getMessage());
    }
    if (response.getFoundCount() == 0) {
        return new Status("ERROR-404", "Not Found, key is: " + key);
    } else if (response.getFoundCount() > 1) {
        // entity back. Unexpected State.
        return Status.UNEXPECTED_STATE;
    }
    Entity entity = response.getFound(0).getEntity();
    logger.debug("Read entity: " + entity.toString());
    Map<String, Value> properties = entity.getProperties();
    Set<String> propertiesToReturn = (fields == null ? properties.keySet() : fields);
    for (String name : propertiesToReturn) {
        if (properties.containsKey(name)) {
            result.put(name, new StringByteIterator(properties.get(name).getStringValue()));
        }
    }
    return Status.OK;
}
Also used : Status(site.ycsb.Status) StringByteIterator(site.ycsb.StringByteIterator) DatastoreException(com.google.datastore.v1.client.DatastoreException)

Example 20 with StringByteIterator

use of site.ycsb.StringByteIterator 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)

Aggregations

StringByteIterator (site.ycsb.StringByteIterator)49 ByteIterator (site.ycsb.ByteIterator)32 HashMap (java.util.HashMap)31 Status (site.ycsb.Status)19 DBException (site.ycsb.DBException)15 Test (org.junit.Test)12 Map (java.util.Map)8 IOException (java.io.IOException)5 Assume.assumeNoException (org.junit.Assume.assumeNoException)4 UnknownHostException (java.net.UnknownHostException)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 SearchHit (org.elasticsearch.search.SearchHit)3 JsonObject (com.couchbase.client.java.document.json.JsonObject)2 Collections.emptyMap (java.util.Collections.emptyMap)2 User (org.apache.gora.benchmark.generated.User)2 GoraException (org.apache.gora.util.GoraException)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2