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");
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations