Java Code Examples for reactor.util.function.Tuples#of()
The following examples show how to use
reactor.util.function.Tuples#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationRegistry.java From spring-boot-admin with Apache License 2.0 | 6 votes |
protected Tuple2<String, Instant> getStatus(List<Instance> instances) { // TODO: Correct is just a second readmodel for groups Map<String, Instant> statusWithTime = instances.stream().collect( toMap((instance) -> instance.getStatusInfo().getStatus(), Instance::getStatusTimestamp, this::getMax)); if (statusWithTime.size() == 1) { Map.Entry<String, Instant> e = statusWithTime.entrySet().iterator().next(); return Tuples.of(e.getKey(), e.getValue()); } if (statusWithTime.containsKey(StatusInfo.STATUS_UP)) { Instant oldestNonUp = statusWithTime.entrySet().stream() .filter((e) -> !StatusInfo.STATUS_UP.equals(e.getKey())).map(Map.Entry::getValue) .min(naturalOrder()).orElse(Instant.EPOCH); Instant latest = getMax(oldestNonUp, statusWithTime.getOrDefault(StatusInfo.STATUS_UP, Instant.EPOCH)); return Tuples.of(StatusInfo.STATUS_RESTRICTED, latest); } return statusWithTime.entrySet().stream().min(Map.Entry.comparingByKey(StatusInfo.severity())) .map((e) -> Tuples.of(e.getKey(), e.getValue())).orElse(Tuples.of(STATUS_UNKNOWN, Instant.EPOCH)); }
Example 2
Source File: FluxNameFuseableTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanOperator() throws Exception { Tuple2<String, String> tag1 = Tuples.of("foo", "oof"); Tuple2<String, String> tag2 = Tuples.of("bar", "rab"); Set<Tuple2<String, String>> tags = new HashSet<>(); tags.add(tag1); tags.add(tag2); Flux<Integer> source = Flux.range(1, 4).map(i -> i); FluxNameFuseable<Integer> test = new FluxNameFuseable<>(source, "foo", tags); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(-1); assertThat(test.scan(Scannable.Attr.NAME)).isEqualTo("foo"); //noinspection unchecked final Stream<Tuple2<String, String>> scannedTags = test.scan(Scannable.Attr.TAGS); assertThat(scannedTags).isNotNull(); assertThat(scannedTags.iterator()).containsExactlyInAnyOrder(tag1, tag2); }
Example 3
Source File: FluxNameTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanOperator() throws Exception { Tuple2<String, String> tag1 = Tuples.of("foo", "oof"); Tuple2<String, String> tag2 = Tuples.of("bar", "rab"); Set<Tuple2<String, String>> tags = new HashSet<>(); tags.add(tag1); tags.add(tag2); Flux<Integer> source = Flux.range(1, 4).map(i -> i); FluxName<Integer> test = new FluxName<>(source, "foo", tags); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(-1); assertThat(test.scan(Scannable.Attr.NAME)).isEqualTo("foo"); final Stream<Tuple2<String, String>> scannedTags = test.scan(Scannable.Attr.TAGS); assertThat(scannedTags).isNotNull(); assertThat(scannedTags.iterator()).containsExactlyInAnyOrder(tag1, tag2); }
Example 4
Source File: MonoNameFuseableTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanOperator() throws Exception { Tuple2<String, String> tag1 = Tuples.of("foo", "oof"); Tuple2<String, String> tag2 = Tuples.of("bar", "rab"); Set<Tuple2<String, String>> tags = new HashSet<>(); tags.add(tag1); tags.add(tag2); Mono<Integer> source = Mono.just(1).map(i -> i); MonoNameFuseable<Integer> test = new MonoNameFuseable<>(source, "foo", tags); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE); assertThat(test.scan(Scannable.Attr.NAME)).isEqualTo("foo"); final Stream<Tuple2<String, String>> scannedTags = test.scan(Scannable.Attr.TAGS); assertThat(scannedTags).isNotNull(); assertThat(scannedTags.iterator()).containsExactlyInAnyOrder(tag1, tag2); }
Example 5
Source File: MonoNameTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanOperator() throws Exception { Tuple2<String, String> tag1 = Tuples.of("foo", "oof"); Tuple2<String, String> tag2 = Tuples.of("bar", "rab"); Set<Tuple2<String, String>> tags = new HashSet<>(); tags.add(tag1); tags.add(tag2); Mono<Integer> source = Mono.just(1).map(i -> i); MonoName<Integer> test = new MonoName<>(source, "foo", tags); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE); assertThat(test.scan(Scannable.Attr.NAME)).isEqualTo("foo"); final Stream<Tuple2<String, String>> scannedTags = test.scan(Scannable.Attr.TAGS); assertThat(scannedTags).isNotNull(); assertThat(scannedTags.iterator()).containsExactlyInAnyOrder(tag1, tag2); }
Example 6
Source File: ParallelFluxNameTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanOperator() throws Exception { Tuple2<String, String> tag1 = Tuples.of("foo", "oof"); Tuple2<String, String> tag2 = Tuples.of("bar", "rab"); Set<Tuple2<String, String>> tags = new HashSet<>(); tags.add(tag1); tags.add(tag2); ParallelFlux<Integer> source = Flux.range(1, 4).parallel(3); ParallelFluxName<Integer> test = new ParallelFluxName<>(source, "foo", tags); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)) .isEqualTo(256) .isEqualTo(source.getPrefetch()); assertThat(test.scan(Scannable.Attr.NAME)).isEqualTo("foo"); final Stream<Tuple2<String, String>> scannedTags = test.scan(Scannable.Attr.TAGS); assertThat(scannedTags).isNotNull(); assertThat(scannedTags.iterator()).containsExactlyInAnyOrder(tag1, tag2); }
Example 7
Source File: GatewayRSocketTests.java From spring-cloud-rsocket with Apache License 2.0 | 6 votes |
@Before public void init() { routingTable = mock(RoutingTable.class); this.metadataExtractor.metadataToExtract(FORWARDING_MIME_TYPE, Forwarding.class, "forwarding"); MetadataEncoder encoder = new MetadataEncoder(Metadata.COMPOSITE_MIME_TYPE, this.rSocketStrategies); Forwarding metadata = Forwarding.of(1).with(WellKnownKey.SERVICE_NAME, "mock") .build(); DataBuffer dataBuffer = encoder.metadata(metadata, FORWARDING_MIME_TYPE).encode(); DataBuffer data = MetadataEncoder.emptyDataBuffer(rSocketStrategies); incomingPayload = PayloadUtils.createPayload(data, dataBuffer); RSocket rSocket = mock(RSocket.class); Tuple2<String, RSocket> tuple = Tuples.of("1111", rSocket); when(routingTable.findRSockets(any(TagsMetadata.class))) .thenReturn(Collections.singletonList(tuple)); when(rSocket.requestResponse(any(Payload.class))) .thenReturn(Mono.just(DefaultPayload.create("response"))); }
Example 8
Source File: QueryTestSupport.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
static Tuple2<String, int[]> link(String name, int... indexes) { if (indexes.length == 0) { throw new IllegalArgumentException("must has least one index"); } return Tuples.of(name, indexes); }
Example 9
Source File: BeanFactoryAwareFunctionRegistryTests.java From spring-cloud-function with Apache License 2.0 | 5 votes |
@Bean public Function<Flux<Person>, Tuple3<Flux<Person>, Flux<String>, Flux<Integer>>> multiOutputAsTuple() { return flux -> { Flux<Person> pubSubFlux = flux.publish().autoConnect(3); Flux<String> nameFlux = pubSubFlux.map(person -> person.getName()); Flux<Integer> idFlux = pubSubFlux.map(person -> person.getId()); return Tuples.of(pubSubFlux, nameFlux, idFlux); }; }
Example 10
Source File: FluxIndexedFuseableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void indexMapperThrows() { Flux<String> source = Flux.just("foo", "bar"); Flux<Tuple2<Integer, String>> test = new FluxIndexFuseable<>(source, (i, v) -> { if (i == 0L) return Tuples.of(0, v); throw new IllegalStateException("boom-" + i); }); StepVerifier.create(test) .expectNext(Tuples.of(0, "foo")) .verifyErrorSatisfies(e -> assertThat(e) .isInstanceOf(IllegalStateException.class) .hasMessage("boom-1")); }
Example 11
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java From spring-cloud-function with Apache License 2.0 | 5 votes |
@Bean public Function<Flux<Message<Person>>, Tuple3<Flux<Person>, Flux<String>, Flux<Integer>>> multiOutputAsTupleMessageIn() { return flux -> { Flux<Person> pubSubFlux = flux.map(message -> message.getPayload()).publish().autoConnect(3); Flux<String> nameFlux = pubSubFlux.map(person -> person.getName()); Flux<Integer> idFlux = pubSubFlux.map(person -> person.getId()); return Tuples.of(pubSubFlux, nameFlux, idFlux); }; }
Example 12
Source File: FluxIndexTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void indexMapperThrows() { Flux<String> source = Flux.just("foo", "bar"); Flux<Tuple2<Integer, String>> test = new FluxIndex<>(source, (i, v) -> { if (i == 0L) return Tuples.of(0, v); throw new IllegalStateException("boom-" + i); }); StepVerifier.create(test) .expectNext(Tuples.of(0, "foo")) .verifyErrorSatisfies(e -> assertThat(e) .isInstanceOf(IllegalStateException.class) .hasMessage("boom-1")); }
Example 13
Source File: ApplicationController.java From Moss with Apache License 2.0 | 5 votes |
protected Tuple2<String, Instant> getStatus(List<Instance> instances) { Map<String, Instant> statusWithTime = instances.stream() .collect(toMap(instance -> instance.getStatusInfo().getStatus(), Instance::getStatusTimestamp, this::getMax )); if (statusWithTime.size() == 1) { Map.Entry<String, Instant> e = statusWithTime.entrySet().iterator().next(); return Tuples.of(e.getKey(), e.getValue()); } if (statusWithTime.containsKey(StatusInfo.STATUS_UP)) { Instant oldestNonUp = statusWithTime.entrySet() .stream() .filter(e -> !StatusInfo.STATUS_UP.equals(e.getKey())) .map(Map.Entry::getValue) .min(naturalOrder()) .orElse(Instant.EPOCH); Instant latest = getMax(oldestNonUp, statusWithTime.getOrDefault(StatusInfo.STATUS_UP, Instant.EPOCH)); return Tuples.of(StatusInfo.STATUS_RESTRICTED, latest); } return statusWithTime.entrySet() .stream() .min(Map.Entry.comparingByKey(StatusInfo.severity())) .map(e -> Tuples.of(e.getKey(), e.getValue())) .orElse(Tuples.of(STATUS_UNKNOWN, Instant.EPOCH)); }
Example 14
Source File: ApplicationsController.java From Moss with Apache License 2.0 | 5 votes |
protected Tuple2<String, Instant> getStatus(List<Instance> instances) { //TODO: Correct is just a second readmodel for groups Map<String, Instant> statusWithTime = instances.stream() .collect(toMap(instance -> instance.getStatusInfo().getStatus(), Instance::getStatusTimestamp, this::getMax )); if (statusWithTime.size() == 1) { Map.Entry<String, Instant> e = statusWithTime.entrySet().iterator().next(); return Tuples.of(e.getKey(), e.getValue()); } if (statusWithTime.containsKey(StatusInfo.STATUS_UP)) { Instant oldestNonUp = statusWithTime.entrySet() .stream() .filter(e -> !StatusInfo.STATUS_UP.equals(e.getKey())) .map(Map.Entry::getValue) .min(naturalOrder()) .orElse(Instant.EPOCH); Instant latest = getMax(oldestNonUp, statusWithTime.getOrDefault(StatusInfo.STATUS_UP, Instant.EPOCH)); return Tuples.of(StatusInfo.STATUS_RESTRICTED, latest); } return statusWithTime.entrySet() .stream() .min(Map.Entry.comparingByKey(StatusInfo.severity())) .map(e -> Tuples.of(e.getKey(), e.getValue())) .orElse(Tuples.of(STATUS_UNKNOWN, Instant.EPOCH)); }
Example 15
Source File: FluxOnAssembly.java From reactor-core with Apache License 2.0 | 5 votes |
private void add(Publisher<?> parent, String prefix, String line) { //noinspection ConstantConditions int key = getParentOrThis(Scannable.from(parent)); synchronized (chainOrder) { int i = 0; int n = chainOrder.size(); int j = n - 1; Tuple4<Integer, String, String, Integer> tmp; while(j >= 0){ tmp = chainOrder.get(j); //noinspection ConstantConditions if(tmp.getT1() == key){ //noinspection ConstantConditions i = tmp.getT4(); break; } j--; } for(;;){ Tuple4<Integer, String, String, Integer> t = Tuples.of(parent.hashCode(), prefix, line, i); if(!chainOrder.contains(t)){ chainOrder.add(t); break; } i++; } } }
Example 16
Source File: FluxIterableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanOperator() { Iterable<String> collection = Arrays.asList("A", "B", "C"); Iterable<Object> tuple = Tuples.of("A", "B"); Iterable<String> other = () -> Arrays.asList("A", "B", "C", "D").iterator(); FluxIterable<String> collectionFlux = new FluxIterable<>(collection); FluxIterable<Object> tupleFlux = new FluxIterable<>(tuple); FluxIterable<String> otherFlux = new FluxIterable<>(other); assertThat(collectionFlux.scan(Scannable.Attr.BUFFERED)).as("collection").isEqualTo(3); assertThat(tupleFlux.scan(Scannable.Attr.BUFFERED)).as("tuple").isEqualTo(2); assertThat(otherFlux.scan(Scannable.Attr.BUFFERED)).as("other").isEqualTo(0); }
Example 17
Source File: BaseWalletServiceTest.java From Hands-On-Reactive-Programming-in-Spring-5 with MIT License | 4 votes |
Tuple2<Long, Long> simulateOperations(WalletService walletService) { int accounts = 500; int defaultBalance = 1000; int iterations = 10000; int parallelism = 200; // given // Clean up just in case walletService.removeAllClients() .block(); List<String> clients = walletService.generateClients(accounts, defaultBalance) .doOnNext(name -> log.info("Created wallet for: {}", name)) .collectList() .block(); // when Scheduler mongoScheduler = Schedulers .newParallel("MongoOperations", parallelism); Instant startTime = now(); OperationalSimulation simulation = OperationalSimulation.builder() .walletService(walletService) .clients(clients) .defaultBalance(defaultBalance) .iterations(iterations) .simulationScheduler(mongoScheduler) .build(); OperationStats operations = simulation .runSimulation() .block(); // then log.info("--- Results --------------------------------"); WalletService.Statistics statistics = walletService.reportAllWallets() .block(); log.info("Expected/actual total balance: {}$ / {}$ | Took: {}", accounts * defaultBalance, statistics.getTotalBalance(), between(startTime, now())); log.info("{}", statistics); log.info("{}", operations); log.info("Cleaning up database"); walletService.removeAllClients() .block(); return Tuples.of((long) accounts * defaultBalance, statistics.getTotalBalance()); }
Example 18
Source File: R2dbcAppDetailRepository.java From cf-butler with Apache License 2.0 | 4 votes |
private Tuple2<AppDetail, ApplicationPolicy> toTuple(AppDetail detail, ApplicationPolicy policy) { return Tuples.of(detail, policy); }
Example 19
Source File: ApplicationsController.java From Moss with Apache License 2.0 | 4 votes |
protected Tuple2<String, Flux<Instance>> getApplicationForInstance(Instance instance) { String name = instance.getRegistration().getName(); return Tuples.of(name, registry.getInstances(name).filter(Instance::isRegistered)); }
Example 20
Source File: R2dbcServiceInstanceDetailRepository.java From cf-butler with Apache License 2.0 | 4 votes |
private Tuple2<ServiceInstanceDetail, ServiceInstancePolicy> toTuple(ServiceInstanceDetail detail, ServiceInstancePolicy policy) { return Tuples.of(detail, policy); }