Search in sources :

Example 1 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project flink by apache.

the class CheckpointStatsSubtaskDetailsHandlerTest method createTaskStateStats.

private static TaskStateStats createTaskStateStats(int numAcknowledged) {
    ThreadLocalRandom rand = ThreadLocalRandom.current();
    TaskStateStats task = mock(TaskStateStats.class);
    when(task.getJobVertexId()).thenReturn(new JobVertexID());
    when(task.getLatestAckTimestamp()).thenReturn(rand.nextLong(1024) + 1);
    when(task.getStateSize()).thenReturn(rand.nextLong(1024) + 1);
    when(task.getEndToEndDuration(anyLong())).thenReturn(rand.nextLong(1024) + 1);
    when(task.getAlignmentBuffered()).thenReturn(rand.nextLong(1024) + 1);
    when(task.getNumberOfSubtasks()).thenReturn(rand.nextInt(1024) + 1);
    when(task.getNumberOfAcknowledgedSubtasks()).thenReturn(numAcknowledged);
    TaskStateStats.TaskStateStatsSummary summary = mock(TaskStateStats.TaskStateStatsSummary.class);
    doReturn(createMinMaxAvgStats(rand)).when(summary).getStateSizeStats();
    doReturn(createMinMaxAvgStats(rand)).when(summary).getAckTimestampStats();
    doReturn(createMinMaxAvgStats(rand)).when(summary).getAlignmentBufferedStats();
    doReturn(createMinMaxAvgStats(rand)).when(summary).getAlignmentDurationStats();
    doReturn(createMinMaxAvgStats(rand)).when(summary).getSyncCheckpointDurationStats();
    doReturn(createMinMaxAvgStats(rand)).when(summary).getAsyncCheckpointDurationStats();
    when(task.getSummaryStats()).thenReturn(summary);
    SubtaskStateStats[] subtasks = new SubtaskStateStats[3];
    subtasks[0] = createSubtaskStats(0, rand);
    subtasks[1] = createSubtaskStats(1, rand);
    subtasks[2] = null;
    when(task.getSubtaskStats()).thenReturn(subtasks);
    return task;
}
Also used : TaskStateStats(org.apache.flink.runtime.checkpoint.TaskStateStats) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SubtaskStateStats(org.apache.flink.runtime.checkpoint.SubtaskStateStats)

Example 2 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project flink by apache.

the class MinMaxAvgStatsTest method testAddRandomNumbers.

/**
	 * Test sequence of random numbers.
	 */
@Test
public void testAddRandomNumbers() throws Exception {
    ThreadLocalRandom rand = ThreadLocalRandom.current();
    MinMaxAvgStats mma = new MinMaxAvgStats();
    long count = 13;
    long sum = 0;
    long min = Integer.MAX_VALUE;
    long max = Integer.MIN_VALUE;
    for (int i = 0; i < count; i++) {
        int number = rand.nextInt(124) + 1;
        sum += number;
        min = Math.min(min, number);
        max = Math.max(max, number);
        mma.add(number);
    }
    assertEquals(min, mma.getMinimum());
    assertEquals(max, mma.getMaximum());
    assertEquals(sum, mma.getSum());
    assertEquals(count, mma.getCount());
    assertEquals(sum / count, mma.getAverage());
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Test(org.junit.Test)

Example 3 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project jetty.project by eclipse.

the class HttpClientLoadTest method test.

private void test(final CountDownLatch latch, final List<String> failures) {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    // Choose a random destination
    String host = random.nextBoolean() ? "localhost" : "127.0.0.1";
    // Choose a random method
    HttpMethod method = random.nextBoolean() ? HttpMethod.GET : HttpMethod.POST;
    boolean ssl = isTransportSecure();
    // Choose randomly whether to close the connection on the client or on the server
    boolean clientClose = false;
    if (!ssl && random.nextInt(100) < 5)
        clientClose = true;
    boolean serverClose = false;
    if (!ssl && random.nextInt(100) < 5)
        serverClose = true;
    int maxContentLength = 64 * 1024;
    int contentLength = random.nextInt(maxContentLength) + 1;
    test(getScheme(), host, method.asString(), clientClose, serverClose, contentLength, true, latch, failures);
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) HttpMethod(org.eclipse.jetty.http.HttpMethod)

Example 4 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project hibernate-orm by hibernate.

the class CorrectnessTestCase method createFamily.

private static Family createFamily() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    String familyName = randomString(random);
    Family f = new Family(familyName);
    HashSet<Person> members = new HashSet<>();
    members.add(createPerson(random, f));
    f.setMembers(members);
    return f;
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Family(org.hibernate.test.cache.infinispan.stress.entities.Family) Person(org.hibernate.test.cache.infinispan.stress.entities.Person) HashSet(java.util.HashSet)

Example 5 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project cassandra-mesos-deprecated by mesosphere.

the class CassandraCluster method liveNodes.

@NotNull
public List<CassandraNode> liveNodes(int limit) {
    final CassandraClusterState state = clusterState.get();
    final int total = state.getNodesCount();
    if (total == 0) {
        return Collections.emptyList();
    }
    int totalLive = 0;
    for (int i = 0; i < total; i++) {
        if (isLiveNode(state.getNodes(i))) {
            totalLive++;
        }
    }
    limit = Math.min(totalLive, limit);
    final ThreadLocalRandom tlr = ThreadLocalRandom.current();
    final List<CassandraNode> result = new ArrayList<>(limit);
    int misses = 0;
    while (result.size() < limit && misses < 250) {
        // the check for 250 misses is a poor-man's implementation to prevent a possible race-condition
        final int i = tlr.nextInt(total);
        final CassandraNode node = state.getNodes(i);
        if (isLiveNode(node) && !result.contains(node)) {
            result.add(node);
            misses = 0;
        } else {
            misses++;
        }
    }
    return result;
}
Also used : Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) NotNull(org.jetbrains.annotations.NotNull)

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