Java Code Examples for reactor.core.publisher.Flux#fromArray()
The following examples show how to use
reactor.core.publisher.Flux#fromArray() .
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: ReactiveAdapterDefault.java From alibaba-rsocket-broker with 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 File: FirestoreRepositoryIntegrationTests.java From spring-cloud-gcp with 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 3
Source File: ReactorFromOtherPublisher.java From Spring-5.0-Projects with 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 4
Source File: ReactiveDummyServiceImpl.java From resilience4j with 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 5
Source File: FirestoreRepositoryIntegrationTests.java From spring-cloud-gcp with 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 6
Source File: FirestoreRepositoryIntegrationTests.java From spring-cloud-gcp with 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 7
Source File: FirestoreIntegrationTests.java From spring-cloud-gcp with 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 8
Source File: BenchmarkReactorServerServiceImpl.java From reactive-grpc with 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 File: ExampleTests.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@Test public void data2() { // tag::2[] String[] items = new String[]{"alpha", "bravo", "charlie"}; Flux.fromArray(items); // end::2[] }
Example 10
Source File: ExampleTests.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@Test public void data2() { // tag::2[] String[] items = new String[]{"alpha", "bravo", "charlie"}; Flux.fromArray(items); // end::2[] }
Example 11
Source File: ReactiveRetryDummyServiceImpl.java From resilience4j with 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 12
Source File: ReactorEssentialsTest.java From Hands-On-Reactive-Programming-in-Spring-5 with 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 13
Source File: ClobCodecTest.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Override public Flux<CharSequence> stream() { return Flux.fromArray(values); }
Example 14
Source File: PrefixTests.java From spring-cloud-function with Apache License 2.0 | 4 votes |
@Bean({ "words", "get/more" }) public Supplier<Flux<String>> words() { return () -> Flux.fromArray(new String[] { "foo", "bar" }); }
Example 15
Source File: PrefixTests.java From spring-cloud-function with 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 File: FluxRestApplicationTests.java From spring-cloud-function with Apache License 2.0 | 4 votes |
@GetMapping({ "/words", "/get/more" }) public Flux<Object> words() { return Flux.fromArray(new String[] { "foo", "bar" }); }
Example 17
Source File: MvcRestApplicationTests.java From spring-cloud-function with Apache License 2.0 | 4 votes |
@GetMapping({ "/words", "/get/more" }) public Flux<Object> words() { return Flux.fromArray(new String[] { "foo", "bar" }); }
Example 18
Source File: SampleApplication.java From spring-cloud-function with Apache License 2.0 | 4 votes |
@Bean public Supplier<Flux<String>> words() { return () -> Flux.fromArray(new String[] {"foo", "bar"}); }
Example 19
Source File: ClobCodecTest.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Override public Flux<CharSequence> stream() { return Flux.fromArray(values); }
Example 20
Source File: ItemResource.java From spring-auto-restdocs with 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}); }