Search in sources :

Example 26 with StringByteIterator

use of com.yahoo.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(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Example 27 with StringByteIterator

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

the class RestClient method httpGet.

// Connection is automatically released back in case of an exception.
private int httpGet(String endpoint, HashMap<String, ByteIterator> result) throws IOException {
    requestTimedout.setIsSatisfied(false);
    Thread timer = new Thread(new Timer(execTimeout, requestTimedout));
    timer.start();
    int responseCode = 200;
    HttpGet request = new HttpGet(endpoint);
    for (int i = 0; i < headers.length; i = i + 2) {
        request.setHeader(headers[i], headers[i + 1]);
    }
    CloseableHttpResponse response = client.execute(request);
    responseCode = response.getStatusLine().getStatusCode();
    HttpEntity responseEntity = response.getEntity();
    // If null entity don't bother about connection release.
    if (responseEntity != null) {
        InputStream stream = responseEntity.getContent();
        /*
       * TODO: Gzip Compression must be supported in the future. Header[]
       * header = response.getAllHeaders();
       * if(response.getHeaders("Content-Encoding")[0].getValue().contains
       * ("gzip")) stream = new GZIPInputStream(stream);
       */
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        StringBuffer responseContent = new StringBuffer();
        String line = "";
        while ((line = reader.readLine()) != null) {
            if (requestTimedout.isSatisfied()) {
                // Must avoid memory leak.
                reader.close();
                stream.close();
                EntityUtils.consumeQuietly(responseEntity);
                response.close();
                client.close();
                throw new TimeoutException();
            }
            responseContent.append(line);
        }
        timer.interrupt();
        result.put("response", new StringByteIterator(responseContent.toString()));
        // Closing the input stream will trigger connection release.
        stream.close();
    }
    EntityUtils.consumeQuietly(responseEntity);
    response.close();
    client.close();
    return responseCode;
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BufferedReader(java.io.BufferedReader) StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Example 28 with StringByteIterator

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

the class OrientDBClientTest method insertRow.

/*
      Inserts a row of deterministic values for the given insertKey using the orientDBClient.
   */
private Map<String, ByteIterator> insertRow(String insertKey) {
    HashMap<String, ByteIterator> insertMap = new HashMap<>();
    for (int i = 0; i < 3; i++) {
        insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
    }
    orientDBClient.insert(CLASS, insertKey, insertMap);
    return insertMap;
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Example 29 with StringByteIterator

use of com.yahoo.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(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 30 with StringByteIterator

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

the class RestClientTest method insert_200.

// Insert success.
@Test
public void insert_200() {
    HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
    data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
    Status status = rc.insert(null, VALID_RESOURCE, data);
    assertEquals(Status.OK, status);
}
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)

Aggregations

StringByteIterator (com.yahoo.ycsb.StringByteIterator)33 ByteIterator (com.yahoo.ycsb.ByteIterator)21 HashMap (java.util.HashMap)17 Status (com.yahoo.ycsb.Status)13 Test (org.junit.Test)9 DBException (com.yahoo.ycsb.DBException)5 IOException (java.io.IOException)5 SolrQuery (org.apache.solr.client.solrj.SolrQuery)4 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)4 SolrDocumentList (org.apache.solr.common.SolrDocumentList)4 Map (java.util.Map)3 JsonObject (com.couchbase.client.java.document.json.JsonObject)2 SolrDocument (org.apache.solr.common.SolrDocument)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 JsonNode (com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode)1 TemporaryFailureException (com.couchbase.client.java.error.TemporaryFailureException)1