Search in sources :

Example 46 with StringByteIterator

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

the class JdbcDBClient method read.

@Override
public Status read(String tableName, String key, Set<String> fields, Map<String, ByteIterator> result) {
    try {
        StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, "", getShardIndexByKey(key));
        PreparedStatement readStatement = cachedStatements.get(type);
        if (readStatement == null) {
            readStatement = createAndCacheReadStatement(type, key);
        }
        readStatement.setString(1, key);
        ResultSet resultSet = readStatement.executeQuery();
        if (!resultSet.next()) {
            resultSet.close();
            return Status.NOT_FOUND;
        }
        if (result != null && fields != null) {
            for (String field : fields) {
                String value = resultSet.getString(field);
                result.put(field, new StringByteIterator(value));
            }
        }
        resultSet.close();
        return Status.OK;
    } catch (SQLException e) {
        System.err.println("Error in processing read of table " + tableName + ": " + e);
        return Status.ERROR;
    }
}
Also used : StringByteIterator(site.ycsb.StringByteIterator)

Example 47 with StringByteIterator

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

the class RadosClient method read.

@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    byte[] buffer;
    try {
        RadosObjectInfo info = ioctx.stat(key);
        buffer = new byte[(int) info.getSize()];
        ReadOp rop = ioctx.readOpCreate();
        ReadResult readResult = rop.queueRead(0, info.getSize());
        // TODO: more size than byte length possible;
        // rop.operate(key, Rados.OPERATION_NOFLAG); // for rados-java 0.3.0
        rop.operate(key, 0);
        // readResult.raiseExceptionOnError("Error ReadOP(%d)", readResult.getRVal()); // for rados-java 0.3.0
        if (readResult.getRVal() < 0) {
            throw new RadosException("Error ReadOP", readResult.getRVal());
        }
        if (info.getSize() != readResult.getBytesRead()) {
            return new Status("ERROR", "Error the object size read");
        }
        readResult.getBuffer().get(buffer);
    } catch (RadosException e) {
        return new Status("ERROR-" + e.getReturnValue(), e.getMessage());
    }
    JSONObject json = new JSONObject(new String(buffer, java.nio.charset.StandardCharsets.UTF_8));
    Set<String> fieldsToReturn = (fields == null ? json.keySet() : fields);
    for (String name : fieldsToReturn) {
        result.put(name, new StringByteIterator(json.getString(name)));
    }
    return result.isEmpty() ? Status.ERROR : Status.OK;
}
Also used : RadosObjectInfo(com.ceph.rados.jna.RadosObjectInfo) Status(site.ycsb.Status) JSONObject(org.json.JSONObject) StringByteIterator(site.ycsb.StringByteIterator) ReadResult(com.ceph.rados.ReadOp.ReadResult) RadosException(com.ceph.rados.exceptions.RadosException) ReadOp(com.ceph.rados.ReadOp)

Example 48 with StringByteIterator

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

the class JdbcDBClientTest method updateTest.

@Test
public void updateTest() {
    try {
        String preupdateString = "preupdate";
        StringBuilder fauxInsertString = new StringBuilder(String.format("INSERT INTO %s VALUES(?", TABLE_NAME));
        for (int i = 0; i < NUM_FIELDS; i++) {
            fauxInsertString.append(",?");
        }
        fauxInsertString.append(")");
        PreparedStatement fauxInsertStatement = jdbcConnection.prepareStatement(fauxInsertString.toString());
        for (int i = 2; i < NUM_FIELDS + 2; i++) {
            fauxInsertStatement.setString(i, preupdateString);
        }
        fauxInsertStatement.setString(1, "user0");
        fauxInsertStatement.execute();
        fauxInsertStatement.setString(1, "user1");
        fauxInsertStatement.execute();
        fauxInsertStatement.setString(1, "user2");
        fauxInsertStatement.execute();
        HashMap<String, ByteIterator> updateMap = new HashMap<String, ByteIterator>();
        for (int i = 0; i < 3; i++) {
            updateMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue("user1", FIELD_PREFIX + i)));
        }
        jdbcDBClient.update(TABLE_NAME, "user1", updateMap);
        ResultSet resultSet = jdbcConnection.prepareStatement(String.format("SELECT * FROM %s ORDER BY %s", TABLE_NAME, KEY_FIELD)).executeQuery();
        // Ensure that user0 record was not changed
        resultSet.next();
        assertEquals("Assert first row key is user0", resultSet.getString(KEY_FIELD), "user0");
        for (int i = 0; i < 3; i++) {
            assertEquals("Assert first row fields contain preupdateString", resultSet.getString(FIELD_PREFIX + i), preupdateString);
        }
        // Check that all the columns have expected values for user1 record
        resultSet.next();
        assertEquals(resultSet.getString(KEY_FIELD), "user1");
        for (int i = 0; i < 3; i++) {
            assertEquals(resultSet.getString(FIELD_PREFIX + i), updateMap.get(FIELD_PREFIX + i).toString());
        }
        // Ensure that user2 record was not changed
        resultSet.next();
        assertEquals("Assert third row key is user2", resultSet.getString(KEY_FIELD), "user2");
        for (int i = 0; i < 3; i++) {
            assertEquals("Assert third row fields contain preupdateString", resultSet.getString(FIELD_PREFIX + i), preupdateString);
        }
        resultSet.close();
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Failed updateTest");
    }
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) ByteIterator(site.ycsb.ByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator)

Example 49 with StringByteIterator

use of site.ycsb.StringByteIterator in project gora by apache.

the class GoraClientTest method setUp.

/**
 * Sets the up. testUpdate Setup is executed before each test using
 * the @Before annotation of JUnit 4. Use @BeforeClass if you want to execute
 * a code block just once.
 *
 * @throws Exception
 *           the exception files are auto-generated. I have the code to add
 *           the license file accordingly
 */
@Before
public void setUp() throws Exception {
    DATA_TO_INSERT = new HashMap<>();
    DATA_TO_UPDATE = new HashMap<>();
    INTEGER_DATA = new HashMap<>();
    for (int count = 0; count < Constants.TEST_NUMBER_OF_FIELDS; count++) {
        DATA_TO_INSERT.put(Constants.FIELD_PREFIX + count, new StringByteIterator(Constants.TEST_VALUE + count));
        DATA_TO_UPDATE.put(Constants.FIELD_PREFIX + count, new StringByteIterator(Constants.TEST_UPDATED + count));
        INTEGER_DATA.put(Constants.FIELD_PREFIX + count, new StringByteIterator(count + ""));
    }
    Properties properties = new Properties();
    properties.setProperty(Constants.KEY_CLASS_KEY, Constants.KEY_CLASS_VALUE);
    properties.setProperty(Constants.PERSISTENCE_CLASS_KEY, Constants.PERSISTENCE_CLASS_VALUE);
    properties.setProperty(CoreWorkload.FIELD_COUNT_PROPERTY, Constants.TEST_NUMBER_OF_FIELDS + "");
    // Setup and start embedded MongoDB, make sure local mongodb is not running.
    Properties dataStoreProperties = DataStoreFactory.createProps();
    String dataStoreToTest = GoraBenchmarkUtils.getDataBase(dataStoreProperties);
    if (Constants.MONGODB.equals(dataStoreToTest)) {
        setupMongoDBCluster();
        properties.setProperty("gora.mongodb.servers", mongo.getContainerIpAddress() + ":" + mongo.getFirstMappedPort());
    }
    benchmarkClient = new GoraBenchmarkClient();
    benchmarkClient.setProperties(properties);
    benchmarkClient.init();
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) Before(org.junit.Before)

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