Search in sources :

Example 6 with Tuple

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);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ArrayList(java.util.ArrayList) Tuple(org.bboxdb.storage.entity.Tuple)

Example 7 with Tuple

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());
}
Also used : Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 8 with Tuple

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);
}
Also used : Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 9 with Tuple

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));
}
Also used : Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 10 with Tuple

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);
}
Also used : Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Aggregations

Tuple (org.bboxdb.storage.entity.Tuple)198 Test (org.junit.Test)123 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)104 BoundingBox (org.bboxdb.commons.math.BoundingBox)62 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)58 ArrayList (java.util.ArrayList)41 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)25 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)24 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)18 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)18 ByteBuffer (java.nio.ByteBuffer)17 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)15 SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)13 IOException (java.io.IOException)11 List (java.util.List)11 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)11 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)11 StorageManagerException (org.bboxdb.storage.StorageManagerException)11 TupleBuilder (org.bboxdb.tools.converter.tuple.TupleBuilder)11