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);
}
}
}
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);
}
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);
}
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();
}
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));
}
Aggregations