use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeInsertTupleWithCustomHeader.
/**
* The the encoding and decoding of an insert tuple package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeInsertTupleWithCustomHeader() throws IOException, PackageEncodeException {
final RoutingHeader routingHeader = ROUTING_HEADER_ROUTED;
final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_ROUTED, new TupleStoreName("test"), tuple);
Assert.assertEquals(routingHeader, insertPackage.getRoutingHeader());
byte[] encodedVersion = networkPackageToByte(insertPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(bb);
Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
Assert.assertEquals(routingHeader, decodedPackage.getRoutingHeader());
Assert.assertFalse(insertPackage.getRoutingHeader().equals(new RoutingHeader(false)));
Assert.assertEquals(insertPackage, decodedPackage);
Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
Assert.assertTrue(insertPackage.toString().length() > 10);
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testListTablesResponse.
/**
* Try to encode and decode the list tables response
* @throws PackageEncodeException
* @throws IOException
*/
@Test(timeout = 60000)
public void testListTablesResponse() throws PackageEncodeException, IOException {
final List<TupleStoreName> tables = new ArrayList<TupleStoreName>();
tables.add(new TupleStoreName("3_group1_table1"));
tables.add(new TupleStoreName("3_group1_testtable"));
tables.add(new TupleStoreName("3_group1_test4711"));
tables.add(new TupleStoreName("3_group1_mytest57"));
final ListTablesResponse response = new ListTablesResponse((short) 3, tables);
final byte[] encodedPackage = networkPackageToByte(response);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
final ListTablesResponse responseDecoded = ListTablesResponse.decodePackage(bb);
final List<TupleStoreName> myTables = responseDecoded.getTables();
Assert.assertEquals(tables, myTables);
Assert.assertEquals(tables.size(), myTables.size());
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testGetRequestBodyLength.
/**
* Read the body length from a request package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testGetRequestBodyLength() throws IOException, PackageEncodeException {
final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_UNROUTED, new TupleStoreName("test"), tuple);
final byte[] encodedPackage = networkPackageToByte(insertPackage);
Assert.assertNotNull(encodedPackage);
// 18 Byte package header
final int calculatedBodyLength = encodedPackage.length - 18;
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
final long bodyLength = NetworkPackageDecoder.getBodyLengthFromRequestPackage(bb);
Assert.assertEquals(calculatedBodyLength, bodyLength);
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestZookeeperIntegration method testTableCreateDelete.
/**
* Test the table deletion and creation
* @throws ZookeeperException
* @throws BBoxDBException
* @throws InterruptedException
*/
@Test(timeout = 60000)
public void testTableCreateDelete() throws Exception {
final TupleStoreAdapter tupleStoreAdapter = zookeeperClient.getTupleStoreAdapter();
final SpacePartitioner spacePartitioner = getSpacePartitioner();
final DistributionRegion rootNode = spacePartitioner.getRootNode();
final String rootPath = distributionRegionAdapter.getZookeeperPathForDistributionRegion(rootNode);
distributionRegionAdapter.addSystemToDistributionRegion(rootPath, ZookeeperClientFactory.getLocalInstanceName());
final TupleStoreName tupleStoreName = new TupleStoreName(TEST_GROUP + "_tabletest");
final TupleStoreName tupleStoreName0 = new TupleStoreName(TEST_GROUP + "_tabletest_0");
final TupleStoreConfiguration configuration = TupleStoreConfigurationBuilder.create().build();
tupleStoreAdapter.writeTuplestoreConfiguration(tupleStoreName, configuration);
final TupleStoreManagerRegistry storageRegistry = new TupleStoreManagerRegistry();
storageRegistry.init();
storageRegistry.deleteTable(tupleStoreName0, true);
storageRegistry.createTable(tupleStoreName0, configuration);
storageRegistry.getTupleStoreManager(tupleStoreName0);
Assert.assertTrue(storageRegistry.isStorageManagerKnown(tupleStoreName0));
System.out.println("=== Executing deletion");
tupleStoreAdapter.deleteTable(tupleStoreName0);
Thread.sleep(5000);
Assert.assertFalse(storageRegistry.isStorageManagerKnown(tupleStoreName0));
storageRegistry.shutdown();
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TupleStoreManagerRegistry method deleteAllTablesInDistributionGroup.
/**
* Delete all tables that are part of the distribution group
* @param distributionGroupName
* @throws StorageManagerException
*/
public synchronized void deleteAllTablesInDistributionGroup(final String distributionGroupName) throws StorageManagerException {
// Memtables
logger.info("Shuting down active memtables for distribution group: {}", distributionGroupName);
final Predicate<TupleStoreName> deleteTablePredicate = (t) -> (t.getDistributionGroup().equals(distributionGroupName));
shutdownAndDeleteTablesForPredicate(deleteTablePredicate, true);
// Delete the group dir
for (final String directory : storages.keySet()) {
logger.info("Deleting all local stored data for distribution group {} in path {} ", distributionGroupName, directory);
executePendingDeletes(directory);
deleteMedatadaOfDistributionGroup(distributionGroupName, directory);
final String groupDirName = SSTableHelper.getDistributionGroupDir(directory, distributionGroupName);
final File groupDir = new File(groupDirName);
final String[] children = groupDir.list();
if (children != null && children.length > 0) {
final List<String> childList = Arrays.asList(children);
throw new StorageManagerException("Unable to delete non empty dir: " + groupDirName + " / " + childList);
}
if (groupDir.exists()) {
logger.debug("Deleting {}", groupDir);
groupDir.delete();
}
}
}
Aggregations