You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2022/03/22 01:19:47 UTC

[httpcomponents-core] branch master updated: Upgrade to RxJava3

This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 513700f  Upgrade to RxJava3
513700f is described below

commit 513700f91b48b6f7f12e86444282ca5048b2b6bd
Author: Ryan Schmitt <rs...@apache.org>
AuthorDate: Mon Mar 21 13:32:16 2022 -0700

    Upgrade to RxJava3
    
    Since the `ReactiveTestUtils` API references symbols from RxJava2, I've
    left it untouched for now so that japicmp doesn't yell at me.
---
 httpcore5-reactive/pom.xml                            |  6 +++---
 .../hc/core5/reactive/TestReactiveDataConsumer.java   |  8 ++++----
 .../hc/core5/reactive/TestReactiveDataProducer.java   |  2 +-
 .../hc/core5/reactive/TestReactiveEntityProducer.java |  2 +-
 .../examples/ReactiveFullDuplexClientExample.java     |  4 ++--
 httpcore5-testing/pom.xml                             |  7 ++++++-
 ...ReactiveTestUtils.java => Reactive3TestUtils.java} | 19 ++++++++++---------
 .../testing/reactive/ReactiveRandomProcessor.java     |  4 ++--
 .../hc/core5/testing/reactive/ReactiveTestUtils.java  |  6 ++++++
 .../hc/core5/testing/reactive/ReactiveClientTest.java | 12 ++++++------
 pom.xml                                               |  3 ++-
 11 files changed, 43 insertions(+), 30 deletions(-)

diff --git a/httpcore5-reactive/pom.xml b/httpcore5-reactive/pom.xml
index b15d2b9..5e322ca 100644
--- a/httpcore5-reactive/pom.xml
+++ b/httpcore5-reactive/pom.xml
@@ -55,9 +55,9 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>io.reactivex.rxjava2</groupId>
+      <groupId>io.reactivex.rxjava3</groupId>
       <artifactId>rxjava</artifactId>
-      <version>${rxjava.version}</version>
+      <version>${rxjava3.version}</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
@@ -81,4 +81,4 @@
     </plugins>
   </reporting>
 
-</project>
\ No newline at end of file
+</project>
diff --git a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataConsumer.java b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataConsumer.java
index efdf1a1..40d8a7a 100644
--- a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataConsumer.java
+++ b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataConsumer.java
@@ -35,10 +35,10 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
-import io.reactivex.Flowable;
-import io.reactivex.Notification;
-import io.reactivex.Observable;
-import io.reactivex.Single;
+import io.reactivex.rxjava3.core.Flowable;
+import io.reactivex.rxjava3.core.Notification;
+import io.reactivex.rxjava3.core.Observable;
+import io.reactivex.rxjava3.core.Single;
 import org.apache.hc.core5.http.HttpStreamResetException;
 import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.junit.jupiter.api.Assertions;
diff --git a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataProducer.java b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataProducer.java
index 0e0f9ff..96a6747 100644
--- a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataProducer.java
+++ b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataProducer.java
@@ -34,7 +34,7 @@ import org.apache.hc.core5.http.nio.DataStreamChannel;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-import io.reactivex.Flowable;
+import io.reactivex.rxjava3.core.Flowable;
 
 public class TestReactiveDataProducer {
     @Test
diff --git a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveEntityProducer.java b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveEntityProducer.java
index 369df16..e89402b 100644
--- a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveEntityProducer.java
+++ b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveEntityProducer.java
@@ -35,7 +35,7 @@ import org.apache.hc.core5.http.nio.DataStreamChannel;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-import io.reactivex.Flowable;
+import io.reactivex.rxjava3.core.Flowable;
 
 public class TestReactiveEntityProducer {
 
diff --git a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java
index f962860..8c87b50 100644
--- a/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java
+++ b/httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java
@@ -54,8 +54,8 @@ import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.util.Timeout;
 import org.reactivestreams.Publisher;
 
-import io.reactivex.Flowable;
-import io.reactivex.Observable;
+import io.reactivex.rxjava3.core.Flowable;
+import io.reactivex.rxjava3.core.Observable;
 
 /**
  * Example of full-duplex HTTP/1.1 message exchanges using reactive streaming. This demo will stream randomly
diff --git a/httpcore5-testing/pom.xml b/httpcore5-testing/pom.xml
index 4847db0..c94f2ab 100644
--- a/httpcore5-testing/pom.xml
+++ b/httpcore5-testing/pom.xml
@@ -66,6 +66,11 @@
       <version>${rxjava.version}</version>
     </dependency>
     <dependency>
+      <groupId>io.reactivex.rxjava3</groupId>
+      <artifactId>rxjava</artifactId>
+      <version>${rxjava3.version}</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-slf4j-impl</artifactId>
       <scope>test</scope>
@@ -184,4 +189,4 @@
     </plugins>
   </reporting>
 
-</project>
\ No newline at end of file
+</project>
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/Reactive3TestUtils.java
similarity index 95%
copy from httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java
copy to httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/Reactive3TestUtils.java
index 39fb67d..7334240 100644
--- 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/Reactive3TestUtils.java
@@ -27,6 +27,14 @@
 
 package org.apache.hc.core5.testing.reactive;
 
+import io.reactivex.rxjava3.core.Emitter;
+import io.reactivex.rxjava3.core.Flowable;
+import io.reactivex.rxjava3.core.Single;
+import io.reactivex.rxjava3.functions.Consumer;
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.util.TextUtils;
+import org.reactivestreams.Publisher;
+
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
@@ -34,15 +42,8 @@ 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;
-
-public class ReactiveTestUtils {
+@Internal
+public class Reactive3TestUtils {
     /** The range from which to generate random data. */
     private final static byte[] RANGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
             .getBytes(StandardCharsets.US_ASCII);
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveRandomProcessor.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveRandomProcessor.java
index cdcbe50..ba05cc4 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveRandomProcessor.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveRandomProcessor.java
@@ -51,7 +51,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.reactive.ReactiveRequestProcessor;
 import org.reactivestreams.Publisher;
 
-import io.reactivex.Flowable;
+import io.reactivex.rxjava3.core.Flowable;
 
 public class ReactiveRandomProcessor implements ReactiveRequestProcessor {
     public ReactiveRandomProcessor() {
@@ -100,7 +100,7 @@ public class ReactiveRandomProcessor implements ReactiveRequestProcessor {
             }
 
             final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
-            final Flowable<ByteBuffer> stream = ReactiveTestUtils.produceStream(n);
+            final Flowable<ByteBuffer> stream = Reactive3TestUtils.produceStream(n);
             final String hash = ReactiveTestUtils.getStreamHash(n);
             response.addHeader("response-hash-code", hash);
             final BasicEntityDetails basicEntityDetails = new BasicEntityDetails(n, ContentType.APPLICATION_OCTET_STREAM);
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
index 39fb67d..f6d4444 100644
--- 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
@@ -34,6 +34,7 @@ import java.security.NoSuchAlgorithmException;
 import java.util.Random;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.hc.core5.annotation.Internal;
 import org.apache.hc.core5.util.TextUtils;
 import org.reactivestreams.Publisher;
 
@@ -42,6 +43,11 @@ import io.reactivex.Flowable;
 import io.reactivex.Single;
 import io.reactivex.functions.Consumer;
 
+/**
+ * @deprecated Use {@link Reactive3TestUtils} and RxJava3
+ */
+@Internal
+@Deprecated
 public class ReactiveTestUtils {
     /** The range from which to generate random data. */
     private final static byte[] RANGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java
index fa64c47..739eaf9 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java
@@ -69,7 +69,7 @@ import org.apache.hc.core5.testing.nio.LoggingH2StreamListener;
 import org.apache.hc.core5.testing.nio.LoggingHttp1StreamListener;
 import org.apache.hc.core5.testing.nio.LoggingIOSessionDecorator;
 import org.apache.hc.core5.testing.nio.LoggingIOSessionListener;
-import org.apache.hc.core5.testing.reactive.ReactiveTestUtils.StreamDescription;
+import org.apache.hc.core5.testing.reactive.Reactive3TestUtils.StreamDescription;
 import org.apache.hc.core5.util.TextUtils;
 import org.apache.hc.core5.util.Timeout;
 import org.hamcrest.CoreMatchers;
@@ -84,8 +84,8 @@ import org.reactivestreams.Publisher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import io.reactivex.Flowable;
-import io.reactivex.Observable;
+import io.reactivex.rxjava3.core.Flowable;
+import io.reactivex.rxjava3.core.Observable;
 
 @RunWith(Parameterized.class)
 @EnableRuleMigrationSupport
@@ -211,7 +211,7 @@ public class ReactiveClientTest {
         final InetSocketAddress address = startClientAndServer();
         final long expectedLength = 6_554_200L;
         final AtomicReference<String> expectedHash = new AtomicReference<>();
-        final Flowable<ByteBuffer> stream = ReactiveTestUtils.produceStream(expectedLength, expectedHash);
+        final Flowable<ByteBuffer> stream = Reactive3TestUtils.produceStream(expectedLength, expectedHash);
         final ReactiveEntityProducer producer = new ReactiveEntityProducer(stream, -1, null, null);
         final BasicRequestProducer request = getRequestProducer(address, producer);
 
@@ -219,7 +219,7 @@ public class ReactiveClientTest {
         requester.execute(request, consumer, SOCKET_TIMEOUT, null);
         final Message<HttpResponse, Publisher<ByteBuffer>> response = consumer.getResponseFuture()
                 .get(RESULT_TIMEOUT.getDuration(), RESULT_TIMEOUT.getTimeUnit());
-        final StreamDescription desc = ReactiveTestUtils.consumeStream(response.getBody()).blockingGet();
+        final StreamDescription desc = Reactive3TestUtils.consumeStream(response.getBody()).blockingGet();
 
         Assertions.assertEquals(expectedLength, desc.length);
         Assertions.assertEquals(expectedHash.get(), TextUtils.toHexString(desc.md.digest()));
@@ -244,7 +244,7 @@ public class ReactiveClientTest {
             requester.execute(request, consumer, SOCKET_TIMEOUT, null);
             final Message<HttpResponse, Publisher<ByteBuffer>> response = consumer.getResponseFuture()
                 .get(RESULT_TIMEOUT.getDuration(), RESULT_TIMEOUT.getTimeUnit());
-            final StreamDescription desc = ReactiveTestUtils.consumeStream(response.getBody()).blockingGet();
+            final StreamDescription desc = Reactive3TestUtils.consumeStream(response.getBody()).blockingGet();
 
             Assertions.assertEquals(expectedLength, desc.length);
             Assertions.assertEquals(expectedHash.get(), TextUtils.toHexString(desc.md.digest()));
diff --git a/pom.xml b/pom.xml
index bb7fae4..099c03a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,6 +79,7 @@
     <slf4j.version>1.7.25</slf4j.version>
     <log4j.version>2.17.0</log4j.version>
     <rxjava.version>2.2.21</rxjava.version>
+    <rxjava3.version>3.1.3</rxjava3.version>
     <api.comparison.version>5.1</api.comparison.version>
     <japicmp.version>0.15.4</japicmp.version>
     <hc.animal-sniffer.signature.ignores>javax.net.ssl.SSLEngine,javax.net.ssl.SSLParameters</hc.animal-sniffer.signature.ignores>
@@ -374,4 +375,4 @@
     </plugins>
   </reporting>
 
-</project>
\ No newline at end of file
+</project>