Search in sources :

Example 1 with Status

use of com.yahoo.ycsb.Status in project YCSB by brianfrankcooper.

the class ElasticsearchClientTest method testRead.

/**
     * Test of read method, of class ElasticsearchClient.
     */
@Test
public void testRead() {
    System.out.println("read");
    Set<String> fields = MOCK_DATA.keySet();
    HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10);
    Status result = instance.read(MOCK_TABLE, MOCK_KEY1, fields, resultParam);
    assertEquals(Status.OK, result);
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with Status

use of com.yahoo.ycsb.Status in project YCSB by brianfrankcooper.

the class ElasticsearchClientTest method testUpdate.

/**
     * Test of update method, of class ElasticsearchClient.
     */
@Test
public void testUpdate() {
    System.out.println("update");
    int i;
    HashMap<String, ByteIterator> newValues = new HashMap<String, ByteIterator>(10);
    for (i = 1; i <= 10; i++) {
        newValues.put("field" + i, new StringByteIterator("newvalue" + i));
    }
    Status result = instance.update(MOCK_TABLE, MOCK_KEY1, newValues);
    assertEquals(Status.OK, result);
    //validate that the values changed
    HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10);
    instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);
    for (i = 1; i <= 10; i++) {
        assertEquals("newvalue" + i, resultParam.get("field" + i).toString());
    }
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) StringByteIterator(com.yahoo.ycsb.StringByteIterator) Test(org.junit.Test)

Example 3 with Status

use of com.yahoo.ycsb.Status in project YCSB by brianfrankcooper.

the class ElasticsearchClientTest method testScan.

/**
     * Test of scan method, of class ElasticsearchClient.
     */
@Test
public void testScan() {
    System.out.println("scan");
    int recordcount = 10;
    Set<String> fields = MOCK_DATA.keySet();
    Vector<HashMap<String, ByteIterator>> resultParam = new Vector<HashMap<String, ByteIterator>>(10);
    Status result = instance.scan(MOCK_TABLE, MOCK_KEY1, recordcount, fields, resultParam);
    assertEquals(Status.OK, result);
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) Vector(java.util.Vector) Test(org.junit.Test)

Example 4 with Status

use of com.yahoo.ycsb.Status in project YCSB by brianfrankcooper.

the class GoogleDatastoreClient method read.

@Override
public Status read(String table, String key, Set<String> fields, HashMap<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(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) DatastoreException(com.google.datastore.v1.client.DatastoreException)

Example 5 with Status

use of com.yahoo.ycsb.Status in project YCSB by brianfrankcooper.

the class GoogleDatastoreClient method doSingleItemMutation.

private Status doSingleItemMutation(String table, String key, @Nullable HashMap<String, ByteIterator> values, MutationType mutationType) {
    // First build the key.
    Key.Builder datastoreKey = buildPrimaryKey(table, key);
    // Build a commit request in non-transactional mode.
    // Single item mutation to google datastore
    // is always atomic and strongly consistent. Transaction is only necessary
    // for multi-item mutation, or Read-modify-write operation.
    CommitRequest.Builder commitRequest = CommitRequest.newBuilder();
    commitRequest.setMode(Mode.NON_TRANSACTIONAL);
    if (mutationType == MutationType.DELETE) {
        commitRequest.addMutationsBuilder().setDelete(datastoreKey);
    } else {
        // If this is not for delete, build the entity.
        Entity.Builder entityBuilder = Entity.newBuilder();
        entityBuilder.setKey(datastoreKey);
        for (Entry<String, ByteIterator> val : values.entrySet()) {
            entityBuilder.getMutableProperties().put(val.getKey(), Value.newBuilder().setStringValue(val.getValue().toString()).build());
        }
        Entity entity = entityBuilder.build();
        logger.debug("entity built as: " + entity.toString());
        if (mutationType == MutationType.UPSERT) {
            commitRequest.addMutationsBuilder().setUpsert(entity);
        } else if (mutationType == MutationType.UPDATE) {
            commitRequest.addMutationsBuilder().setUpdate(entity);
        } else {
            throw new RuntimeException("Impossible MutationType, code bug.");
        }
    }
    try {
        datastore.commit(commitRequest.build());
        logger.debug("successfully committed.");
    } catch (DatastoreException exception) {
        // Catch all Datastore rpc errors.
        // Log the exception, the name of the method called and the error code.
        logger.error(String.format("Datastore Exception when committing (%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());
    }
    return Status.OK;
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) DatastoreException(com.google.datastore.v1.client.DatastoreException)

Aggregations

Status (com.yahoo.ycsb.Status)54 Test (org.junit.Test)39 HashMap (java.util.HashMap)38 ByteIterator (com.yahoo.ycsb.ByteIterator)33 StringByteIterator (com.yahoo.ycsb.StringByteIterator)31 Vector (java.util.Vector)5 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)4 DB (com.yahoo.ycsb.DB)4 DatastoreException (com.google.datastore.v1.client.DatastoreException)2 Get (org.apache.hadoop.hbase.client.Get)2 Put (org.apache.hadoop.hbase.client.Put)2 Result (org.apache.hadoop.hbase.client.Result)2 ReadOp (com.ceph.rados.ReadOp)1 ReadResult (com.ceph.rados.ReadOp.ReadResult)1 RadosException (com.ceph.rados.exceptions.RadosException)1 RadosObjectInfo (com.ceph.rados.jna.RadosObjectInfo)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Select (com.datastax.driver.core.querybuilder.Select)1 DBException (com.yahoo.ycsb.DBException)1