long[] randomLongsGet = new Random(0x123456789ABCDL).longs().limit(this.mapSizeDividedBy16000).toArray();
@Test(dataProvider = "filterTypes") public void bloomFilterTest(FilterType filterType) { for (int capacity = 2 << 10; capacity < (2 << 22); capacity = capacity << 2) { long[] input = new Random().longs(capacity).distinct().toArray(); List<String[]> rows = new ArrayList<>(); int expectedInsertions = capacity / 2; Membership filter = filterType.create(expectedInsertions, FPP, CONFIG); int falsePositives = falsePositives(filter, input); double falsePositiveRate = ((double) falsePositives / expectedInsertions); assertThat(filterType.toString(), falsePositiveRate, is(lessThan(FPP + 0.01))); rows.add(row(filterType, expectedInsertions, falsePositives, falsePositiveRate)); if (display) { printTable(rows); } } }
@Test(timeout=180000) public void testCRUD() throws Exception { Random random = new Random(); LongStream longStream = random.longs(1000); Set<Long> added = new HashSet<>(); longStream.forEach(x -> { CACHE1.put(x, new BlobValue()); added.add(x); }); Set<Long> readKeysByCache2BeforeFailOver = new HashSet<>(); added.forEach(x -> { if (CACHE2.get(x) != null) { readKeysByCache2BeforeFailOver.add(x); } }); CLUSTER.getClusterControl().terminateActive(); Set<Long> readKeysByCache1AfterFailOver = new HashSet<>(); added.forEach(x -> { if (CACHE1.get(x) != null) { readKeysByCache1AfterFailOver.add(x); } }); assertThat(readKeysByCache2BeforeFailOver.size(), greaterThanOrEqualTo(readKeysByCache1AfterFailOver.size())); readKeysByCache1AfterFailOver.stream().filter(readKeysByCache2BeforeFailOver::contains).forEach(y -> assertThat(CACHE2.get(y), notNullValue())); }
@Test(timeout=180000) @Ignore //TODO: FIXME: FIX THIS RANDOMLY FAILING TEST public void testBulkOps() throws Exception { List<Cache<Long, BlobValue>> caches = new ArrayList<>(); caches.add(CACHE1); caches.add(CACHE2); Map<Long, BlobValue> entriesMap = new HashMap<>(); Random random = new Random(); LongStream longStream = random.longs(1000); longStream.forEach(x -> entriesMap.put(x, new BlobValue())); caches.forEach(cache -> cache.putAll(entriesMap)); Set<Long> keySet = entriesMap.keySet(); Set<Long> readKeysByCache2BeforeFailOver = new HashSet<>(); keySet.forEach(x -> { if (CACHE2.get(x) != null) { readKeysByCache2BeforeFailOver.add(x); } }); CLUSTER.getClusterControl().terminateActive(); Set<Long> readKeysByCache1AfterFailOver = new HashSet<>(); keySet.forEach(x -> { if (CACHE1.get(x) != null) { readKeysByCache1AfterFailOver.add(x); } }); assertThat(readKeysByCache2BeforeFailOver.size(), greaterThanOrEqualTo(readKeysByCache1AfterFailOver.size())); readKeysByCache1AfterFailOver.stream().filter(readKeysByCache2BeforeFailOver::contains).forEach(y -> assertThat(CACHE2.get(y), notNullValue())); }
@Test(timeout=180000) public void testClear() throws Exception { List<Cache<Long, BlobValue>> caches = new ArrayList<>(); caches.add(CACHE1); caches.add(CACHE2); Map<Long, BlobValue> entriesMap = new HashMap<>(); Random random = new Random(); LongStream longStream = random.longs(1000); longStream.forEach(x -> entriesMap.put(x, new BlobValue())); caches.forEach(cache -> cache.putAll(entriesMap)); Set<Long> keySet = entriesMap.keySet(); Set<Long> readKeysByCache2BeforeFailOver = new HashSet<>(); keySet.forEach(x -> { if (CACHE2.get(x) != null) { readKeysByCache2BeforeFailOver.add(x); } }); CACHE1.clear(); CLUSTER.getClusterControl().terminateActive(); if (cacheConsistency == Consistency.STRONG) { readKeysByCache2BeforeFailOver.forEach(x -> assertThat(CACHE2.get(x), nullValue())); } else { readKeysByCache2BeforeFailOver.forEach(x -> assertThat(CACHE1.get(x), nullValue())); } }
@Test public void testLazyBlockBuilderInitialization() { long[][] expectedValues = new long[ARRAY_SIZES.length][]; Random rand = new Random(47); for (int i = 0; i < ARRAY_SIZES.length; i++) { expectedValues[i] = rand.longs(ARRAY_SIZES[i]).toArray(); } BlockBuilder emptyBlockBuilder = new ArrayBlockBuilder(BIGINT, null, 0, 0); BlockBuilder blockBuilder = new ArrayBlockBuilder(BIGINT, null, 100, 100); assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes()); assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes()); writeValues(expectedValues, blockBuilder); assertTrue(blockBuilder.getSizeInBytes() > emptyBlockBuilder.getSizeInBytes()); assertTrue(blockBuilder.getRetainedSizeInBytes() > emptyBlockBuilder.getRetainedSizeInBytes()); blockBuilder = blockBuilder.newBlockBuilderLike(null); assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes()); assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes()); }
@Test public void testWithFixedWidthBlock() { long[][] expectedValues = new long[ARRAY_SIZES.length][]; Random rand = new Random(47); for (int i = 0; i < ARRAY_SIZES.length; i++) { expectedValues[i] = rand.longs(ARRAY_SIZES[i]).toArray(); } BlockBuilder blockBuilder = createBlockBuilderWithValues(expectedValues); assertBlock(blockBuilder, () -> blockBuilder.newBlockBuilderLike(null), expectedValues); assertBlock(blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), expectedValues); assertBlockFilteredPositions(expectedValues, blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), 0, 1, 3, 4, 7); assertBlockFilteredPositions(expectedValues, blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), 2, 3, 5, 6); long[][] expectedValuesWithNull = alternatingNullValues(expectedValues); BlockBuilder blockBuilderWithNull = createBlockBuilderWithValues(expectedValuesWithNull); assertBlock(blockBuilderWithNull, () -> blockBuilder.newBlockBuilderLike(null), expectedValuesWithNull); assertBlock(blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), expectedValuesWithNull); assertBlockFilteredPositions(expectedValuesWithNull, blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), 0, 1, 5, 6, 7, 10, 11, 12, 15); assertBlockFilteredPositions(expectedValuesWithNull, blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), 2, 3, 4, 9, 13, 14); }
RandomExpirationSupplier(Supplier<T> delegate, long minDuration, long maxDuration, TimeUnit timeUnit) { checkArgument(minDuration >= 0, "minDuration cannot be negative"); checkArgument(maxDuration > minDuration, "maxDuration must be greater than minDuration"); checkNotNull(delegate, "delegate"); checkNotNull(timeUnit, "timeUnit"); long minDurationNanos = timeUnit.toNanos(minDuration); long maxDurationNanos = timeUnit.toNanos(maxDuration); _delegate = delegate; _nanosDurations = new Random().longs(minDurationNanos, maxDurationNanos).iterator(); }
public Stream<Long> longStream(Long size, Long start, Long bound) { return random.longs(size, start, bound).boxed(); } }
RandomExpirationSupplier(Supplier<T> delegate, long minDuration, long maxDuration, TimeUnit timeUnit) { checkArgument(minDuration >= 0, "minDuration cannot be negative"); checkArgument(maxDuration > minDuration, "maxDuration must be greater than minDuration"); checkNotNull(delegate, "delegate"); checkNotNull(timeUnit, "timeUnit"); long minDurationNanos = timeUnit.toNanos(minDuration); long maxDurationNanos = timeUnit.toNanos(maxDuration); _delegate = delegate; _nanosDurations = new Random().longs(minDurationNanos, maxDurationNanos).iterator(); }
@Override public long nextLong(long bound) { return random.longs(1, 0, bound).findFirst().getAsLong(); }
@Override public long nextLong(long lower, long upper) { return random.longs(1, lower, upper).findFirst().getAsLong(); }
@Override public long nextLong(long bound) { return random.longs(1, 0, bound).findFirst().getAsLong(); }
public Optional<QuoteOfTheDay> random() { long count = repository.count(); if(count==0) return Optional.empty(); Random r = new Random(); long randomIndex=count<=Integer.MAX_VALUE? r.nextInt((int)count): r.longs(1, 0, count).findFirst().orElseThrow(AssertionError::new); return StreamSupport.stream(repository.findAll().spliterator(), false) .skip(randomIndex).findFirst(); }
public static long randomLongBetween(long startInclusive, long endInclusive) { return RANDOM.longs(startInclusive, addExact(endInclusive, 1)) .findFirst() .getAsLong(); }
public List<Point> getRandomPoints(int num) { long count=allValues().count(); assert count > num; return new Random().longs(0, count) .distinct() .limit(num) .mapToObj(i -> allValues().skip(i).findFirst().get()) .collect(Collectors.toList()); }
static ClusterPlacement createClusterPlacement( Supplier<Long> timeSource, int clusterNumber, SpydraArgument.Pooling pooling) { long time = timeSource.get() / 1000; long age = pooling.getMaxAge().getSeconds(); long timeOffset = new Random(clusterNumber).longs(1, 0, age).findFirst().getAsLong(); long generation = computeGeneration(time + timeOffset, age); return new ClusterPlacementBuilder() .clusterNumber(clusterNumber) .clusterGeneration(generation) .build(); }
@Test(dataProvider = "sorters") public void sortRandomLongValues(final IndexSorter sorter, final Integer size) { final long[] values = new Random().longs(size).toArray(); final long[] actual = indexSort(sorter, values); final long[] expected = arraySort(values); Assert.assertEquals(actual, expected); }
private Set<Cookie> createCookies(int numberOfCookies) { if (numberOfCookies < 0) { return null; } Set<Cookie> cookies = new HashSet<>(); for (int x = 0; x < numberOfCookies; x++) { Cookie cookie = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString()); cookie.setHttpOnly(new Random().ints(0, 1000).findAny().getAsInt() % 2 == 0); cookie.setMaxAge(new Random().longs(0, 1000).findAny().getAsLong()); cookies.add(cookie); } return cookies; }
private Location[] getTwoNodes(final PackedAtlas packedAtlas, final long size) { final OfLong iterator = this.random.longs(0, size).iterator(); final long index1 = iterator.next(); final long index2 = iterator.next(); final Location[] result = new Location[2]; result[0] = packedAtlas.nodeLocation(index1); result[1] = packedAtlas.nodeLocation(index2); return result; } }