use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class RestWorkload method doTransactionInsert.
@Override
public void doTransactionInsert(DB db) {
HashMap<String, ByteIterator> value = new HashMap<String, ByteIterator>();
// Create random bytes of insert data with a specific size.
value.put("data", new RandomByteIterator(fieldlengthgenerator.nextValue().longValue()));
db.insert(null, getNextURL(2), value);
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class CrailClient method insert.
@Override
public Status insert(String table, String key, Map<String, ByteIterator> values) {
try {
String path = table + "/" + key;
CrailKeyValue file = client.create(path, CrailNodeType.KEYVALUE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, enumerateKeys).get().asKeyValue();
CrailBufferedOutputStream stream = file.getBufferedOutputStream(1024);
for (Entry<String, ByteIterator> entry : values.entrySet()) {
byte[] fieldKey = entry.getKey().getBytes();
int fieldKeyLength = fieldKey.length;
byte[] fieldValue = entry.getValue().toArray();
int fieldValueLength = fieldValue.length;
stream.writeInt(fieldKeyLength);
stream.write(fieldKey);
stream.writeInt(fieldValueLength);
stream.write(fieldValue);
}
file.syncDir();
stream.close();
} catch (Exception e) {
LOG.error("Error during insert, table " + table + ", key " + key + ", exception " + e.getMessage());
return Status.ERROR;
}
return Status.OK;
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class ElasticsearchClientTest method testUpdate.
/**
* Test of update method, of class ElasticsearchClient.
*/
@Test
public void testUpdate() {
int i;
HashMap<String, ByteIterator> newValues = new HashMap<>(10);
for (i = 1; i <= 10; i++) {
newValues.put(FIELD_PREFIX + 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<>(10);
instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);
for (i = 1; i <= 10; i++) {
assertEquals("newvalue" + i, resultParam.get(FIELD_PREFIX + i).toString());
}
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class HBaseClient2 method update.
/**
* Update a record in the database. Any field/value pairs in the specified
* values HashMap will be written into the record with the specified record
* key, overwriting any existing values with the same field name.
*
* @param table
* The name of the table
* @param key
* The record key of the record to write
* @param values
* A HashMap of field/value pairs to update in the record
* @return Zero on success, a non-zero error code on error
*/
@Override
public Status update(String table, String key, Map<String, ByteIterator> values) {
// if this is a "new" table, init HTable object. Else, use existing one
if (!tableName.equals(table)) {
currentTable = null;
try {
getHTable(table);
tableName = table;
} catch (IOException e) {
System.err.println("Error accessing HBase table: " + e);
return Status.ERROR;
}
}
if (debug) {
System.out.println("Setting up put for key: " + key);
}
Put p = new Put(Bytes.toBytes(key));
p.setDurability(durability);
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
byte[] value = entry.getValue().toArray();
if (debug) {
System.out.println("Adding field/value " + entry.getKey() + "/" + Bytes.toStringBinary(value) + " to put request");
}
p.addColumn(columnFamilyBytes, Bytes.toBytes(entry.getKey()), value);
}
try {
if (clientSideBuffering) {
// removed Preconditions.checkNotNull, which throws NPE, in favor of NPE on next line
bufferedMutator.mutate(p);
} else {
currentTable.put(p);
}
} catch (IOException e) {
if (debug) {
System.err.println("Error doing put: " + e);
}
return Status.ERROR;
} catch (ConcurrentModificationException e) {
// do nothing for now...hope this is rare
return Status.ERROR;
}
return Status.OK;
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class IgniteClientTest method testReadNotPresent.
@Test
public void testReadNotPresent() throws Exception {
cluster.cache(DEFAULT_CACHE_NAME).clear();
final String key = "key";
final Map<String, String> input = new HashMap<>();
input.put("field0", "value1");
input.put("field1", "value2A");
input.put("field3", null);
final Status sPut = client.insert(DEFAULT_CACHE_NAME, key, StringByteIterator.getByteIteratorMap(input));
assertThat(sPut, is(Status.OK));
assertThat(cluster.cache(DEFAULT_CACHE_NAME).size(), is(1));
final Set<String> fld = new TreeSet<>();
final String newKey = "newKey";
final HashMap<String, ByteIterator> result1 = new HashMap<>();
final Status sGet = client.read(DEFAULT_CACHE_NAME, newKey, fld, result1);
assertThat(sGet, is(Status.NOT_FOUND));
}
Aggregations