From 95d4012393fd02a8b759ae7ea3cf4012b94b0cc3 Mon Sep 17 00:00:00 2001 From: Ryan Schmitt Date: Mon, 28 Jul 2025 16:01:22 -0700 Subject: [PATCH] Drop RxJava 2 RxJava 2 is end-of-life as of February 28, 2021. `ReactiveTestUtils` can probably be dropped for 5.6 in favor of `Reactive3TestUtils`. --- httpcore5-testing/pom.xml | 7 +- .../testing/reactive/ReactiveTestUtils.java | 158 ------------------ pom.xml | 6 +- 3 files changed, 4 insertions(+), 167 deletions(-) delete mode 100644 httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java diff --git a/httpcore5-testing/pom.xml b/httpcore5-testing/pom.xml index 91c0a515f9..7741059258 100644 --- a/httpcore5-testing/pom.xml +++ b/httpcore5-testing/pom.xml @@ -60,11 +60,6 @@ org.slf4j slf4j-api - - io.reactivex.rxjava2 - rxjava - ${rxjava.version} - io.reactivex.rxjava3 rxjava @@ -161,4 +156,4 @@ - \ No newline at end of file + diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java deleted file mode 100644 index 1813cdd3a1..0000000000 --- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - * - */ - -package org.apache.hc.core5.testing.reactive; - -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Random; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.hc.core5.util.TextUtils; -import org.reactivestreams.Publisher; - -import io.reactivex.Emitter; -import io.reactivex.Flowable; -import io.reactivex.Single; -import io.reactivex.functions.Consumer; - -/** - * @deprecated Use {@link Reactive3TestUtils} and RxJava3 - */ -@Deprecated -public class ReactiveTestUtils { - /** The range from which to generate random data. */ - private final static byte[] RANGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - .getBytes(StandardCharsets.US_ASCII); - - /** - * Produces a deterministic stream of bytes, in randomly sized chunks of up to 128kB. - * - * @param length the number of bytes in the stream - * @return a reactive stream of bytes - */ - public static Flowable produceStream(final long length) { - return produceStream(length, null); - } - - /** - * Produces a deterministic stream of bytes, in randomly sized chunks of up to 128kB, while computing the hash of - * the random data. - * - * @param length the number of bytes in the stream - * @param hash an output argument for the hash, set when the end of the stream is reached; if {@code null}, the - * hash will not be computed - * @return a reactive stream of bytes - */ - public static Flowable produceStream(final long length, final AtomicReference hash) { - return produceStream(length, 128 * 1024, hash); - } - - /** - * Produces a deterministic stream of bytes, in randomly sized chunks, while computing the hash of the random data. - * - * @param length the number of bytes in the stream - * @param maximumBlockSize the maximum size of any {@code ByteBuffer in the stream} - * @param hash an output argument for the hash, set when the end of the stream is reached; if {@code null}, the - * hash will not be computed - * @return a reactive stream of bytes - */ - public static Flowable produceStream( - final long length, - final int maximumBlockSize, - final AtomicReference hash - ) { - return Flowable.generate(new Consumer>() { - final Random random = new Random(length); // Use the length as the random seed for easy reproducibility - long bytesEmitted; - final MessageDigest md = newMessageDigest(); - - @Override - public void accept(final Emitter emitter) { - final long remainingLength = length - bytesEmitted; - if (remainingLength == 0) { - emitter.onComplete(); - if (hash != null) { - hash.set(TextUtils.toHexString(md.digest())); - } - } else { - final int bufferLength = (int) Math.min(remainingLength, 1 + random.nextInt(maximumBlockSize)); - final byte[] bs = new byte[bufferLength]; - for (int i = 0; i < bufferLength; i++) { - final byte b = RANGE[(int) (random.nextDouble() * RANGE.length)]; - bs[i] = b; - } - if (hash != null) { - md.update(bs); - } - emitter.onNext(ByteBuffer.wrap(bs)); - bytesEmitted += bufferLength; - } - } - }); - } - - /** - * Computes the hash of the deterministic stream (as produced by {@link #produceStream(long)}). - */ - public static String getStreamHash(final long length) { - return TextUtils.toHexString(consumeStream(produceStream(length)).blockingGet().md.digest()); - } - - /** - * Consumes the given stream and returns a data structure containing its length and digest. - */ - public static Single consumeStream(final Publisher publisher) { - final StreamDescription seed = new StreamDescription(0, newMessageDigest()); - return Flowable.fromPublisher(publisher) - .reduce(seed, (desc, byteBuffer) -> { - final long length = desc.length + byteBuffer.remaining(); - desc.md.update(byteBuffer); - return new StreamDescription(length, desc.md); - }); - } - - private static MessageDigest newMessageDigest() { - try { - return MessageDigest.getInstance("MD5"); - } catch (final NoSuchAlgorithmException ex) { - throw new AssertionError(ex); - } - } - - public static class StreamDescription { - public final long length; - public final MessageDigest md; - - public StreamDescription(final long length, final MessageDigest md) { - this.length = length; - this.md = md; - } - } -} diff --git a/pom.xml b/pom.xml index 509ee4ae16..5d4584f851 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,6 @@ 4.11.0 1.7.36 2.25.0 - 2.2.21 3.1.10 1.21.3 5.3 @@ -232,6 +231,7 @@ true true + true METHOD_NEW_DEFAULT @@ -241,6 +241,7 @@ @org.apache.hc.core5.annotation.Internal + org.apache.hc.core5.testing.reactive.ReactiveTestUtils @@ -369,7 +370,6 @@ @org.apache.hc.core5.annotation.Internal - true @@ -382,4 +382,4 @@ - \ No newline at end of file +