From 658514986f7e08c40870ee622dd0132c40a029c3 Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Mon, 7 Mar 2022 22:27:23 +0100 Subject: [PATCH] TestWithNetworkConnections, InboundMessageQueuer: migrate from SettableFuture to CompletableFuture --- .../java/org/bitcoinj/testing/InboundMessageQueuer.java | 8 ++++---- .../org/bitcoinj/testing/TestWithNetworkConnections.java | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/src/test/java/org/bitcoinj/testing/InboundMessageQueuer.java b/core/src/test/java/org/bitcoinj/testing/InboundMessageQueuer.java index 91525be62..d78db354e 100644 --- a/core/src/test/java/org/bitcoinj/testing/InboundMessageQueuer.java +++ b/core/src/test/java/org/bitcoinj/testing/InboundMessageQueuer.java @@ -17,7 +17,6 @@ package org.bitcoinj.testing; import org.bitcoinj.core.*; -import com.google.common.util.concurrent.SettableFuture; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -25,13 +24,14 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CompletableFuture; /** * An extension of {@link PeerSocketHandler} that keeps inbound messages in a queue for later processing */ public abstract class InboundMessageQueuer extends PeerSocketHandler { public final BlockingQueue inboundMessages = new ArrayBlockingQueue<>(1000); - public final Map> mapPingFutures = new HashMap<>(); + public final Map> mapPingFutures = new HashMap<>(); public Peer peer; public BloomFilter lastReceivedFilter; @@ -51,9 +51,9 @@ public abstract class InboundMessageQueuer extends PeerSocketHandler { @Override protected void processMessage(Message m) throws Exception { if (m instanceof Ping) { - SettableFuture future = mapPingFutures.get(((Ping) m).getNonce()); + CompletableFuture future = mapPingFutures.get(((Ping) m).getNonce()); if (future != null) { - future.set(null); + future.complete(null); return; } } diff --git a/core/src/test/java/org/bitcoinj/testing/TestWithNetworkConnections.java b/core/src/test/java/org/bitcoinj/testing/TestWithNetworkConnections.java index bcb8c08cf..661cafb06 100644 --- a/core/src/test/java/org/bitcoinj/testing/TestWithNetworkConnections.java +++ b/core/src/test/java/org/bitcoinj/testing/TestWithNetworkConnections.java @@ -30,8 +30,6 @@ import org.bitcoinj.utils.Threading; import org.bitcoinj.wallet.KeyChainGroup; import org.bitcoinj.wallet.Wallet; -import com.google.common.util.concurrent.SettableFuture; - import javax.annotation.Nullable; import javax.net.SocketFactory; import java.io.IOException; @@ -39,6 +37,7 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; @@ -198,7 +197,7 @@ public class TestWithNetworkConnections { private void outboundPingAndWait(final InboundMessageQueuer p, long nonce) throws Exception { // Send a ping and wait for it to get to the other side - SettableFuture pingReceivedFuture = SettableFuture.create(); + CompletableFuture pingReceivedFuture = new CompletableFuture<>(); p.mapPingFutures.put(nonce, pingReceivedFuture); p.peer.sendMessage(new Ping(nonce)); pingReceivedFuture.get(); @@ -207,10 +206,10 @@ public class TestWithNetworkConnections { private void inboundPongAndWait(final InboundMessageQueuer p, final long nonce) throws Exception { // Receive a ping (that the Peer doesn't see) and wait for it to get through the socket - final SettableFuture pongReceivedFuture = SettableFuture.create(); + final CompletableFuture pongReceivedFuture = new CompletableFuture<>(); PreMessageReceivedEventListener listener = (p1, m) -> { if (m instanceof Pong && ((Pong) m).getNonce() == nonce) { - pongReceivedFuture.set(null); + pongReceivedFuture.complete(null); return null; } return m;