Java Code Examples for reactor.core.publisher.Flux#fromArray()
The following examples show how to use
reactor.core.publisher.Flux#fromArray() .
These examples are extracted from open source projects.
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 Project: alibaba-rsocket-broker File: ReactiveAdapterDefault.java License: Apache License 2.0 | 6 votes |
@Override public <T> Flux<T> toFlux(@Nullable Object source) { if (source instanceof Flux) { return (Flux) source; } else if (source instanceof Iterable) { return Flux.fromIterable((Iterable) source); } else if (source instanceof Stream) { return Flux.fromStream((Stream) source); } else if (source instanceof Publisher) { return Flux.from((Publisher) source); } else if (source == null) { return Flux.empty(); } else if (source.getClass().isArray()) { return Flux.fromArray((T[]) source); } return (Flux<T>) Flux.just(source); }
Example 2
Source Project: Spring-5.0-Projects File: ReactorFromOtherPublisher.java License: MIT License | 6 votes |
public static void main(String[] args) { Flux<String> fewWords = Flux.just("One","Two"); /* from array */ Flux<Integer> intFlux = Flux.fromArray(new Integer[]{1,2,3,4,5,6,7}); /* from Java 8 stream */ Flux<String> strFlux = Flux.fromStream(Stream.of( "Ten", "Hundred", "Thousand", "Ten Thousands", "Lac","Ten Lac", "Crore")); /* from other Publisher */ Flux<String> fromOtherPublisherFlux = Flux.from(fewWords); intFlux.subscribe(System.out::println); strFlux.subscribe(System.out::println); fromOtherPublisherFlux.subscribe(System.out::println); }
Example 3
Source Project: spring-cloud-gcp File: FirestoreRepositoryIntegrationTests.java License: Apache License 2.0 | 6 votes |
@Test //tag::repository_part_tree[] public void partTreeRepositoryMethodTest() { User u1 = new User("Cloud", 22, null, null, new Address("1 First st., NYC", "USA")); u1.favoriteDrink = "tea"; User u2 = new User("Squall", 17, null, null, new Address("2 Second st., London", "UK")); u2.favoriteDrink = "wine"; Flux<User> users = Flux.fromArray(new User[] {u1, u2}); this.userRepository.saveAll(users).blockLast(); assertThat(this.userRepository.count().block()).isEqualTo(2); assertThat(this.userRepository.findByAge(22).collectList().block()).containsExactly(u1); assertThat(this.userRepository.findByHomeAddressCountry("USA").collectList().block()).containsExactly(u1); assertThat(this.userRepository.findByFavoriteDrink("wine").collectList().block()).containsExactly(u2); assertThat(this.userRepository.findByAgeGreaterThanAndAgeLessThan(20, 30).collectList().block()) .containsExactly(u1); assertThat(this.userRepository.findByAgeGreaterThan(10).collectList().block()).containsExactlyInAnyOrder(u1, u2); }
Example 4
Source Project: Hands-On-Reactive-Programming-in-Spring-5 File: ReactorEssentialsTest.java License: MIT License | 5 votes |
@Test public void createFlux() { Flux<String> stream1 = Flux.just("Hello", "world"); Flux<Integer> stream2 = Flux.fromArray(new Integer[]{1, 2, 3}); Flux<Integer> stream3 = Flux.range(1, 500); Flux<String> emptyStream = Flux.empty(); Flux<String> streamWithError = Flux.error(new RuntimeException("Hi!")); }
Example 5
Source Project: resilience4j File: ReactiveRetryDummyServiceImpl.java License: Apache License 2.0 | 5 votes |
@Override public Flux<String> doSomethingFlux(boolean throwException) { if (throwException) { return Flux.error(new IllegalArgumentException("FailedFlux")); } return Flux.fromArray(Arrays.array("test", "test2")); }
Example 6
Source Project: Learning-Spring-Boot-2.0-Second-Edition File: ExampleTests.java License: MIT License | 5 votes |
@Test public void data2() { // tag::2[] String[] items = new String[]{"alpha", "bravo", "charlie"}; Flux.fromArray(items); // end::2[] }
Example 7
Source Project: Learning-Spring-Boot-2.0-Second-Edition File: ExampleTests.java License: MIT License | 5 votes |
@Test public void data2() { // tag::2[] String[] items = new String[]{"alpha", "bravo", "charlie"}; Flux.fromArray(items); // end::2[] }
Example 8
Source Project: reactive-grpc File: BenchmarkReactorServerServiceImpl.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public BenchmarkReactorServerServiceImpl(int times) { Messages.SimpleResponse[] array = new Messages.SimpleResponse[times]; Arrays.fill(array, Messages.SimpleResponse.getDefaultInstance()); this.responseFlux = Flux.fromArray(array); this.responseMono = Mono.just(Messages.SimpleResponse.getDefaultInstance()); }
Example 9
Source Project: spring-cloud-gcp File: FirestoreIntegrationTests.java License: Apache License 2.0 | 5 votes |
@Test public void saveAllTest() { User u1 = new User("Cloud", 22); User u2 = new User("Squall", 17); Flux<User> users = Flux.fromArray(new User[]{u1, u2}); assertThat(this.firestoreTemplate.count(User.class).block()).isEqualTo(0); this.firestoreTemplate.saveAll(users).blockLast(); assertThat(this.firestoreTemplate.count(User.class).block()).isEqualTo(2); assertThat(this.firestoreTemplate.deleteAll(User.class).block()).isEqualTo(2); }
Example 10
Source Project: spring-cloud-gcp File: FirestoreRepositoryIntegrationTests.java License: Apache License 2.0 | 5 votes |
@Test public void inFilterQueryTest() { User u1 = new User("Cloud", 22); User u2 = new User("Squall", 17); Flux<User> users = Flux.fromArray(new User[] {u1, u2}); this.userRepository.saveAll(users).blockLast(); List<String> pagedUsers = this.userRepository.findByAgeIn(Arrays.asList(22, 23, 24)) .map(User::getName) .collectList() .block(); assertThat(pagedUsers).containsExactly("Cloud"); pagedUsers = this.userRepository.findByAgeIn(Arrays.asList(17, 22)) .map(User::getName) .collectList() .block(); assertThat(pagedUsers).containsExactly("Cloud", "Squall"); pagedUsers = this.userRepository.findByAgeIn(Arrays.asList(18, 23)) .map(User::getName) .collectList() .block(); assertThat(pagedUsers).isEmpty(); }
Example 11
Source Project: spring-cloud-gcp File: FirestoreRepositoryIntegrationTests.java License: Apache License 2.0 | 5 votes |
@Test public void containsFilterQueryTest() { User u1 = new User("Cloud", 22, Arrays.asList("cat", "dog")); User u2 = new User("Squall", 17, Collections.singletonList("pony")); Flux<User> users = Flux.fromArray(new User[] {u1, u2}); this.userRepository.saveAll(users).blockLast(); List<String> pagedUsers = this.userRepository.findByPetsContains(Arrays.asList("cat", "dog")) .map(User::getName) .collectList() .block(); assertThat(pagedUsers).containsExactly("Cloud"); pagedUsers = this.userRepository.findByPetsContains(Arrays.asList("cat", "pony")) .map(User::getName) .collectList() .block(); assertThat(pagedUsers).containsExactlyInAnyOrder("Cloud", "Squall"); pagedUsers = this.userRepository.findByAgeAndPetsContains(17, Arrays.asList("cat", "pony")) .map(User::getName) .collectList() .block(); assertThat(pagedUsers).containsExactlyInAnyOrder("Squall"); pagedUsers = this.userRepository.findByPetsContainsAndAgeIn("cat", Arrays.asList(22, 23)) .map(User::getName) .collectList() .block(); assertThat(pagedUsers).containsExactlyInAnyOrder("Cloud"); }
Example 12
Source Project: resilience4j File: ReactiveDummyServiceImpl.java License: Apache License 2.0 | 5 votes |
@Override public Flux<String> doSomethingFlux(boolean throwException) throws IOException { if (throwException) { return Flux.error(new IllegalArgumentException("FailedFlux")); } return Flux.fromArray(Arrays.array("test", "test2")); }
Example 13
Source Project: r2dbc-mysql File: ClobCodecTest.java License: Apache License 2.0 | 4 votes |
@Override public Flux<CharSequence> stream() { return Flux.fromArray(values); }
Example 14
Source Project: r2dbc-mysql File: ClobCodecTest.java License: Apache License 2.0 | 4 votes |
@Override public Flux<CharSequence> stream() { return Flux.fromArray(values); }
Example 15
Source Project: spring-cloud-function File: PrefixTests.java License: Apache License 2.0 | 4 votes |
@Bean({ "words", "get/more" }) public Supplier<Flux<String>> words() { return () -> Flux.fromArray(new String[] { "foo", "bar" }); }
Example 16
Source Project: spring-cloud-function File: PrefixTests.java License: Apache License 2.0 | 4 votes |
@Bean({ "words", "get/more" }) public Supplier<Flux<String>> words() { return () -> Flux.fromArray(new String[] { "foo", "bar" }); }
Example 17
Source Project: spring-cloud-function File: FluxRestApplicationTests.java License: Apache License 2.0 | 4 votes |
@GetMapping({ "/words", "/get/more" }) public Flux<Object> words() { return Flux.fromArray(new String[] { "foo", "bar" }); }
Example 18
Source Project: spring-cloud-function File: MvcRestApplicationTests.java License: Apache License 2.0 | 4 votes |
@GetMapping({ "/words", "/get/more" }) public Flux<Object> words() { return Flux.fromArray(new String[] { "foo", "bar" }); }
Example 19
Source Project: spring-cloud-function File: SampleApplication.java License: Apache License 2.0 | 4 votes |
@Bean public Supplier<Flux<String>> words() { return () -> Flux.fromArray(new String[] {"foo", "bar"}); }
Example 20
Source Project: spring-auto-restdocs File: ItemResource.java License: Apache License 2.0 | 2 votes |
/** * Lists all items. * <p> * An example of retuning a collection using Flux. * * @return list of all items */ @GetMapping public Flux<ItemResponse> allItems() { return Flux.fromArray(new ItemResponse[]{ITEM, CHILD}); }