use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RedisClient method read.
// XXX jedis.select(int index) to switch to `table`
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
if (fields == null) {
StringByteIterator.putAllAsByteIterators(result, jedis.hgetAll(key));
} else {
String[] fieldArray = (String[]) fields.toArray(new String[fields.size()]);
List<String> values = jedis.hmget(key, fieldArray);
Iterator<String> fieldIterator = fields.iterator();
Iterator<String> valueIterator = values.iterator();
while (fieldIterator.hasNext() && valueIterator.hasNext()) {
result.put(fieldIterator.next(), new StringByteIterator(valueIterator.next()));
}
assert !fieldIterator.hasNext() && !valueIterator.hasNext();
}
return result.isEmpty() ? Status.ERROR : Status.OK;
}
use of site.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, Map<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 site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RestClientTest method update_200.
@Test
public void update_200() {
HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
Status status = rc.update(null, VALID_RESOURCE, data);
assertEquals(Status.OK, status);
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RestClientTest method update_404.
@Test
public void update_404() {
HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
Status status = rc.update(null, ABSENT_RESOURCE, data);
assertEquals(Status.NOT_FOUND, status);
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RestClientTest method insert_500.
@Test
public void insert_500() {
HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
Status status = rc.insert(null, INVALID_RESOURCE, data);
assertEquals(Status.ERROR, status);
}
Aggregations