Search in sources :

Example 16 with TupleStoreName

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);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 17 with TupleStoreName

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());
}
Also used : ArrayList(java.util.ArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ListTablesResponse(org.bboxdb.network.packages.response.ListTablesResponse) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 18 with TupleStoreName

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);
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 19 with TupleStoreName

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();
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 20 with TupleStoreName

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();
        }
    }
}
Also used : Arrays(java.util.Arrays) Multiset(com.google.common.collect.Multiset) BBoxDBConfiguration(org.bboxdb.misc.BBoxDBConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SSTableHelper(org.bboxdb.storage.sstable.SSTableHelper) BBoxDBService(org.bboxdb.misc.BBoxDBService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HashMultiset(com.google.common.collect.HashMultiset) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) BBoxDBConfigurationManager(org.bboxdb.misc.BBoxDBConfigurationManager) StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ServiceState(org.bboxdb.commons.ServiceState) List(java.util.List) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreLocator(org.bboxdb.storage.tuplestore.TupleStoreLocator) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) File(java.io.File)

Aggregations

TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)77 Test (org.junit.Test)25 Tuple (org.bboxdb.storage.entity.Tuple)18 StorageManagerException (org.bboxdb.storage.StorageManagerException)15 ArrayList (java.util.ArrayList)14 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ByteBuffer (java.nio.ByteBuffer)12 BoundingBox (org.bboxdb.commons.math.BoundingBox)12 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)12 BBoxDBException (org.bboxdb.misc.BBoxDBException)12 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)12 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)12 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)11 List (java.util.List)10 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)10 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)10 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9