Search in sources :

Example 21 with StringByteIterator

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

Example 22 with StringByteIterator

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

the class OrientDBClientTest method updateTest.

@Test
public void updateTest() {
    String preupdateString = "preupdate";
    String user0 = "user0";
    String user1 = "user1";
    String user2 = "user2";
    OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
    try (ODatabaseDocumentTx db = pool.acquire()) {
        // Manually insert three documents
        for (String key : Arrays.asList(user0, user1, user2)) {
            ODocument doc = new ODocument(CLASS);
            for (int i = 0; i < NUM_FIELDS; i++) {
                doc.field(FIELD_PREFIX + i, preupdateString);
            }
            doc.save();
            ODictionary<ORecord> dictionary = db.getDictionary();
            dictionary.put(key, doc);
        }
    }
    HashMap<String, ByteIterator> updateMap = new HashMap<>();
    for (int i = 0; i < NUM_FIELDS; i++) {
        updateMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(user1, FIELD_PREFIX + i)));
    }
    orientDBClient.update(CLASS, user1, updateMap);
    try (ODatabaseDocumentTx db = pool.acquire()) {
        ODictionary<ORecord> dictionary = db.getDictionary();
        // Ensure that user0 record was not changed
        ODocument result = dictionary.get(user0);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert first row fields contain preupdateString", result.field(FIELD_PREFIX + i), preupdateString);
        }
        // Check that all the columns have expected values for user1 record
        result = dictionary.get(user1);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert updated row fields are correct", result.field(FIELD_PREFIX + i), updateMap.get(FIELD_PREFIX + i).toString());
        }
        // Ensure that user2 record was not changed
        result = dictionary.get(user2);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert third row fields contain preupdateString", result.field(FIELD_PREFIX + i), preupdateString);
        }
    }
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) ByteIterator(site.ycsb.ByteIterator) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ORecord(com.orientechnologies.orient.core.record.ORecord) StringByteIterator(site.ycsb.StringByteIterator) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 23 with StringByteIterator

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

the class MemcachedClient method fromJson.

protected static void fromJson(String value, Set<String> fields, Map<String, ByteIterator> result) throws IOException {
    JsonNode json = MAPPER.readTree(value);
    boolean checkFields = fields != null && !fields.isEmpty();
    for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.getFields(); jsonFields.hasNext(); ) /* increment in loop body */
    {
        Map.Entry<String, JsonNode> jsonField = jsonFields.next();
        String name = jsonField.getKey();
        if (checkFields && !fields.contains(name)) {
            continue;
        }
        JsonNode jsonValue = jsonField.getValue();
        if (jsonValue != null && !jsonValue.isNull()) {
            result.put(name, new StringByteIterator(jsonValue.asText()));
        }
    }
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) JsonNode(org.codehaus.jackson.JsonNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with StringByteIterator

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

the class InfinispanClient method read.

public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    try {
        Map<String, String> row;
        if (clustered) {
            row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false);
        } else {
            Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
            row = cache.get(key);
        }
        if (row != null) {
            result.clear();
            if (fields == null || fields.isEmpty()) {
                StringByteIterator.putAllAsByteIterators(result, row);
            } else {
                for (String field : fields) {
                    result.put(field, new StringByteIterator(row.get(field)));
                }
            }
        }
        return Status.OK;
    } catch (Exception e) {
        LOGGER.error(e);
        return Status.ERROR;
    }
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) AtomicMap(org.infinispan.atomic.AtomicMap) Map(java.util.Map) IOException(java.io.IOException) DBException(site.ycsb.DBException)

Example 25 with StringByteIterator

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

the class JdbcDBClientTest method insertRow.

/*
        Inserts a row of deterministic values for the given insertKey using the jdbcDBClient.
     */
private HashMap<String, ByteIterator> insertRow(String insertKey) {
    HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
    for (int i = 0; i < 3; i++) {
        insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
    }
    jdbcDBClient.insert(TABLE_NAME, insertKey, insertMap);
    return insertMap;
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) ByteIterator(site.ycsb.ByteIterator) 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