Skip to content

Commit

Permalink
Merge pull request #2749 from alvasw/bitcoind_remove_throws_Malformed…
Browse files Browse the repository at this point in the history
…URLException

BitcoindRegtestSetup: Remove unnecessary 'throws InterruptedException'
  • Loading branch information
HenrikJannsen authored Sep 3, 2024
2 parents 737e3b8 + 1d577ac commit d70d753
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 396 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.net.MalformedURLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -53,7 +52,7 @@ public BitcoindPsbtMultiSigIntegrationTests(BitcoindRegtestSetup regtestSetup) {
}

@Test
public void psbtMultiSigTest() throws MalformedURLException, InterruptedException {
public void psbtMultiSigTest() throws InterruptedException {
var aliceWallet = regtestSetup.createAndInitializeNewWallet("alice_wallet");
var bobWallet = regtestSetup.createAndInitializeNewWallet("bob_wallet");
var charlieWallet = regtestSetup.createAndInitializeNewWallet("charlie_wallet");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand All @@ -34,7 +32,6 @@
public class BitcoindZeroMqBlockHashIntegrationIntegrationTests {

private final BitcoindRegtestSetup regtestSetup;
private final Set<String> minedBlockHashes = new CopyOnWriteArraySet<>();
private final CountDownLatch listenerReceivedBlockHashLatch = new CountDownLatch(1);

public BitcoindZeroMqBlockHashIntegrationIntegrationTests(BitcoindRegtestSetup regtestSetup) {
Expand All @@ -46,43 +43,36 @@ void blockHashNotification() throws InterruptedException {
ZmqListeners zmqListeners = regtestSetup.getZmqListeners();
zmqListeners.registerNewBlockMinedListener((blockHash) -> {
log.info("Notification: New block with hash {}", blockHash);

if (minedBlockHashes.contains(blockHash)) {
listenerReceivedBlockHashLatch.countDown();
} else {
minedBlockHashes.add(blockHash);
}
listenerReceivedBlockHashLatch.countDown();
});

createAndStartDaemonThread(() -> {
Thread thread = new Thread(() -> {
while (true) {
try {
List<String> blockHashes = regtestSetup.mineOneBlock();
log.info("Mined block: {}", blockHashes);

for (String blockHash : blockHashes) {
if (minedBlockHashes.contains(blockHash)) {
listenerReceivedBlockHashLatch.countDown();
return;
} else {
minedBlockHashes.add(blockHash);
}
if (Thread.interrupted()) {
break;
}

log.info("Sleeping for 200ms before mining next block.");
//noinspection BusyWait
Thread.sleep(200);

} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});

thread.start();

boolean await = listenerReceivedBlockHashLatch.await(1, TimeUnit.MINUTES);
thread.interrupt();

if (!await) {
throw new IllegalStateException("Didn't connect to bitcoind after 1 minute.");
}
}

private void createAndStartDaemonThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
thread.start();
}
}

This file was deleted.

Loading

0 comments on commit d70d753

Please sign in to comment.