Search in sources :

Example 26 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testGetByKey.

/**
 * Insert a tuple and request it via key
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testGetByKey() throws InterruptedException, ExecutionException, BBoxDBException {
    System.out.println("=== Running testGetByKey");
    final String table = DISTRIBUTION_GROUP + "_relation12333";
    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);
    result1.waitForAll();
    final TupleListFuture future = bboxDBClient.queryKey(table, "abc");
    future.waitForAll();
    final List<Tuple> resultList = Lists.newArrayList(future.iterator());
    Assert.assertEquals(1, resultList.size());
    System.out.println("=== End testGetByKey");
    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 27 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testQueriesWithoutTables.

/**
 * Start a bounding box query without inserted tuples
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testQueriesWithoutTables() throws InterruptedException, ExecutionException, BBoxDBException {
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    final String table = DISTRIBUTION_GROUP + "_nonexisting";
    System.out.println("== Waiting for queryBoundingBox");
    final BoundingBox boundingBox = new BoundingBox(-1d, 2d, -1d, 2d);
    final TupleListFuture result1 = bboxDBClient.queryBoundingBox(table, boundingBox);
    result1.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
    result1.waitForAll();
    Assert.assertTrue(result1.isFailed());
    Assert.assertEquals(ErrorMessages.ERROR_TABLE_NOT_EXIST, result1.getMessage(0));
    System.out.println("== Waiting for queryKey");
    final TupleListFuture result2 = bboxDBClient.queryKey(table, "abc");
    result2.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
    result2.waitForAll();
    Assert.assertTrue(result2.isFailed());
    Assert.assertEquals(ErrorMessages.ERROR_TABLE_NOT_EXIST, result2.getMessage(0));
    System.out.println("== Waiting for queryInsertedTime");
    final TupleListFuture result3 = bboxDBClient.queryInsertedTime(table, 1234);
    result3.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
    result3.waitForAll();
    Assert.assertTrue(result3.isFailed());
    Assert.assertEquals(ErrorMessages.ERROR_TABLE_NOT_EXIST, result3.getMessage(0));
    System.out.println("== Waiting for queryVersionTime");
    final TupleListFuture result4 = bboxDBClient.queryVersionTime(table, 1234);
    result4.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
    result4.waitForAll();
    Assert.assertTrue(result4.isFailed());
    Assert.assertEquals(ErrorMessages.ERROR_TABLE_NOT_EXIST, result4.getMessage(0));
    System.out.println("== Waiting for queryBoundingBoxAndTime");
    final TupleListFuture result5 = bboxDBClient.queryBoundingBoxAndTime(table, boundingBox, 1234);
    result5.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
    result5.waitForAll();
    Assert.assertTrue(result5.isFailed());
    Assert.assertEquals(ErrorMessages.ERROR_TABLE_NOT_EXIST, result5.getMessage(0));
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Test(org.junit.Test)

Example 28 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox 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 29 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestStaticgridSpacePartitioner method testRootElement.

@Test(timeout = 60000)
public void testRootElement() throws ZookeeperException, ZookeeperNotFoundException, BBoxDBException {
    final StaticgridSpacePartitioner spacePartitioner = getSpacePartitioner();
    final DistributionRegion rootElement = spacePartitioner.getRootNode();
    Assert.assertEquals(rootElement.getState(), DistributionRegionState.SPLIT);
    final BoundingBox box = rootElement.getConveringBox();
    Assert.assertEquals(new BoundingBox(0.0, 5.0, 0.0, 6.0), box);
}
Also used : StaticgridSpacePartitioner(org.bboxdb.distribution.partitioner.StaticgridSpacePartitioner) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) Test(org.junit.Test)

Example 30 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class NetworkQueryHelper method executeJoinQuery.

/**
 * Execute a join
 * @param bboxDBConnection
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void executeJoinQuery(final BBoxDB bboxDBClient, final String distributionGroup) throws InterruptedException, BBoxDBException {
    System.out.println("=== Execute join");
    final String table1 = distributionGroup + "_table1";
    final String table2 = distributionGroup + "_table2";
    // Create table1
    System.out.println("Create table 1");
    final EmptyResultFuture resultCreateTable1 = bboxDBClient.createTable(table1, new TupleStoreConfiguration());
    resultCreateTable1.waitForAll();
    Assert.assertFalse(resultCreateTable1.isFailed());
    System.out.println("Create table 2");
    final EmptyResultFuture resultCreateTable2 = bboxDBClient.createTable(table2, new TupleStoreConfiguration());
    resultCreateTable2.waitForAll();
    Assert.assertFalse(resultCreateTable2.isFailed());
    // Insert tuples
    System.out.println("Insert tuple 1");
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(1.0, 2.0, 1.0, 2.0), "abc".getBytes());
    final EmptyResultFuture insertResult1 = bboxDBClient.insertTuple(table1, tuple1);
    insertResult1.waitForAll();
    Assert.assertFalse(insertResult1.isFailed());
    Assert.assertTrue(insertResult1.isDone());
    System.out.println("Insert tuple 2");
    final Tuple tuple2 = new Tuple("def", new BoundingBox(1.5, 2.5, 1.5, 2.5), "abc".getBytes());
    final EmptyResultFuture insertResult2 = bboxDBClient.insertTuple(table1, tuple2);
    insertResult2.waitForAll();
    Assert.assertFalse(insertResult2.isFailed());
    Assert.assertTrue(insertResult2.isDone());
    System.out.println("Insert tuple 3");
    final Tuple tuple3 = new Tuple("123", new BoundingBox(0.0, 5.0, 0.0, 5.0), "abc".getBytes());
    final EmptyResultFuture insertResult3 = bboxDBClient.insertTuple(table2, tuple3);
    insertResult3.waitForAll();
    Assert.assertFalse(insertResult3.isFailed());
    Assert.assertTrue(insertResult3.isDone());
    // Execute the join
    final JoinedTupleListFuture joinResult = bboxDBClient.queryJoin(Arrays.asList(table1, table2), new BoundingBox(0.0, 10.0, 0.0, 10.0));
    joinResult.waitForAll();
    final List<JoinedTuple> resultList = Lists.newArrayList(joinResult.iterator());
    System.out.println(resultList);
    Assert.assertEquals(2, resultList.size());
    Assert.assertEquals(2, resultList.get(0).getNumberOfTuples());
    Assert.assertEquals(table1, resultList.get(0).getTupleStoreName(0));
    Assert.assertEquals(table2, resultList.get(0).getTupleStoreName(1));
    Assert.assertEquals(new BoundingBox(1.0, 2.0, 1.0, 2.0), resultList.get(0).getBoundingBox());
    Assert.assertEquals(2, resultList.get(1).getNumberOfTuples());
    Assert.assertEquals(table1, resultList.get(1).getTupleStoreName(0));
    Assert.assertEquals(table2, resultList.get(1).getTupleStoreName(1));
    Assert.assertEquals(new BoundingBox(1.5, 2.5, 1.5, 2.5), resultList.get(1).getBoundingBox());
    System.out.println("=== End Execute join");
}
Also used : JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Aggregations

BoundingBox (org.bboxdb.commons.math.BoundingBox)194 Test (org.junit.Test)113 Tuple (org.bboxdb.storage.entity.Tuple)61 ArrayList (java.util.ArrayList)25 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)24 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)23 BBoxDBException (org.bboxdb.misc.BBoxDBException)22 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)20 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)16 List (java.util.List)15 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)13 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)13 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)13 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)11 IOException (java.io.IOException)10 Date (java.util.Date)10 DoubleInterval (org.bboxdb.commons.math.DoubleInterval)10 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)10