use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class KeepAliveRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static KeepAliveRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_KEEP_ALIVE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final List<Tuple> tuples = new ArrayList<>();
final short tableLength = encodedPackage.getShort();
// Unused
encodedPackage.get();
// Unused
encodedPackage.get();
final int elements = encodedPackage.getInt();
final byte[] tableNameBytes = new byte[tableLength];
encodedPackage.get(tableNameBytes, 0, tableNameBytes.length);
final String tableName = new String(tableNameBytes);
for (int i = 0; i < elements; i++) {
final int keyLength = encodedPackage.getInt();
final byte[] keyBytes = new byte[keyLength];
encodedPackage.get(keyBytes, 0, keyBytes.length);
final String key = new String(keyBytes);
final int boundingBoxLength = encodedPackage.getInt();
final byte[] boundingBoxBytes = new byte[boundingBoxLength];
encodedPackage.get(boundingBoxBytes, 0, boundingBoxBytes.length);
final BoundingBox boundingBox = BoundingBox.fromByteArray(boundingBoxBytes);
final long version = encodedPackage.getLong();
final Tuple tuple = new Tuple(key, boundingBox, "".getBytes(), version);
tuples.add(tuple);
}
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
return new KeepAliveRequest(sequenceNumber, tableName, tuples);
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestMemtable method isFullBySize.
/**
* Test if full
* @throws StorageManagerException
*/
@Test(timeout = 60000)
public void isFullBySize() throws StorageManagerException {
Assert.assertFalse(memtable.isFull());
final Tuple tuple = new Tuple("3", null, "def".getBytes(), 1) {
@Override
public int getSize() {
return (int) ((MEMTABLE_MAX_SIZE / 2) - 1);
}
};
memtable.put(tuple);
Assert.assertFalse(memtable.isFull());
memtable.put(tuple);
Assert.assertFalse(memtable.isFull());
memtable.put(tuple);
Assert.assertTrue(memtable.isFull());
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestMemtable method testStoreNullTuple.
/**
* Test the null tuple
* @throws Exception
*/
@Test(expected = NullPointerException.class)
public void testStoreNullTuple() throws Exception {
// This should cause an NPE
final Tuple createdTuple = new Tuple("1", null, null);
memtable.put(createdTuple);
Assert.assertTrue(false);
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestMemtable method testInsertElements.
/**
* Test insert1
* @throws Exception
*/
@Test(timeout = 60000)
public void testInsertElements() throws Exception {
final Tuple tuple = new Tuple("1", null, "abc".getBytes());
memtable.put(tuple);
Assert.assertEquals(tuple, memtable.get("1").get(0));
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestMemtable method testSortedList1.
/**
* Test key updates and sorted list query
* @throws StorageManagerException
*/
@Test(timeout = 60000)
public void testSortedList1() throws StorageManagerException {
// Insert key 1
final Tuple createdTuple1 = new Tuple("1", null, "abc".getBytes());
memtable.put(createdTuple1);
Assert.assertEquals(memtable.getSortedTupleList().size(), 1);
// Update Key 1
final Tuple createdTuple2 = new Tuple("1", null, "defh".getBytes());
memtable.put(createdTuple2);
Assert.assertEquals(memtable.getSortedTupleList().size(), 2);
}
Aggregations