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