use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testSingleTupleResponse.
/**
* Try to encode and decode the single tuple response
* @throws PackageEncodeException
* @throws IOException
*/
@Test(timeout = 60000)
public void testSingleTupleResponse() throws PackageEncodeException, IOException {
final String tablename = "table1";
final Tuple tuple = new Tuple("abc", BoundingBox.FULL_SPACE, "databytes".getBytes());
final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
final byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
Assert.assertFalse(singleTupleResponse.getTuple() instanceof DeletedTuple);
Assert.assertTrue(singleTupleResponse.toString().length() > 10);
}
use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testSingleTupleDeletedResponse.
/**
* Try to encode and decode the single tuple response - with deleted tuple
* @throws PackageEncodeException
* @throws IOException
*/
@Test(timeout = 60000)
public void testSingleTupleDeletedResponse() throws PackageEncodeException, IOException {
final String tablename = "table1";
final Tuple tuple = new DeletedTuple("abc", 12);
final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
final byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
Assert.assertTrue(singleTupleResponse.getTuple() instanceof DeletedTuple);
Assert.assertEquals(singleTupleResponse.toString(), responseDecoded.toString());
}
use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.
the class TestTupleHelper method encodeAndDecodeTuple2.
/**
* Encode and decode a tuple
* @throws IOException
*/
@Test(timeout = 60000)
public void encodeAndDecodeTuple2() throws IOException {
final Tuple tuple = new DeletedTuple("abc");
// Read from stream
final byte[] bytes = TupleHelper.tupleToBytes(tuple);
final ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
final Tuple readTuple = TupleHelper.decodeTuple(inputStream);
Assert.assertEquals(tuple, readTuple);
// Read from byte buffer
final ByteBuffer bb = ByteBuffer.wrap(bytes);
final Tuple readTuple2 = TupleHelper.decodeTuple(bb);
Assert.assertEquals(tuple, readTuple2);
}
use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method deleteTuple.
@Override
public EmptyResultFuture deleteTuple(final String table, final String key, final long timestamp) throws BBoxDBException {
final DeletedTuple tuple = new DeletedTuple(key);
final DistributionRegion distributionRegion = getRootNode(table);
final Supplier<List<NetworkOperationFuture>> supplier = () -> {
final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
final List<NetworkOperationFuture> futures = new ArrayList<>();
for (final RoutingHop hop : hops) {
final BBoxDBInstance instance = hop.getDistributedInstance();
final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
final NetworkOperationFuture future = connection.getBboxDBClient().getInsertTupleFuture(table, tuple, routingHeader);
futures.add(future);
}
return futures;
};
return new EmptyResultFuture(supplier);
}
use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method queryKey.
@Override
public TupleListFuture queryKey(final String table, final String key) throws BBoxDBException {
if (logger.isDebugEnabled()) {
logger.debug("Query by for key {} in table {}", key, table);
}
final DeletedTuple tuple = new DeletedTuple(key);
final DistributionRegion distributionRegion = getRootNode(table);
final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, tuple.getBoundingBox());
final List<NetworkOperationFuture> futures = new ArrayList<>();
for (final RoutingHop hop : hops) {
final BBoxDBInstance instance = hop.getDistributedInstance();
final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
final NetworkOperationFuture future = connection.getBboxDBClient().getQueryKeyFuture(table, key, routingHeader);
futures.add(future);
}
return futures;
};
final DuplicateResolver<Tuple> duplicateResolver = TupleStoreConfigurationCache.getInstance().getDuplicateResolverForTupleStore(table);
return new TupleListFuture(futureProvider, duplicateResolver, table);
}
Aggregations