Java Code Examples for reactor.test.StepVerifier#FirstStep

The following examples show how to use reactor.test.StepVerifier#FirstStep . 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: Jackson2TokenizerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void testTokenize(List<String> source, List<String> expected, boolean tokenizeArrayElements) {
	Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(
			Flux.fromIterable(source).map(this::stringBuffer),
			this.jsonFactory, this.objectMapper, tokenizeArrayElements);

	Flux<String> result = tokens
			.map(tokenBuffer -> {
				try {
					TreeNode root = this.objectMapper.readTree(tokenBuffer.asParser());
					return this.objectMapper.writeValueAsString(root);
				}
				catch (IOException ex) {
					throw new UncheckedIOException(ex);
				}
			});

	StepVerifier.FirstStep<String> builder = StepVerifier.create(result);
	expected.forEach(s -> builder.assertNext(new JSONAssertConsumer(s)));
	builder.verifyComplete();
}
 
Example 2
Source File: AbstractEncoderTestCase.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Test a standard {@link Encoder#encode encode} scenario.
 *
 * @param input the input to be provided to the encoder
 * @param inputType the input type
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 * @param <T> the output type
 */
@SuppressWarnings("unchecked")
protected <T> void testEncode(Publisher<? extends T> input, ResolvableType inputType,
		Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	Flux<DataBuffer> result = encoder().encode(input, this.bufferFactory, inputType,
			mimeType, hints);
	StepVerifier.FirstStep<DataBuffer> step = StepVerifier.create(result);
	stepConsumer.accept(step);
}
 
Example 3
Source File: AbstractEncoderTestCase.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Test a standard {@link Encoder#encode encode} scenario.
 *
 * @param input the input to be provided to the encoder
 * @param inputType the input type
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 * @param <T> the output type
 */
@SuppressWarnings("unchecked")
protected <T> void testEncode(Publisher<? extends T> input, ResolvableType inputType,
		Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	Flux<DataBuffer> result = encoder().encode(input, this.bufferFactory, inputType,
			mimeType, hints);
	StepVerifier.FirstStep<DataBuffer> step = StepVerifier.create(result);
	stepConsumer.accept(step);
}
 
Example 4
Source File: IntegrationTestSupport.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
private StepVerifier.FirstStep<Void> process(Function<? super MySqlConnection, Publisher<?>> runner) {
    return create()
        .flatMap(connection -> Flux.from(runner.apply(connection))
            .onErrorResume(e -> connection.close().then(Mono.error(e)))
            .concatWith(connection.close().then(Mono.empty()))
            .then())
        .as(StepVerifier::create);
}
 
Example 5
Source File: IntegrationTestSupport.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
private StepVerifier.FirstStep<Void> process(Function<? super MySqlConnection, Publisher<?>> runner) {
    return create()
        .flatMap(connection -> Flux.from(runner.apply(connection))
            .onErrorResume(e -> connection.close().then(Mono.error(e)))
            .concatWith(connection.close().then(Mono.empty()))
            .then())
        .as(StepVerifier::create);
}
 
Example 6
Source File: GrpcAgentReplicatorEventStreamTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private StepVerifier.FirstStep<ReplicatorEvent<AgentSnapshot, AgentEvent>> newConnectVerifier() {
    return StepVerifier.withVirtualTime(() -> newStream().connect().log());
}
 
Example 7
Source File: GrpcRelocationReplicatorEventStreamTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private StepVerifier.FirstStep<ReplicatorEvent<TaskRelocationSnapshot, TaskRelocationEvent>> newConnectVerifier() {
    return StepVerifier.withVirtualTime(() -> newStream().connect().log());
}
 
Example 8
Source File: GrpcEvictionReplicatorEventStreamTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private StepVerifier.FirstStep<ReplicatorEvent<EvictionDataSnapshot, EvictionEvent>> newConnectVerifier() {
    return StepVerifier.withVirtualTime(() -> newStream().connect().log());
}
 
Example 9
Source File: GrpcJobReplicatorEventStreamTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private StepVerifier.FirstStep<ReplicatorEvent<JobSnapshot, JobManagerEvent<?>>> newConnectVerifier() {
    return StepVerifier.withVirtualTime(() -> newStream().connect().log());
}
 
Example 10
Source File: RetryableReplicatorEventStreamTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private StepVerifier.FirstStep<ReplicatorEvent<String, String>> newConnectVerifier() {
    return StepVerifier.withVirtualTime(() -> newStream().connect().log());
}
 
Example 11
Source File: AbstractDecoderTestCase.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Helper methods that tests for a variety of {@link Flux} decoding scenarios. This methods
 * invokes:
 * <ul>
 *     <li>{@link #testDecode(Publisher, ResolvableType, Consumer, MimeType, Map)}</li>
 *     <li>{@link #testDecodeError(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeEmpty(ResolvableType, MimeType, Map)}</li>
 * </ul>
 *
 * @param input the input to be provided to the decoder
 * @param outputType the desired output type
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 * @param <T> the output type
 */
protected <T> void testDecodeAll(Publisher<DataBuffer> input, ResolvableType outputType,
		Consumer<StepVerifier.FirstStep<T>> stepConsumer,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
	testDecode(input, outputType, stepConsumer, mimeType, hints);
	testDecodeError(input, outputType, mimeType, hints);
	testDecodeCancel(input, outputType, mimeType, hints);
	testDecodeEmpty(outputType, mimeType, hints);
}
 
Example 12
Source File: AbstractEncoderTestCase.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Helper methods that tests for a variety of decoding scenarios. This methods
 * invokes:
 * <ul>
 *     <li>{@link #testEncode(Publisher, ResolvableType, Consumer, MimeType, Map)}</li>
 *     <li>{@link #testEncodeError(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testEncodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testEncodeEmpty(ResolvableType, MimeType, Map)}</li>
 * </ul>
 *
 * @param input the input to be provided to the encoder
 * @param inputType the input type
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 * @param <T> the output type
 */
protected <T> void testEncodeAll(Publisher<? extends T> input, ResolvableType inputType,
		Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
	testEncode(input, inputType, stepConsumer, mimeType, hints);
	testEncodeError(input, inputType, mimeType, hints);
	testEncodeCancel(input, inputType, mimeType, hints);
	testEncodeEmpty(inputType, mimeType, hints);
}
 
Example 13
Source File: AbstractDecoderTestCase.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Test a standard {@link Decoder#decodeToMono decode} scenario. For example:
 * <pre class="code">
 * byte[] bytes1 = ...
 * byte[] bytes2 = ...
 * byte[] allBytes = ... // bytes1 + bytes2
 *
 * Flux&lt;DataBuffer&gt; input = Flux.concat(
 *   dataBuffer(bytes1),
 *   dataBuffer(bytes2));
 *
 * testDecodeAll(input, byte[].class, step -&gt; step
 *   .consumeNextWith(expectBytes(allBytes))
 * 	 .verifyComplete());
 * </pre>
 *
 * @param input the input to be provided to the decoder
 * @param outputType the desired output type
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 * @param <T> the output type
 */
@SuppressWarnings("unchecked")
protected <T> void testDecodeToMono(Publisher<DataBuffer> input, ResolvableType outputType,
		Consumer<StepVerifier.FirstStep<T>> stepConsumer,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	Mono<T> result = (Mono<T>) this.decoder.decodeToMono(input, outputType, mimeType, hints);
	StepVerifier.FirstStep<T> step = StepVerifier.create(result);
	stepConsumer.accept(step);
}
 
Example 14
Source File: AbstractDecoderTestCase.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Helper methods that tests for a variety of {@link Flux} decoding scenarios. This methods
 * invokes:
 * <ul>
 *     <li>{@link #testDecode(Publisher, ResolvableType, Consumer, MimeType, Map)}</li>
 *     <li>{@link #testDecodeError(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeEmpty(ResolvableType, MimeType, Map)}</li>
 * </ul>
 *
 * @param input the input to be provided to the decoder
 * @param outputType the desired output type
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 * @param <T> the output type
 */
protected <T> void testDecodeAll(Publisher<DataBuffer> input, ResolvableType outputType,
		Consumer<StepVerifier.FirstStep<T>> stepConsumer,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	testDecode(input, outputType, stepConsumer, mimeType, hints);
	testDecodeError(input, outputType, mimeType, hints);
	testDecodeCancel(input, outputType, mimeType, hints);
	testDecodeEmpty(outputType, mimeType, hints);
}
 
Example 15
Source File: AbstractDecoderTestCase.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Test a standard {@link Decoder#decode decode} scenario. For example:
 * <pre class="code">
 * byte[] bytes1 = ...
 * byte[] bytes2 = ...
 *
 * Flux&lt;DataBuffer&gt; input = Flux.concat(
 *   dataBuffer(bytes1),
 *   dataBuffer(bytes2));
 *
 * testDecodeAll(input, byte[].class, step -&gt; step
 *   .consumeNextWith(expectBytes(bytes1))
 *   .consumeNextWith(expectBytes(bytes2))
 * 	 .verifyComplete());
 * </pre>
 *
 * @param input the input to be provided to the decoder
 * @param outputType the desired output type
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 * @param <T> the output type
 */
@SuppressWarnings("unchecked")
protected <T> void testDecode(Publisher<DataBuffer> input, ResolvableType outputType,
		Consumer<StepVerifier.FirstStep<T>> stepConsumer,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	Flux<T> result = (Flux<T>) this.decoder.decode(input, outputType, mimeType, hints);
	StepVerifier.FirstStep<T> step = StepVerifier.create(result);
	stepConsumer.accept(step);
}
 
Example 16
Source File: AbstractDecoderTestCase.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Test a standard {@link Decoder#decodeToMono decode} scenario. For example:
 * <pre class="code">
 * byte[] bytes1 = ...
 * byte[] bytes2 = ...
 * byte[] allBytes = ... // bytes1 + bytes2
 *
 * Flux&lt;DataBuffer&gt; input = Flux.concat(
 *   dataBuffer(bytes1),
 *   dataBuffer(bytes2));
 *
 * testDecodeAll(input, byte[].class, step -&gt; step
 *   .consumeNextWith(expectBytes(allBytes))
 * 	 .verifyComplete());
 * </pre>
 *
 * @param input the input to be provided to the decoder
 * @param outputClass the desired output class
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param <T> the output type
 */
protected <T> void testDecodeToMono(Publisher<DataBuffer> input,
		Class<? extends T> outputClass, Consumer<StepVerifier.FirstStep<T>> stepConsumer) {

	testDecodeToMono(input, ResolvableType.forClass(outputClass), stepConsumer, null, null);
}
 
Example 17
Source File: AbstractDecoderTestCase.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Test a standard {@link Decoder#decodeToMono) decode} scenario. For example:
 * <pre class="code">
 * byte[] bytes1 = ...
 * byte[] bytes2 = ...
 * byte[] allBytes = ... // bytes1 + bytes2
 *
 * Flux&lt;DataBuffer&gt; input = Flux.concat(
 *   dataBuffer(bytes1),
 *   dataBuffer(bytes2));
 *
 * testDecodeAll(input, byte[].class, step -&gt; step
 *   .consumeNextWith(expectBytes(allBytes))
 * 	 .verifyComplete());
 * </pre>
 *
 * @param input the input to be provided to the decoder
 * @param outputClass the desired output class
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param <T> the output type
 */
protected <T> void testDecodeToMono(Publisher<DataBuffer> input,
		Class<? extends T> outputClass, Consumer<StepVerifier.FirstStep<T>> stepConsumer) {
	testDecodeToMono(input, ResolvableType.forClass(outputClass), stepConsumer, null, null);
}
 
Example 18
Source File: AbstractDecoderTestCase.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Helper methods that tests for a variety of {@link Mono} decoding scenarios. This methods
 * invokes:
 * <ul>
 *     <li>{@link #testDecodeToMono(Publisher, ResolvableType, Consumer, MimeType, Map)}</li>
 *     <li>{@link #testDecodeToMonoError(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeToMonoCancel(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeToMonoEmpty(ResolvableType, MimeType, Map)}</li>
 * </ul>
 *
 * @param input the input to be provided to the decoder
 * @param outputClass the desired output class
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param <T> the output type
 */
protected <T> void testDecodeToMonoAll(Publisher<DataBuffer> input,
		Class<? extends T> outputClass, Consumer<StepVerifier.FirstStep<T>> stepConsumer) {

	testDecodeToMonoAll(input, ResolvableType.forClass(outputClass), stepConsumer, null, null);
}
 
Example 19
Source File: AbstractEncoderTestCase.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Test a standard {@link Encoder#encode encode} scenario.
 *
 * @param input the input to be provided to the encoder
 * @param inputClass the input class
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param <T> the output type
 */
protected <T> void testEncode(Publisher<? extends T> input, Class<? extends T> inputClass,
		Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer) {
	testEncode(input, ResolvableType.forClass(inputClass), stepConsumer, null, null);
}
 
Example 20
Source File: AbstractDecoderTestCase.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Helper methods that tests for a variety of {@link Flux} decoding scenarios. This methods
 * invokes:
 * <ul>
 *     <li>{@link #testDecode(Publisher, ResolvableType, Consumer, MimeType, Map)}</li>
 *     <li>{@link #testDecodeError(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
 *     <li>{@link #testDecodeEmpty(ResolvableType, MimeType, Map)}</li>
 * </ul>
 *
 * @param input the input to be provided to the decoder
 * @param outputClass the desired output class
 * @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
 * @param <T> the output type
 */
protected <T> void testDecodeAll(Publisher<DataBuffer> input, Class<? extends T> outputClass,
		Consumer<StepVerifier.FirstStep<T>> stepConsumer) {

	testDecodeAll(input, ResolvableType.forClass(outputClass), stepConsumer, null, null);
}