Search in sources :

Example 6 with LongSet

use of com.carrotsearch.hppc.LongSet in project titan by thinkaurelius.

the class IDAuthorityTest method testSimpleIDAcquisition.

@Test
public void testSimpleIDAcquisition() throws BackendException {
    final IDBlockSizer blockSizer = new InnerIDBlockSizer();
    idAuthorities[0].setIDBlockSizer(blockSizer);
    int numTrials = 100;
    LongSet ids = new LongHashSet((int) blockSize * numTrials);
    long previous = 0;
    for (int i = 0; i < numTrials; i++) {
        IDBlock block = idAuthorities[0].getIDBlock(0, 0, GET_ID_BLOCK_TIMEOUT);
        checkBlock(block, ids);
        if (hasEmptyUid) {
            if (previous != 0)
                assertEquals(previous + 1, block.getId(0));
            previous = block.getId(block.numIds() - 1);
        }
    }
}
Also used : LongHashSet(com.carrotsearch.hppc.LongHashSet) IDBlockSizer(com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer) LongSet(com.carrotsearch.hppc.LongSet) Test(org.junit.Test)

Example 7 with LongSet

use of com.carrotsearch.hppc.LongSet in project titan by thinkaurelius.

the class IDAuthorityTest method checkBlock.

private void checkBlock(IDBlock block) {
    assertTrue(blockSize < 10000);
    LongSet ids = new LongHashSet((int) blockSize);
    checkBlock(block, ids);
}
Also used : LongHashSet(com.carrotsearch.hppc.LongHashSet) LongSet(com.carrotsearch.hppc.LongSet)

Example 8 with LongSet

use of com.carrotsearch.hppc.LongSet in project titan by thinkaurelius.

the class IDAuthorityTest method testManyThreadsOneIDAuthority.

@Test
public void testManyThreadsOneIDAuthority() throws BackendException, InterruptedException, ExecutionException {
    ExecutorService es = Executors.newFixedThreadPool(CONCURRENCY);
    final IDAuthority targetAuthority = idAuthorities[0];
    targetAuthority.setIDBlockSizer(new InnerIDBlockSizer());
    final int targetPartition = 0;
    final int targetNamespace = 2;
    final ConcurrentLinkedQueue<IDBlock> blocks = new ConcurrentLinkedQueue<IDBlock>();
    final int blocksPerThread = 40;
    Assert.assertTrue(0 < blocksPerThread);
    List<Future<Void>> futures = new ArrayList<Future<Void>>(CONCURRENCY);
    // Start some concurrent threads getting blocks the same ID authority and same partition in that authority
    for (int c = 0; c < CONCURRENCY; c++) {
        futures.add(es.submit(new Callable<Void>() {

            @Override
            public Void call() {
                try {
                    getBlock();
                } catch (BackendException e) {
                    throw new RuntimeException(e);
                }
                return null;
            }

            private void getBlock() throws BackendException {
                for (int i = 0; i < blocksPerThread; i++) {
                    IDBlock block = targetAuthority.getIDBlock(targetPartition, targetNamespace, GET_ID_BLOCK_TIMEOUT);
                    Assert.assertNotNull(block);
                    blocks.add(block);
                }
            }
        }));
    }
    for (Future<Void> f : futures) {
        try {
            f.get();
        } catch (ExecutionException e) {
            throw e;
        }
    }
    es.shutdownNow();
    assertEquals(blocksPerThread * CONCURRENCY, blocks.size());
    LongSet ids = new LongHashSet((int) blockSize * blocksPerThread * CONCURRENCY);
    for (IDBlock block : blocks) checkBlock(block, ids);
}
Also used : LongSet(com.carrotsearch.hppc.LongSet) Callable(java.util.concurrent.Callable) LongHashSet(com.carrotsearch.hppc.LongHashSet) ConsistentKeyIDAuthority(com.thinkaurelius.titan.diskstorage.idmanagement.ConsistentKeyIDAuthority) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 9 with LongSet

use of com.carrotsearch.hppc.LongSet in project titan by thinkaurelius.

the class IDAuthorityTest method testMultiIDAcquisition.

@Test
public void testMultiIDAcquisition() throws Throwable {
    final int numPartitions = MAX_NUM_PARTITIONS;
    final int numAcquisitionsPerThreadPartition = 100;
    final IDBlockSizer blockSizer = new InnerIDBlockSizer();
    for (int i = 0; i < CONCURRENCY; i++) idAuthorities[i].setIDBlockSizer(blockSizer);
    final List<ConcurrentLinkedQueue<IDBlock>> ids = new ArrayList<ConcurrentLinkedQueue<IDBlock>>(numPartitions);
    for (int i = 0; i < numPartitions; i++) {
        ids.add(new ConcurrentLinkedQueue<IDBlock>());
    }
    final int maxIterations = numAcquisitionsPerThreadPartition * numPartitions * 2;
    final Collection<Future<?>> futures = new ArrayList<Future<?>>(CONCURRENCY);
    ExecutorService es = Executors.newFixedThreadPool(CONCURRENCY);
    Set<String> uids = new HashSet<String>(CONCURRENCY);
    for (int i = 0; i < CONCURRENCY; i++) {
        final IDAuthority idAuthority = idAuthorities[i];
        final IDStressor stressRunnable = new IDStressor(numAcquisitionsPerThreadPartition, numPartitions, maxIterations, idAuthority, ids);
        uids.add(idAuthority.getUniqueID());
        futures.add(es.submit(stressRunnable));
    }
    // If this fails, it's likely to be a bug in the test rather than the
    // IDAuthority (the latter is technically possible, just less likely)
    assertEquals(CONCURRENCY, uids.size());
    for (Future<?> f : futures) {
        try {
            f.get();
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    }
    for (int i = 0; i < numPartitions; i++) {
        ConcurrentLinkedQueue<IDBlock> list = ids.get(i);
        assertEquals(numAcquisitionsPerThreadPartition * CONCURRENCY, list.size());
        LongSet idset = new LongHashSet((int) blockSize * list.size());
        for (IDBlock block : list) checkBlock(block, idset);
    }
    es.shutdownNow();
}
Also used : IDBlockSizer(com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer) LongSet(com.carrotsearch.hppc.LongSet) LongHashSet(com.carrotsearch.hppc.LongHashSet) ConsistentKeyIDAuthority(com.thinkaurelius.titan.diskstorage.idmanagement.ConsistentKeyIDAuthority) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ExecutionException(java.util.concurrent.ExecutionException) LongHashSet(com.carrotsearch.hppc.LongHashSet) Test(org.junit.Test)

Example 10 with LongSet

use of com.carrotsearch.hppc.LongSet in project cassandra by apache.

the class TokenTreeTest method buildSerializeAndGet.

public void buildSerializeAndGet(boolean isStatic) throws Exception {
    final long tokMin = 0;
    final long tokMax = 1000;
    final TokenTree tokenTree = generateTree(tokMin, tokMax, isStatic);
    for (long i = 0; i <= tokMax; i++) {
        TokenTree.OnDiskToken result = tokenTree.get(i, KEY_CONVERTER);
        Assert.assertNotNull("failed to find object for token " + i, result);
        LongSet found = result.getOffsets();
        Assert.assertEquals(1, found.size());
        Assert.assertEquals(i, found.toArray()[0]);
    }
    Assert.assertNull("found missing object", tokenTree.get(tokMax + 10, KEY_CONVERTER));
}
Also used : LongSet(com.carrotsearch.hppc.LongSet)

Aggregations

LongSet (com.carrotsearch.hppc.LongSet)15 LongHashSet (com.carrotsearch.hppc.LongHashSet)7 Test (org.junit.Test)5 LongOpenHashSet (com.carrotsearch.hppc.LongOpenHashSet)3 File (java.io.File)3 ConsistentKeyIDAuthority (com.thinkaurelius.titan.diskstorage.idmanagement.ConsistentKeyIDAuthority)2 IDBlockSizer (com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer)2 ArrayList (java.util.ArrayList)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 CombinedTerm (org.apache.cassandra.index.sasi.utils.CombinedTerm)2 MappedBuffer (org.apache.cassandra.index.sasi.utils.MappedBuffer)2 RandomAccessReader (org.apache.cassandra.io.util.RandomAccessReader)2 SequentialWriter (org.apache.cassandra.io.util.SequentialWriter)2 LongArrayList (com.carrotsearch.hppc.LongArrayList)1 LongCursor (com.carrotsearch.hppc.cursors.LongCursor)1 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)1 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1