use of alluxio.client.keyvalue.KeyValuePair in project alluxio by Alluxio.
the class KeyValueStoreOperations method getKeyValuePairs.
private boolean getKeyValuePairs(KeyValueStoreReader reader) throws Exception {
LOG.info("Getting key-value pairs...");
// API: KeyValueStoreReader#size
if (reader.size() != mNumKeyValuePairs) {
LOG.error("The key-value store has the wrong numbers of key-value pairs");
return false;
}
// API: KeyValueStoreReader#get
for (Map.Entry<ByteBuffer, ByteBuffer> pair : mKeyValuePairs.entrySet()) {
ByteBuffer expectedValue = pair.getValue();
ByteBuffer gotValue = reader.get(pair.getKey());
if (!expectedValue.equals(gotValue)) {
LOG.error("The value returned from the key-value store iterator is unexpected");
return false;
}
}
// API: KeyValueStoreReader#iterator
KeyValueIterator iterator = reader.iterator();
while (iterator.hasNext()) {
KeyValuePair kv = iterator.next();
ByteBuffer expectedValue = mKeyValuePairs.get(kv.getKey());
ByteBuffer gotValue = kv.getValue();
if (!expectedValue.equals(gotValue)) {
LOG.error("The value returned from the key-value store iterator is not expected");
return false;
}
}
return true;
}
use of alluxio.client.keyvalue.KeyValuePair in project alluxio by Alluxio.
the class KeyValueRecordReader method nextKeyValue.
@Override
public synchronized boolean nextKeyValue() throws IOException {
if (!mKeyValuePairIterator.hasNext()) {
return false;
}
KeyValuePair pair;
try {
pair = mKeyValuePairIterator.next();
} catch (AlluxioException e) {
throw new IOException(e);
}
// TODO(cc): Implement a ByteBufferInputStream which is backed by a ByteBuffer so we could
// benefit from zero-copy.
mCurrentKey.set(new BytesWritable(BufferUtils.newByteArrayFromByteBuffer(pair.getKey())));
mCurrentValue.set(new BytesWritable(BufferUtils.newByteArrayFromByteBuffer(pair.getValue())));
mNumVisitedKeyValuePairs++;
return true;
}
use of alluxio.client.keyvalue.KeyValuePair in project alluxio by Alluxio.
the class SameKeyValueStoresTest method areTheSameStores.
private boolean areTheSameStores(KeyValueStoreReader reader1, KeyValueStoreReader reader2) throws Exception {
// The two stores are the same if the number of key-value pairs are the same, and the stores
// have the same value for all the keys in store1.
int size1 = reader1.size();
int size2 = reader2.size();
if (size1 != size2) {
LOG.error("store {} has {} pairs while another has {} pairs", mStoreUri1, size1, size2);
return false;
}
KeyValueIterator iterator = reader1.iterator();
while (iterator.hasNext()) {
KeyValuePair pair1 = iterator.next();
byte[] key1 = BufferUtils.newByteArrayFromByteBuffer(pair1.getKey());
byte[] value1 = BufferUtils.newByteArrayFromByteBuffer(pair1.getValue());
byte[] value2 = reader2.get(key1);
if (value2 == null) {
LOG.error("store {} has value for key {} while another has no value for the same key", mStoreUri1, FormatUtils.byteArrayToHexString(key1));
return false;
}
if (!ByteBuffer.wrap(value1).equals(ByteBuffer.wrap(value2))) {
LOG.error("value for key {} are different in the two stores", FormatUtils.byteArrayToHexString(key1));
return false;
}
}
return true;
}
Aggregations