use of java.util.concurrent.ThreadLocalRandom in project cassandra by apache.
the class WaitQueueTest method testSerial.
public void testSerial(final WaitQueue queue) throws InterruptedException {
final AtomicInteger ready = new AtomicInteger();
Thread[] ts = new Thread[4];
for (int i = 0; i < ts.length; i++) ts[i] = NamedThreadFactory.createThread(new Runnable() {
@Override
public void run() {
WaitQueue.Signal wait = queue.register();
ready.incrementAndGet();
try {
wait.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
for (Thread t : ts) t.start();
final ThreadLocalRandom random = ThreadLocalRandom.current();
while (ready.get() < ts.length) random.nextLong();
for (Thread t : ts) queue.signal();
for (Thread t : ts) {
Util.joinThread(t);
assertFalse(queue.getClass().getName(), t.isAlive());
}
}
use of java.util.concurrent.ThreadLocalRandom in project cassandra by apache.
the class ColumnsTest method randomHuge.
private static List<ColumnsCheck> randomHuge() {
List<ColumnsCheck> result = new ArrayList<>();
ThreadLocalRandom random = ThreadLocalRandom.current();
result.add(randomHuge(random.nextInt(64, 128), 0, 0, 0));
result.add(randomHuge(0, random.nextInt(64, 128), 0, 0));
result.add(randomHuge(0, 0, random.nextInt(64, 128), 0));
result.add(randomHuge(0, 0, 0, random.nextInt(64, 128)));
result.add(randomHuge(random.nextInt(64, 128), random.nextInt(64, 128), 0, 0));
result.add(randomHuge(0, random.nextInt(64, 128), random.nextInt(64, 128), 0));
result.add(randomHuge(0, 0, random.nextInt(64, 128), random.nextInt(64, 128)));
result.add(randomHuge(random.nextInt(64, 128), random.nextInt(64, 128), random.nextInt(64, 128), 0));
result.add(randomHuge(0, random.nextInt(64, 128), random.nextInt(64, 128), random.nextInt(64, 128)));
result.add(randomHuge(random.nextInt(64, 128), random.nextInt(64, 128), random.nextInt(64, 128), random.nextInt(64, 128)));
return result;
}
use of java.util.concurrent.ThreadLocalRandom in project cassandra by apache.
the class ColumnsTest method select.
private static List<String> select(List<String> names, int count) {
List<String> result = new ArrayList<>();
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i = 0; i < count; i++) {
int v = random.nextInt(names.size());
result.add(names.get(v));
names.remove(v);
}
return result;
}
use of java.util.concurrent.ThreadLocalRandom in project cassandra by apache.
the class OnDiskIndexTest method testSparseMode.
@Test
public void testSparseMode() throws Exception {
OnDiskIndexBuilder builder = new OnDiskIndexBuilder(UTF8Type.instance, LongType.instance, OnDiskIndexBuilder.Mode.SPARSE);
final long start = System.currentTimeMillis();
final int numIterations = 100000;
for (long i = 0; i < numIterations; i++) builder.add(LongType.instance.decompose(start + i), keyAt(i), i);
File index = File.createTempFile("on-disk-sa-sparse", "db");
index.deleteOnExit();
builder.finish(index);
OnDiskIndex onDisk = new OnDiskIndex(index, LongType.instance, new KeyConverter());
ThreadLocalRandom random = ThreadLocalRandom.current();
for (long step = start; step < (start + numIterations); step += 1000) {
boolean lowerInclusive = random.nextBoolean();
boolean upperInclusive = random.nextBoolean();
long limit = random.nextLong(step, start + numIterations);
RangeIterator<Long, Token> rows = onDisk.search(expressionFor(step, lowerInclusive, limit, upperInclusive));
long lowerKey = step - start;
long upperKey = lowerKey + (limit - step);
if (!lowerInclusive)
lowerKey += 1;
if (upperInclusive)
upperKey += 1;
Set<DecoratedKey> actual = convert(rows);
for (long key = lowerKey; key < upperKey; key++) Assert.assertTrue("key" + key + " wasn't found", actual.contains(keyAt(key)));
Assert.assertEquals((upperKey - lowerKey), actual.size());
}
// let's also explicitly test whole range search
RangeIterator<Long, Token> rows = onDisk.search(expressionFor(start, true, start + numIterations, true));
Set<DecoratedKey> actual = convert(rows);
Assert.assertEquals(numIterations, actual.size());
}
use of java.util.concurrent.ThreadLocalRandom in project cassandra by apache.
the class RangeIntersectionIteratorTest method testIntersectionOfRandomRanges.
private void testIntersectionOfRandomRanges(Strategy strategy) {
for (int attempt = 0; attempt < 16; attempt++) {
final ThreadLocalRandom random = ThreadLocalRandom.current();
final int maxRanges = random.nextInt(2, 16);
// generate randomize ranges
long[][] ranges = new long[maxRanges][];
for (int i = 0; i < ranges.length; i++) {
int rangeSize = random.nextInt(16, 512);
LongSet range = new LongOpenHashSet(rangeSize);
for (int j = 0; j < rangeSize; j++) range.add(random.nextLong(0, 100));
ranges[i] = range.toArray();
Arrays.sort(ranges[i]);
}
List<Long> expected = new ArrayList<>();
// determine unique tokens which intersect every range
for (long token : ranges[0]) {
boolean intersectsAll = true;
for (int i = 1; i < ranges.length; i++) {
if (Arrays.binarySearch(ranges[i], token) < 0) {
intersectsAll = false;
break;
}
}
if (intersectsAll)
expected.add(token);
}
RangeIterator.Builder<Long, Token> builder = RangeIntersectionIterator.builder(strategy);
for (long[] range : ranges) builder.add(new LongIterator(range));
Assert.assertEquals(expected, convert(builder.build()));
}
}
Aggregations