reactor.util.function.Tuple3 Java Examples

The following examples show how to use reactor.util.function.Tuple3. 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: AbstractWebSocketIntegrationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Parameters(name = "client[{0}] - server [{1}]")
public static Object[][] arguments() throws IOException {

	WebSocketClient[] clients = new WebSocketClient[] {
			new TomcatWebSocketClient(),
			new JettyWebSocketClient(),
			new ReactorNettyWebSocketClient(),
			new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY))
	};

	Map<HttpServer, Class<?>> servers = new LinkedHashMap<>();
	servers.put(new TomcatHttpServer(TMP_DIR.getAbsolutePath(), WsContextListener.class), TomcatConfig.class);
	servers.put(new JettyHttpServer(), JettyConfig.class);
	servers.put(new ReactorHttpServer(), ReactorNettyConfig.class);
	servers.put(new UndertowHttpServer(), UndertowConfig.class);

	Flux<WebSocketClient> f1 = Flux.fromArray(clients).concatMap(c -> Flux.just(c).repeat(servers.size()));
	Flux<HttpServer> f2 = Flux.fromIterable(servers.keySet()).repeat(clients.length);
	Flux<Class<?>> f3 = Flux.fromIterable(servers.values()).repeat(clients.length);

	return Flux.zip(f1, f2, f3).map(Tuple3::toArray).collectList().block()
			.toArray(new Object[clients.length * servers.size()][2]);
}
 
Example #2
Source File: AbstractWebSocketIntegrationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Parameters(name = "client[{0}] - server [{1}]")
public static Object[][] arguments() throws IOException {

	WebSocketClient[] clients = new WebSocketClient[] {
			new TomcatWebSocketClient(),
			new JettyWebSocketClient(),
			new ReactorNettyWebSocketClient(),
			new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY))
	};

	Map<HttpServer, Class<?>> servers = new LinkedHashMap<>();
	servers.put(new TomcatHttpServer(TMP_DIR.getAbsolutePath(), WsContextListener.class), TomcatConfig.class);
	servers.put(new JettyHttpServer(), JettyConfig.class);
	servers.put(new ReactorHttpServer(), ReactorNettyConfig.class);
	servers.put(new UndertowHttpServer(), UndertowConfig.class);

	Flux<WebSocketClient> f1 = Flux.fromArray(clients).concatMap(c -> Flux.just(c).repeat(servers.size()));
	Flux<HttpServer> f2 = Flux.fromIterable(servers.keySet()).repeat(clients.length);
	Flux<Class<?>> f3 = Flux.fromIterable(servers.values()).repeat(clients.length);

	return Flux.zip(f1, f2, f3).map(Tuple3::toArray).collectList().block()
			.toArray(new Object[clients.length * servers.size()][2]);
}
 
Example #3
Source File: FluxZipTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void nonPairWisePairWise() {
	Flux<Tuple2<Tuple3<Integer, String, String>, String>> f =
			Flux.zip(Flux.just(1), Flux.just("test"), Flux.just("test0"))
			    .zipWith(Flux.just("test2"));

	Assert.assertTrue(f instanceof FluxZip);
	FluxZip<?, ?> s = (FluxZip<?, ?>) f;
	Assert.assertTrue(s.sources != null);
	Assert.assertTrue(s.sources.length == 2);

	Flux<Tuple2<Integer, String>> ff = f.map(t -> Tuples.of(t.getT1()
	                                                         .getT1(),
			t.getT1()
			 .getT2() + t.getT2()));

	ff.subscribeWith(AssertSubscriber.create())
	  .assertValues(Tuples.of(1, "testtest2"))
	  .assertComplete();
}
 
Example #4
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiOutputAsTuplePojoInInputByteArrayInputTypePojoMessage() {
	FunctionCatalog catalog = this.configureCatalog();
	Function<Flux<Message<byte[]>>, Tuple3<Flux<Person>, Flux<String>, Flux<Integer>>> multiOutputFunction =
								catalog.lookup("multiOutputAsTupleMessageIn");

	Message<byte[]> uncleSam = MessageBuilder.withPayload("{\"name\":\"Uncle Sam\",\"id\":1}".getBytes(StandardCharsets.UTF_8))
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
			.build();
	Message<byte[]> unclePierre = MessageBuilder.withPayload("{\"name\":\"Oncle Pierre\",\"id\":2}".getBytes(StandardCharsets.UTF_8))
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
			.build();
	Flux<Message<byte[]>> personStream = Flux.just(uncleSam, unclePierre);

	Tuple3<Flux<Person>, Flux<String>, Flux<Integer>> result = multiOutputFunction.apply(personStream);
	result.getT1().subscribe(v -> System.out.println("=> 1: " + v));
	result.getT2().subscribe(v -> System.out.println("=> 2: " + v));
	result.getT3().subscribe(v -> System.out.println("=> 3: " + v));
}
 
Example #5
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiOutputAsTuplePojoInInputByteArray() {
	FunctionCatalog catalog = this.configureCatalog();
	Function<Flux<Message<byte[]>>, Tuple3<Flux<Person>, Flux<String>, Flux<Integer>>> multiOutputFunction =
								catalog.lookup("multiOutputAsTuplePojoIn");

	Message<byte[]> uncleSam = MessageBuilder.withPayload("{\"name\":\"Uncle Sam\",\"id\":1}".getBytes(StandardCharsets.UTF_8))
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
			.build();
	Message<byte[]> unclePierre = MessageBuilder.withPayload("{\"name\":\"Oncle Pierre\",\"id\":2}".getBytes(StandardCharsets.UTF_8))
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
			.build();
	Flux<Message<byte[]>> personStream = Flux.just(uncleSam, unclePierre);

	Tuple3<Flux<Person>, Flux<String>, Flux<Integer>> result = multiOutputFunction.apply(personStream);
	result.getT1().subscribe(v -> System.out.println("=> 1: " + v));
	result.getT2().subscribe(v -> System.out.println("=> 2: " + v));
	result.getT3().subscribe(v -> System.out.println("=> 3: " + v));
}
 
Example #6
Source File: BrokerSupplier.java    From data-highway with Apache License 2.0 5 votes vote down vote up
private LogDir logDir(
    Map<String, Disk> diskByLogDir,
    GroupedFlux<String, Tuple3<String, String, PartitionReplica>> byLogDir,
    List<Topic> ts) {
  Disk disk = diskByLogDir.getOrDefault(byLogDir.key(), new Disk(0L, 0L));
  return new LogDir(byLogDir.key(), disk.getFree(), disk.getTotal(), ts);
}
 
Example #7
Source File: MonoZipTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void whenDelayJustMono3() {
	MonoProcessor<Tuple3<Integer, Integer, Integer>> mp = MonoProcessor.create();
	StepVerifier.create(Mono.zipDelayError(Mono.just(1), Mono.just(2), Mono.just(3))
	                        .subscribeWith(mp))
	            .then(() -> assertThat(mp.isError()).isFalse())
	            .then(() -> assertThat(mp.isSuccess()).isTrue())
	            .then(() -> assertThat(mp.isTerminated()).isTrue())
	            .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3).isTrue())
	            .verifyComplete();
}
 
Example #8
Source File: MonoZipTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void whenMonoJust3() {
	MonoProcessor<Tuple3<Integer, Integer, Integer>> mp = MonoProcessor.create();
	StepVerifier.create(Mono.zip(Mono.just(1), Mono.just(2), Mono.just(3))
	                        .subscribeWith(mp))
	            .then(() -> assertThat(mp.isError()).isFalse())
	            .then(() -> assertThat(mp.isSuccess()).isTrue())
	            .then(() -> assertThat(mp.isTerminated()).isTrue())
	            .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3).isTrue())
	            .verifyComplete();
}
 
Example #9
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Bean
public Function<Tuple3<Flux<String>, Flux<String>, Flux<Integer>>, Tuple2<Flux<Person>, Mono<Long>>> multiToMulti() {
	return tuple -> {
		Flux<String> toStringFlux = tuple.getT1();
		Flux<String> nameFlux = tuple.getT2();
		Flux<Integer> idFlux = tuple.getT3();
		Flux<Person> person = toStringFlux.zipWith(nameFlux)
				.map(t -> t.getT1() + " " + t.getT2())
				.zipWith(idFlux)
				.map(t -> new Person(t.getT1(), t.getT2()));
		return Tuples.of(person, person.count());
	};
}
 
Example #10
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Bean
public Function<Flux<Person>, Tuple3<Flux<Person>, Flux<String>, Flux<Integer>>> multiOutputAsTuplePojoIn() {
	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 #12
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiToMulti() {
	FunctionCatalog catalog = this.configureCatalog();
	Function<Tuple3<Flux<String>, Flux<String>, Flux<Integer>>, Tuple2<Flux<Person>, Mono<Long>>> multiToMulti =
								catalog.lookup("multiToMulti");

	Flux<String> firstFlux = Flux.just("Unlce", "Oncle");
	Flux<String> secondFlux = Flux.just("Sam", "Pierre");
	Flux<Integer> thirdFlux = Flux.just(1, 2);

	Tuple2<Flux<Person>, Mono<Long>> result = multiToMulti.apply(Tuples.of(firstFlux, secondFlux, thirdFlux));
	result.getT1().subscribe(v -> System.out.println("=> 1: " + v));
	result.getT2().subscribe(v -> System.out.println("=> 2: " + v));
}
 
Example #13
Source File: BeanFactoryAwareFunctionRegistryMultiInOutTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiOutputAsTuplePojoInInputTypeMatch() {
	FunctionCatalog catalog = this.configureCatalog();
	Function<Flux<Person>, Tuple3<Flux<Person>, Flux<String>, Flux<Integer>>> multiOutputFunction =
								catalog.lookup("multiOutputAsTuplePojoIn");
	Flux<Person> personStream = Flux.just(new Person("Uncle Sam", 1), new Person("Oncle Pierre", 2));

	Tuple3<Flux<Person>, Flux<String>, Flux<Integer>> result = multiOutputFunction.apply(personStream);
	result.getT1().subscribe(v -> System.out.println("=> 1: " + v));
	result.getT2().subscribe(v -> System.out.println("=> 2: " + v));
	result.getT3().subscribe(v -> System.out.println("=> 3: " + v));
}
 
Example #14
Source File: BeanFactoryAwareFunctionRegistryTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: BeanFactoryAwareFunctionRegistryTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiOutput() {
	FunctionCatalog catalog = this.configureCatalog();
	Function<Flux<Person>, Tuple3<Flux<Person>, Flux<String>, Flux<Integer>>> multiOutputFunction =
								catalog.lookup("multiOutputAsTuple");
	Flux<Person> personStream = Flux.just(new Person("Uncle Sam", 1), new Person("Oncle Pierre", 2));

	Tuple3<Flux<Person>, Flux<String>, Flux<Integer>> result = multiOutputFunction.apply(personStream);

	result.getT1().subscribe(v -> System.out.println("=> 1: " + v));
	result.getT2().subscribe(v -> System.out.println("=> 2: " + v));
	result.getT3().subscribe(v -> System.out.println("=> 3: " + v));
}
 
Example #16
Source File: FunctionTypeConversionHelper.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
Object convertOutputIfNecessary(Object output, MimeType... acceptedOutputTypes) {
	if (ObjectUtils.isEmpty(acceptedOutputTypes)) {
		return output;
	}
	List<Object> convertedResults = new ArrayList<Object>();
	if (output instanceof Tuple2) {
		convertedResults.add(this.doConvert(((Tuple2) output).getT1(), acceptedOutputTypes[0]));
		convertedResults.add(this.doConvert(((Tuple2) output).getT2(), acceptedOutputTypes[1]));
	}
	if (output instanceof Tuple3) {
		convertedResults.add(this.doConvert(((Tuple3) output).getT3(), acceptedOutputTypes[2]));
	}
	if (output instanceof Tuple4) {
		convertedResults.add(this.doConvert(((Tuple4) output).getT4(), acceptedOutputTypes[3]));
	}
	if (output instanceof Tuple5) {
		convertedResults.add(this.doConvert(((Tuple5) output).getT5(), acceptedOutputTypes[4]));
	}
	if (output instanceof Tuple6) {
		convertedResults.add(this.doConvert(((Tuple6) output).getT6(), acceptedOutputTypes[5]));
	}
	if (output instanceof Tuple7) {
		convertedResults.add(this.doConvert(((Tuple7) output).getT7(), acceptedOutputTypes[6]));
	}
	if (output instanceof Tuple8) {
		convertedResults.add(this.doConvert(((Tuple8) output).getT8(), acceptedOutputTypes[7]));
	}

	output = Tuples.fromArray(convertedResults.toArray());

	return output;
}
 
Example #17
Source File: FunctionTypeConversionHelper.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
Object convertInputIfNecessary(Object input) {
	List<Object> convertedResults = new ArrayList<Object>();
	if (input instanceof Tuple2) {
		convertedResults.add(this.doConvert(((Tuple2) input).getT1(), getInputArgumentType(0)));
		convertedResults.add(this.doConvert(((Tuple2) input).getT2(), getInputArgumentType(1)));
	}
	if (input instanceof Tuple3) {
		convertedResults.add(this.doConvert(((Tuple3) input).getT3(), getInputArgumentType(2)));
	}
	if (input instanceof Tuple4) {
		convertedResults.add(this.doConvert(((Tuple4) input).getT4(), getInputArgumentType(3)));
	}
	if (input instanceof Tuple5) {
		convertedResults.add(this.doConvert(((Tuple5) input).getT5(), getInputArgumentType(4)));
	}
	if (input instanceof Tuple6) {
		convertedResults.add(this.doConvert(((Tuple6) input).getT6(), getInputArgumentType(5)));
	}
	if (input instanceof Tuple7) {
		convertedResults.add(this.doConvert(((Tuple7) input).getT7(), getInputArgumentType(6)));
	}
	if (input instanceof Tuple8) {
		convertedResults.add(this.doConvert(((Tuple8) input).getT8(), getInputArgumentType(7)));
	}

	input = CollectionUtils.isEmpty(convertedResults) ? this.doConvert(input, getInputArgumentType(0))
			: Tuples.fromArray(convertedResults.toArray());
	return input;
}
 
Example #18
Source File: BrokerSupplier.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Override
public Broker get() {
  Map<TopicPartition, Replica> replicaByPartition = replicaByPartitionFunction.apply(brokerNode.getId());

  Set<TopicPartition> partitions = replicaByPartition.keySet();
  Set<String> topics = Flux.fromIterable(partitions).map(TopicPartition::topic).collect(toSet()).block();

  Map<TopicPartition, LeaderInSync> leaderInSyncByPartition = leaderInSyncByPartitionFunction
      .apply(brokerNode.getId(), topics);
  Map<String, Duration> retentionByTopic = retentionByTopicFunction.apply(topics);
  Map<TopicPartition, Offsets> offsetsByPartition = offsetsByPartitionFunction.apply(partitions);
  Map<TopicPartition, Long> sizeByPartition = sizeByPartitionFunction.apply(replicaByPartition);
  Map<String, Disk> diskByLogDir = diskByLogDirFunction.apply(replicaByPartition);

  return Flux
      .fromIterable(partitions)
      .map(p -> replica(replicaByPartition, offsetsByPartition, leaderInSyncByPartition, sizeByPartition, p))
      .groupBy(Tuple3::getT1)
      .flatMap(
          byLogDir -> byLogDir
              .sort(comparing(Tuple3::getT2))
              .windowUntil(keyChanged(Tuple3::getT2), true)
              .flatMap(
                  byTopic -> byTopic
                      .collectMultimap(Tuple3::getT2, Tuple3::getT3)
                      .flatMapIterable(Map::entrySet)
                      .map(
                          e -> new Topic(
                              e.getKey(),
                              retentionByTopic.getOrDefault(e.getKey(), ZERO),
                              newArrayList(e.getValue()))))
              .collectList()
              .map(ts -> logDir(diskByLogDir, byLogDir, ts)))
      .collectList()
      .map(lds -> new Broker(brokerNode.getId(), brokerNode.getRack(), lds))
      .block();
}
 
Example #19
Source File: BeanFactoryAwareFunctionRegistryTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
public Function<Flux<Person>, Flux<Tuple3<Person, String, Integer>>> multiOutputAsTuple2() {
	return null;
}
 
Example #20
Source File: FunctionTypeUtilsTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private static Function<Tuple2<Flux<Map<String, Integer>>, Mono<String>>,
		Tuple3<Flux<List<byte[]>>, Flux<String>, Mono<String>>> multiInputOutputPublisherFunctionComplexTypes() {
	return null;
}
 
Example #21
Source File: FunctionTypeUtilsTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private static Function<Tuple2<Flux<String>, Mono<String>>,
		Tuple3<Flux<String>, Flux<String>, Mono<String>>> multiInputOutputPublisherFunction() {
	return null;
}
 
Example #22
Source File: FunctionTypeUtilsTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private static Function<Tuple2<String, String>, Tuple3<String, Integer, String>> multiInputOutputFunction() {
	return null;
}
 
Example #23
Source File: FunctionTypeTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple3<Flux<String>, Flux<Integer>, Flux<Object>> apply(Tuple2<Flux<String>, Flux<Integer>> t) {
	return null;
}
 
Example #24
Source File: EventRetriever.java    From james-project with Apache License 2.0 4 votes vote down vote up
default Flux<Tuple3<Group, Event, EventDeadLetters.InsertionId>> listGroupEvents(EventDeadLetters deadLetters, Group group) {
    return deadLetters.failedIds(group)
        .flatMap(insertionId -> Flux.zip(Mono.just(group), deadLetters.failedEvent(group, insertionId), Mono.just(insertionId)));
}
 
Example #25
Source File: EventRetriever.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<Tuple3<Group, Event, EventDeadLetters.InsertionId>> retrieveEvents(EventDeadLetters deadLetters) {
    return deadLetters.groupsWithFailedEvents()
        .flatMap(group -> listGroupEvents(deadLetters, group));
}
 
Example #26
Source File: EventRetriever.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<Tuple3<Group, Event, EventDeadLetters.InsertionId>> retrieveEvents(EventDeadLetters deadLetters) {
    return listGroupEvents(deadLetters, group);
}
 
Example #27
Source File: EventRetriever.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<Tuple3<Group, Event, EventDeadLetters.InsertionId>> retrieveEvents(EventDeadLetters deadLetters) {
    return Flux.zip(Mono.just(group), deadLetters.failedEvent(group, insertionId), Mono.just(insertionId));
}
 
Example #28
Source File: EventRetriever.java    From james-project with Apache License 2.0 votes vote down vote up
Flux<Tuple3<Group, Event, EventDeadLetters.InsertionId>> retrieveEvents(EventDeadLetters deadLetters);