Search in sources :

Example 51 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testPaging.

/**
 * Insert some tuples and request it via paging
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testPaging() throws InterruptedException, ExecutionException, BBoxDBException {
    System.out.println("=== Running testPaging");
    final String table = DISTRIBUTION_GROUP + "_relation9999";
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    // Inside our bbox query
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(0d, 1d, 0d, 1d), "abc".getBytes());
    final EmptyResultFuture result1 = bboxDBClient.insertTuple(table, tuple1);
    final Tuple tuple2 = new Tuple("def", new BoundingBox(0d, 0.5d, 0d, 0.5d), "def".getBytes());
    final EmptyResultFuture result2 = bboxDBClient.insertTuple(table, tuple2);
    final Tuple tuple3 = new Tuple("geh", new BoundingBox(0.5d, 1.5d, 0.5d, 1.5d), "geh".getBytes());
    final EmptyResultFuture result3 = bboxDBClient.insertTuple(table, tuple3);
    final Tuple tuple4 = new Tuple("ijk", new BoundingBox(-10d, -9d, -10d, -9d), "ijk".getBytes());
    final EmptyResultFuture result4 = bboxDBClient.insertTuple(table, tuple4);
    final Tuple tuple5 = new Tuple("lmn", new BoundingBox(1d, 2d, 1d, 2d), "lmn".getBytes());
    final EmptyResultFuture result5 = bboxDBClient.insertTuple(table, tuple5);
    result1.waitForAll();
    result2.waitForAll();
    result3.waitForAll();
    result4.waitForAll();
    result5.waitForAll();
    // Without paging
    System.out.println("Pages = unlimited");
    bboxDBClient.setPagingEnabled(false);
    bboxDBClient.setTuplesPerPage((short) 0);
    final TupleListFuture future = bboxDBClient.queryBoundingBox(table, new BoundingBox(-10d, 10d, -10d, 10d));
    future.waitForAll();
    final List<Tuple> resultList = Lists.newArrayList(future.iterator());
    Assert.assertEquals(5, resultList.size());
    // With paging (tuples per page 10)
    System.out.println("Pages = 10");
    bboxDBClient.setPagingEnabled(true);
    bboxDBClient.setTuplesPerPage((short) 10);
    final TupleListFuture future2 = bboxDBClient.queryBoundingBox(table, new BoundingBox(-10d, 10d, -10d, 10d));
    future2.waitForAll();
    final List<Tuple> resultList2 = Lists.newArrayList(future2.iterator());
    Assert.assertEquals(5, resultList2.size());
    // With paging (tuples per page 5)
    System.out.println("Pages = 5");
    bboxDBClient.setPagingEnabled(true);
    bboxDBClient.setTuplesPerPage((short) 5);
    final TupleListFuture future3 = bboxDBClient.queryBoundingBox(table, new BoundingBox(-10d, 10d, -10d, 10d));
    future3.waitForAll();
    final List<Tuple> resultList3 = Lists.newArrayList(future3.iterator());
    Assert.assertEquals(5, resultList3.size());
    // With paging (tuples per page 2)
    System.out.println("Pages = 2");
    bboxDBClient.setPagingEnabled(true);
    bboxDBClient.setTuplesPerPage((short) 2);
    final TupleListFuture future4 = bboxDBClient.queryBoundingBox(table, new BoundingBox(-10d, 10d, -10d, 10d));
    System.out.println("Client is waiting on: " + future4);
    future4.waitForAll();
    final List<Tuple> resultList4 = Lists.newArrayList(future4.iterator());
    Assert.assertEquals(5, resultList4.size());
    // With paging (tuples per page 1)
    System.out.println("Pages = 1");
    bboxDBClient.setPagingEnabled(true);
    bboxDBClient.setTuplesPerPage((short) 1);
    final TupleListFuture future5 = bboxDBClient.queryBoundingBox(table, new BoundingBox(-10d, 10d, -10d, 10d));
    future5.waitForAll();
    final List<Tuple> resultList5 = Lists.newArrayList(future5.iterator());
    Assert.assertEquals(5, resultList5.size());
    System.out.println("=== End testPaging");
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Example 52 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestMemtable method testIterate1.

/**
 * Test iterator 1
 * @throws Exception
 */
@Test(timeout = 60000)
public void testIterate1() throws Exception {
    Assert.assertEquals(0, memtable.getSortedTupleList().size());
    int tuples = 0;
    for (@SuppressWarnings("unused") final Tuple tuple : memtable) {
        tuples++;
    }
    Assert.assertEquals(0, tuples);
}
Also used : Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 53 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestMemtable method testAquire2.

/**
 * Test the aquire
 * @throws StorageManagerException
 */
@Test(timeout = 60000)
public void testAquire2() throws StorageManagerException {
    final Memtable memtable = new Memtable(MEMTABLE_TABLE_NAME, MEMTABLE_MAX_ENTRIES, MEMTABLE_MAX_SIZE);
    memtable.init();
    Assert.assertTrue(memtable.acquire());
    final Tuple createdTuple1 = new Tuple("1", null, "abc".getBytes(), 60);
    memtable.put(createdTuple1);
    memtable.release();
    Assert.assertEquals(3, memtable.getSize());
    memtable.deleteOnClose();
    Assert.assertEquals(0, memtable.getSize());
}
Also used : Memtable(org.bboxdb.storage.memtable.Memtable) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 54 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestMemtable method testBigInsert.

/**
 * Test memtable overflow
 * @throws Exception
 */
@Test(expected = StorageManagerException.class)
public void testBigInsert() throws Exception {
    final int MAX_TUPLES = memtable.getMaxEntries() * 10;
    for (int i = 0; i < MAX_TUPLES; i++) {
        final Tuple createdTuple = new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, Integer.toString(i).getBytes());
        memtable.put(createdTuple);
    }
}
Also used : Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 55 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestMemtable method testIterate4.

/**
 * Test iterator 4
 * @throws Exception
 */
@Test(expected = IllegalStateException.class)
public void testIterate4() throws Exception {
    final Tuple createdTuple1 = new Tuple("1", null, "abc".getBytes());
    memtable.put(createdTuple1);
    final Tuple createdTuple2 = new Tuple("2", null, "abc".getBytes());
    memtable.put(createdTuple2);
    final Tuple createdTuple3 = new Tuple("3", null, "abc".getBytes());
    memtable.put(createdTuple3);
    final Iterator<Tuple> iter = memtable.iterator();
    iter.remove();
}
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