Example usage for java.util.concurrent ThreadLocalRandom nextInt

List of usage examples for java.util.concurrent ThreadLocalRandom nextInt

Introduction

In this page you can find the example usage for java.util.concurrent ThreadLocalRandom nextInt.

Prototype

public int nextInt() 

Source Link

Document

Returns a pseudorandom int value.

Usage

From source file:com.linkedin.pinot.integration.tests.UploadRefreshDeleteIntegrationTest.java

protected void generateAndUploadRandomSegment(String segmentName, int rowCount) throws Exception {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    Schema schema = new Schema.Parser().parse(
            new File(TestUtils.getFileFromResourceUrl(getClass().getClassLoader().getResource("dummy.avsc"))));
    GenericRecord record = new GenericData.Record(schema);
    GenericDatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(schema);
    DataFileWriter<GenericRecord> fileWriter = new DataFileWriter<GenericRecord>(datumWriter);
    File avroFile = new File(_tmpDir, segmentName + ".avro");
    fileWriter.create(schema, avroFile);

    for (int i = 0; i < rowCount; i++) {
        record.put(0, random.nextInt());
        fileWriter.append(record);/*ww w.  jav a2s.  c  o  m*/
    }

    fileWriter.close();

    int segmentIndex = Integer.parseInt(segmentName.split("_")[1]);

    File segmentTarDir = new File(_tarsDir, segmentName);
    ensureDirectoryExistsAndIsEmpty(segmentTarDir);
    ExecutorService executor = MoreExecutors.sameThreadExecutor();
    buildSegmentsFromAvro(Collections.singletonList(avroFile), executor, segmentIndex,
            new File(_segmentsDir, segmentName), segmentTarDir, "mytable", false, null);
    executor.shutdown();
    executor.awaitTermination(1L, TimeUnit.MINUTES);

    for (String segmentFileName : segmentTarDir.list()) {
        File file = new File(segmentTarDir, segmentFileName);
        FileUploadUtils.sendFile("localhost", "8998", "segments", segmentFileName, new FileInputStream(file),
                file.length(), FileUploadUtils.SendFileMethod.POST);
    }

    avroFile.delete();
    FileUtils.deleteQuietly(segmentTarDir);
}

From source file:org.neo4j.io.pagecache.PageCacheTest.java

@Test(timeout = SEMI_LONG_TIMEOUT_MILLIS)
public void freshlyCreatedPagesMustContainAllZeros() throws IOException {
    ThreadLocalRandom rng = ThreadLocalRandom.current();

    getPageCache(fs, maxPages, pageCachePageSize, PageCacheTracer.NULL);

    try (PagedFile pagedFile = pageCache.map(existingFile("a"), filePageSize);
            PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
        for (int i = 0; i < 100; i++) {
            assertTrue(cursor.next());/*w w w  .  j a v a 2  s . com*/
            for (int j = 0; j < filePageSize; j++) {
                cursor.putByte((byte) rng.nextInt());
            }
        }
    }
    pageCache.close();
    pageCache = null;
    System.gc(); // make sure underlying pages are finalizable
    System.gc(); // make sure underlying pages are finally collected

    getPageCache(fs, maxPages, pageCachePageSize, PageCacheTracer.NULL);

    try (PagedFile pagedFile = pageCache.map(existingFile("b"), filePageSize);
            PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
        for (int i = 0; i < 100; i++) {
            assertTrue(cursor.next());
            for (int j = 0; j < filePageSize; j++) {
                assertThat(cursor.getByte(), is((byte) 0));
            }
        }
    }
}