Search in sources :

Example 26 with ThreadLocalRandom

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());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 27 with ThreadLocalRandom

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;
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 28 with ThreadLocalRandom

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;
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 29 with ThreadLocalRandom

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());
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) File(java.io.File) Test(org.junit.Test)

Example 30 with ThreadLocalRandom

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()));
    }
}
Also used : LongSet(com.carrotsearch.hppc.LongSet) Token(org.apache.cassandra.index.sasi.disk.Token) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) LongOpenHashSet(com.carrotsearch.hppc.LongOpenHashSet)

Aggregations

ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)186 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)49 Ignite (org.apache.ignite.Ignite)47 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)45 IgniteCache (org.apache.ignite.IgniteCache)33 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)26 IgniteException (org.apache.ignite.IgniteException)26 Transaction (org.apache.ignite.transactions.Transaction)24 CacheException (javax.cache.CacheException)21 HashMap (java.util.HashMap)16 Map (java.util.Map)15 IgniteTransactions (org.apache.ignite.IgniteTransactions)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 TreeMap (java.util.TreeMap)11 Callable (java.util.concurrent.Callable)11 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 LongAdder (java.util.concurrent.atomic.LongAdder)9 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)9