use of org.bboxdb.network.client.future.TupleListFuture in project bboxdb by jnidzwetzki.
the class DistributedSelftest method queryForNonExistingTuples.
/**
* Query for non existing tuples and exit, as soon as a tuple is found
* @param bboxdbClient
* @throws BBoxDBException
* @throws InterruptedException
* @throws ExecutionException
*/
private static void queryForNonExistingTuples(final BBoxDBCluster bboxdbClient) throws BBoxDBException, InterruptedException, ExecutionException {
logger.info("Query for non existing tuples");
for (int i = 0; i < NUMBER_OF_OPERATIONS; i++) {
final String key = Integer.toString(i);
final TupleListFuture queryResult = bboxdbClient.queryKey(TABLE, key);
queryResult.waitForAll();
if (queryResult.isFailed()) {
logger.error("Query {}: Got failed future, when query for: {}", i, key);
logger.error(queryResult.getAllMessages());
System.exit(-1);
}
for (final Tuple tuple : queryResult) {
logger.error("Found a tuple which should not exist: {} / {}", i, tuple);
System.exit(-1);
}
}
}
use of org.bboxdb.network.client.future.TupleListFuture in project bboxdb by jnidzwetzki.
the class CLI method actionExecuteQuery.
/**
* Execute the given query
* @param line
*/
protected void actionExecuteQuery(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Query should be performed, but no table was specified");
printHelpAndExit();
}
try {
final TupleListFuture resultFuture = buildQueryFuture(line);
if (resultFuture == null) {
System.err.println("Unable to get query");
System.exit(-1);
}
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
System.exit(-1);
}
for (final Tuple tuple : resultFuture) {
printTuple(tuple);
}
System.out.println("Query done");
} catch (BBoxDBException e) {
System.err.println("Got an exception while performing query: " + e);
System.exit(-1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
use of org.bboxdb.network.client.future.TupleListFuture in project bboxdb by jnidzwetzki.
the class CLI method actionExecuteContinuousQuery.
/**
* Execute a continuous bounding box query
* @param line
*/
protected void actionExecuteContinuousQuery(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Query should be performed, but no table was specified");
printHelpAndExit();
}
try {
System.out.println("Executing continuous bounding box query...");
final String table = line.getOptionValue(CLIParameter.TABLE);
if (!line.hasOption(CLIParameter.BOUNDING_BOX)) {
System.err.println("Bounding box is not given");
System.exit(-1);
}
final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
final TupleListFuture resultFuture = bboxDbConnection.queryBoundingBoxContinuous(table, boundingBox);
if (resultFuture == null) {
System.err.println("Unable to get query");
System.exit(-1);
}
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
System.exit(-1);
}
for (final Tuple tuple : resultFuture) {
printTuple(tuple);
}
System.out.println("Query done");
} catch (BBoxDBException e) {
System.err.println("Got an exception while performing query: " + e);
System.exit(-1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
use of org.bboxdb.network.client.future.TupleListFuture in project bboxdb by jnidzwetzki.
the class TestTupleListFuture method testRejectedExeption.
@Test(expected = RejectedException.class)
public void testRejectedExeption() throws InterruptedException, RejectedException {
final TupleListFutureStore tupleListFutureStore = new TupleListFutureStore();
tupleListFutureStore.shutdown();
final BBoxDBConnection connection = Mockito.mock(BBoxDBConnection.class);
final Supplier<NetworkRequestPackage> supplier = () -> (null);
final NetworkOperationFuture networkOperationFuture = new NetworkOperationFuture(connection, supplier);
tupleListFutureStore.put(new TupleListFuture(networkOperationFuture, new DoNothingDuplicateResolver(), ""));
}
use of org.bboxdb.network.client.future.TupleListFuture in project bboxdb by jnidzwetzki.
the class TestBoundingBoxQuery method executeQueries.
/**
* Execute the bounding box queries
* @param maxDimensionSize
* @param boundingBox
* @param bboxDBConnection
* @throws BBoxDBException
* @throws InterruptedException
* @throws RejectedException
*/
protected void executeQueries(final double maxDimensionSize, final BoundingBox boundingBox, final BBoxDB bboxDBConnection) throws BBoxDBException, InterruptedException, RejectedException {
for (int i = 0; i < QUERIES; i++) {
final List<DoubleInterval> bboxIntervals = new ArrayList<>();
// Determine query bounding box
for (int dimension = 0; dimension < boundingBox.getDimension(); dimension++) {
final double dataExtent = boundingBox.getExtent(dimension);
final double bboxOffset = (random.nextDouble() % 1) * dataExtent;
final double coordinateLow = boundingBox.getCoordinateLow(dimension);
final double coordinateHigh = boundingBox.getCoordinateHigh(dimension);
final double bboxStartPos = coordinateLow + bboxOffset;
final double bboxEndPos = Math.min(bboxStartPos + dataExtent * maxDimensionSize, coordinateHigh);
final DoubleInterval doubleInterval = new DoubleInterval(bboxStartPos, bboxEndPos);
bboxIntervals.add(doubleInterval);
}
final BoundingBox queryBox = new BoundingBox(bboxIntervals);
final TupleListFuture future = bboxDBConnection.queryBoundingBox(tablename, queryBox);
pendingFutures.put(future);
}
pendingFutures.waitForCompletion();
}
Aggregations