@Override @Nullable public T get(long timeout, TimeUnit unit) { Assert.notNull(unit, "TimeUnit must not be null"); Duration duration = Duration.ofMillis(TimeUnit.MILLISECONDS.convert(timeout, unit)); return this.processor.block(duration); }
private <T> Function<Flux<T>, Publisher<?>> reconnectFunction(ReconnectStrategy reconnectStrategy) { return flux -> flux .scan(1, (count, element) -> count++) .flatMap(attempt -> Optional.ofNullable(reconnectStrategy.getTimeToNextAttempt(attempt)) .map(time -> Mono.delay(Duration.ofMillis(time), this.scheduler)) .orElse(Mono.empty())); }
@GetMapping("/stream") public Publisher<Long> stream() { return testInterval(Duration.ofMillis(50), 5); } }
@GetMapping(value = "/stream", produces = { APPLICATION_STREAM_JSON_VALUE, "application/stream+x-jackson-smile" }) Flux<Person> person() { return testInterval(Duration.ofMillis(100), 50).map(l -> new Person("foo " + l)); }
@Test public void rxObservableToPublisher() { List<Integer> sequence = Arrays.asList(1, 2, 3); Object source = rx.Observable.from(sequence); Object target = getAdapter(rx.Observable.class).toPublisher(source); assertTrue("Expected Flux Publisher: " + target.getClass().getName(), target instanceof Flux); assertEquals(sequence, ((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))); }
@Test public void reactivexCompletableToPublisher() { Object source = io.reactivex.Completable.complete(); Object target = getAdapter(io.reactivex.Completable.class).toPublisher(source); assertTrue("Expected Mono Publisher: " + target.getClass().getName(), target instanceof Mono); ((Mono<Void>) target).block(Duration.ofMillis(1000)); }
@Test public void rxSingleToPublisher() { Object source = rx.Single.just(1); Object target = getAdapter(rx.Single.class).toPublisher(source); assertTrue("Expected Mono Publisher: " + target.getClass().getName(), target instanceof Mono); assertEquals(Integer.valueOf(1), ((Mono<Integer>) target).block(Duration.ofMillis(1000))); }
@Test public void testFieldPrefixCausesFieldReset() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("_postProcessed", "visible"); formData.add("postProcessed", "on"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertTrue(this.testBean.isPostProcessed()); formData.remove("postProcessed"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertFalse(this.testBean.isPostProcessed()); }
@Test public void testFieldDefault() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("!postProcessed", "off"); formData.add("postProcessed", "on"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertTrue(this.testBean.isPostProcessed()); formData.remove("postProcessed"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertFalse(this.testBean.isPostProcessed()); }
@GwtIncompatible public void testElapsed_duration() { stopwatch.start(); ticker.advance(999999); assertEquals(Duration.ofNanos(999999), stopwatch.elapsed()); ticker.advance(1); assertEquals(Duration.ofMillis(1), stopwatch.elapsed()); }
@Test public void reactivexFlowableToPublisher() { List<Integer> sequence = Arrays.asList(1, 2, 3); Object source = io.reactivex.Flowable.fromIterable(sequence); Object target = getAdapter(io.reactivex.Flowable.class).toPublisher(source); assertTrue("Expected Flux Publisher: " + target.getClass().getName(), target instanceof Flux); assertEquals(sequence, ((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))); }
@Test public void resolveWithMonoOnBindingResultAndModelAttribute() { this.expectedException.expectMessage("An @ModelAttribute and an Errors/BindingResult argument " + "cannot both be declared with an async type wrapper."); MethodParameter parameter = this.testMethod.arg(BindingResult.class); this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange) .block(Duration.ofMillis(5000)); }
@Test public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception { this.binder.setIgnoreUnknownFields(false); MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("_postProcessed", "visible"); formData.add("postProcessed", "on"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertTrue(this.testBean.isPostProcessed()); formData.remove("postProcessed"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertFalse(this.testBean.isPostProcessed()); }
@Test public void testBindingWithNestedObjectCreation() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("spouse", "someValue"); formData.add("spouse.name", "test"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertNotNull(this.testBean.getSpouse()); assertEquals("test", testBean.getSpouse().getName()); }
@Test public void testBindingWithNestedObjectCreationAndWrongOrder() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("spouse.name", "test"); formData.add("spouse", "someValue"); this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000)); assertNotNull(this.testBean.getSpouse()); assertEquals("test", this.testBean.getSpouse().getName()); }
@Test public void publisherToMono() { Publisher<Integer> source = Flowable.fromArray(1, 2, 3); Object target = getAdapter(Mono.class).fromPublisher(source); assertTrue(target instanceof Mono); assertEquals(Integer.valueOf(1), ((Mono<Integer>) target).block(Duration.ofMillis(1000))); }
@Test // SPR-15074 public void orderedWebExceptionHandlerBeans() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(OrderedExceptionHandlerBeanConfig.class); context.refresh(); HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build(); MockServerHttpRequest request = MockServerHttpRequest.get("/").build(); MockServerHttpResponse response = new MockServerHttpResponse(); httpHandler.handle(request, response).block(ofMillis(5000)); assertEquals("ExceptionHandlerB", response.getBodyAsString().block(ofMillis(5000))); }
@GetMapping(value = "/message-stream", produces = "application/x-protobuf;delimited=true") Flux<Msg> messageStream() { return testInterval(Duration.ofMillis(50), 5).map(l -> Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(l.intValue()).build()).build()); }
@Test public void publisherToFlux() { List<Integer> sequence = Arrays.asList(1, 2, 3); Publisher<Integer> source = Flowable.fromIterable(sequence); Object target = getAdapter(Flux.class).fromPublisher(source); assertTrue(target instanceof Flux); assertEquals(sequence, ((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))); }
@Test public void resolveResourceNoVersionStrategy() { String file = "missing.css"; given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.empty()); this.resolver.setStrategyMap(Collections.emptyMap()); Resource actual = this.resolver .resolveResourceInternal(null, file, this.locations, this.chain) .block(Duration.ofMillis(5000)); assertNull(actual); verify(this.chain, times(1)).resolveResource(null, file, this.locations); }