use of java.util.function.Supplier in project jdk8u_jdk by JetBrains.
the class ConcurrentAssociateTest method testOnce.
private static void testOnce(String desc, BiConsumer<ConcurrentMap<Object, Object>, Object> associator) {
ConcurrentHashMap<Object, Object> m = new ConcurrentHashMap<>();
CountDownLatch s = new CountDownLatch(1);
Supplier<Runnable> sr = () -> () -> {
try {
s.await();
} catch (InterruptedException e) {
}
for (int i = 0; i < N; i++) {
Object o = new X();
associator.accept(m, o);
if (!m.containsKey(o)) {
throw new AssociationFailure(desc + " failed: entry does not exist");
}
}
};
int ps = Runtime.getRuntime().availableProcessors();
Stream<CompletableFuture> runners = IntStream.range(0, ps).mapToObj(i -> sr.get()).map(CompletableFuture::runAsync);
CompletableFuture all = CompletableFuture.allOf(runners.toArray(CompletableFuture[]::new));
// Trigger the runners to start associating
s.countDown();
try {
all.join();
} catch (CompletionException e) {
Throwable t = e.getCause();
if (t instanceof AssociationFailure) {
throw (AssociationFailure) t;
} else {
throw e;
}
}
}
use of java.util.function.Supplier in project riposte by Nike-Inc.
the class AsyncNettyHelperTest method supplierWithTracingAndMdc_pair_works_as_expected.
@Test
public void supplierWithTracingAndMdc_pair_works_as_expected() {
// given
Pair<Deque<Span>, Map<String, String>> setupInfo = generateTracingAndMdcInfo();
// when
Supplier result = AsyncNettyHelper.supplierWithTracingAndMdc(supplierMock, setupInfo);
// then
verifySupplierWithTracingAndMdcSupport(result, supplierMock, setupInfo.getLeft(), setupInfo.getRight());
}
use of java.util.function.Supplier in project riposte by Nike-Inc.
the class AsyncNettyHelperTest method supplierWithTracingAndMdc_separate_args_works_as_expected.
@Test
public void supplierWithTracingAndMdc_separate_args_works_as_expected() {
// given
Pair<Deque<Span>, Map<String, String>> setupInfo = generateTracingAndMdcInfo();
// when
Supplier result = AsyncNettyHelper.supplierWithTracingAndMdc(supplierMock, setupInfo.getLeft(), setupInfo.getRight());
// then
verifySupplierWithTracingAndMdcSupport(result, supplierMock, setupInfo.getLeft(), setupInfo.getRight());
}
use of java.util.function.Supplier in project riposte by Nike-Inc.
the class ParserTest method test_match9_works.
@Test
public void test_match9_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Pattern booleanPattern = Pattern.compile("(true|false)");
final Supplier<Parser<Integer>> number = () -> regex(numberPattern).map(m -> new Integer(m.group(1)));
final Supplier<Parser<Boolean>> bool = () -> regex(booleanPattern).map(m -> new Boolean(m.group(1)));
Parser<String> parser = number.get().thenParse(string("A")).thenParse(bool).thenParse(number).thenParse(string("B")).thenParse(bool).thenParse(number).thenParse(string("C")).thenParse(bool).map(match((first, second, third, fourth, fifth, sixth, seventh, eighth, nineth) -> {
return first.toString() + "+" + second.toString() + "+" + third.toString() + "+" + fourth.toString() + "+" + fifth.toString() + "+" + sixth.toString() + "+" + seventh.toString() + "+" + eighth.toString() + "+" + nineth.toString();
}));
Optional<String> oResult = parser.tryParse("1Atrue2Bfalse3Ctrue");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo("1+A+true+2+B+false+3+C+true");
}
use of java.util.function.Supplier in project riposte by Nike-Inc.
the class ParserTest method test_match8_works.
@Test
public void test_match8_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Pattern booleanPattern = Pattern.compile("(true|false)");
final Supplier<Parser<Integer>> number = () -> regex(numberPattern).map(m -> new Integer(m.group(1)));
final Supplier<Parser<Boolean>> bool = () -> regex(booleanPattern).map(m -> new Boolean(m.group(1)));
Parser<String> parser = number.get().thenParse(string("A")).thenParse(bool).thenParse(number).thenParse(string("B")).thenParse(bool).thenParse(number).thenParse(string("C")).map(match((first, second, third, fourth, fifth, sixth, seventh, eighth) -> {
return first.toString() + "+" + second.toString() + "+" + third.toString() + "+" + fourth.toString() + "+" + fifth.toString() + "+" + sixth.toString() + "+" + seventh.toString() + "+" + eighth.toString();
}));
Optional<String> oResult = parser.tryParse("1Atrue2Bfalse3C");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo("1+A+true+2+B+false+3+C");
}
Aggregations