@Test public void testCatchUpToLatestAndSubscribeToNewBlockObservable() throws Exception { List<EthBlock> expected = Arrays.asList( createBlock(0), createBlock(1), createBlock(2), createBlock(3), createBlock(4), createBlock(5), createBlock(6)); List<EthBlock> ethBlocks = Arrays.asList( expected.get(2), expected.get(0), expected.get(1), expected.get(2), expected.get(4), expected.get(3), expected.get(4), expected.get(4), expected.get(5), expected.get(6)); OngoingStubbing<EthBlock> stubbing = when(web3jService.send(any(Request.class), eq(EthBlock.class))); for (EthBlock ethBlock : ethBlocks) { stubbing = stubbing.thenReturn(ethBlock); } EthFilter ethFilter = objectMapper.readValue( "{\n" + " \"id\":1,\n" + " \"jsonrpc\": \"2.0\",\n" + " \"result\": \"0x1\"\n" + "}", EthFilter.class); EthLog ethLog = objectMapper.readValue( "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":[" + "\"0x31c2342b1e0b8ffda1507fbffddf213c4b3c1e819ff6a84b943faabb0ebf2403\"" + "]}", EthLog.class); EthUninstallFilter ethUninstallFilter = objectMapper.readValue( "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":true}", EthUninstallFilter.class); when(web3jService.send(any(Request.class), eq(EthFilter.class))) .thenReturn(ethFilter); when(web3jService.send(any(Request.class), eq(EthLog.class))) .thenReturn(ethLog); when(web3jService.send(any(Request.class), eq(EthUninstallFilter.class))) .thenReturn(ethUninstallFilter); Observable<EthBlock> observable = web3j.catchUpToLatestAndSubscribeToNewBlocksObservable( new DefaultBlockParameterNumber(BigInteger.ZERO), false); CountDownLatch transactionLatch = new CountDownLatch(expected.size()); CountDownLatch completedLatch = new CountDownLatch(1); List<EthBlock> results = new ArrayList<>(expected.size()); Subscription subscription = observable.subscribe( result -> { results.add(result); transactionLatch.countDown(); }, throwable -> fail(throwable.getMessage()), () -> completedLatch.countDown()); transactionLatch.await(1250, TimeUnit.MILLISECONDS); assertThat(results, equalTo(expected)); subscription.unsubscribe(); completedLatch.await(1, TimeUnit.SECONDS); assertTrue(subscription.isUnsubscribed()); }
public Observable<EthBlock> catchUpToLatestAndSubscribeToNewBlocksObservable( DefaultBlockParameter startBlock, boolean fullTransactionObjects, long pollingInterval) { return catchUpToLatestBlockObservable( startBlock, fullTransactionObjects, blockObservable(fullTransactionObjects, pollingInterval)); }
JsonRpc2_0Rx { public Observable<EthBlock> catchUpToLatestAndSubscribeToNewBlocksObservable( DefaultBlockParameter startBlock, boolean fullTransactionObjects, long pollingInterval) { return catchUpToLatestBlockObservable( startBlock, fullTransactionObjects, blockObservable(fullTransactionObjects, pollingInterval)); } }
JsonRpc2_0Rx { public Observable<EthBlock> catchUpToLatestAndSubscribeToNewBlocksObservable( DefaultBlockParameter startBlock, boolean fullTransactionObjects, long pollingInterval) { return catchUpToLatestBlockObservable( startBlock, fullTransactionObjects, blockObservable(fullTransactionObjects, pollingInterval)); } JsonRpc2_0Rx(Web3j web3j, ScheduledExecutorService scheduledExecutorService); }
JsonRpc2_0Rx { public Observable<EthBlock> catchUpToLatestAndSubscribeToNewBlocksObservable( DefaultBlockParameter startBlock, boolean fullTransactionObjects, long pollingInterval) { return catchUpToLatestBlockObservable( startBlock, fullTransactionObjects, blockObservable(fullTransactionObjects, pollingInterval)); } JsonRpc2_0Rx(Web3j web3j, ScheduledExecutorService scheduledExecutorService); Observable<String> ethBlockHashObservable(long pollingInterval); Observable<String> ethPendingTransactionHashObservable(long pollingInterval); Observable<Log> ethLogObservable(
            org.web3j.protocol.core.methods.request.EthFilter ethFilter, long pollingInterval); Observable<Transaction> transactionObservable(long pollingInterval); Observable<Transaction> pendingTransactionObservable(long pollingInterval); Observable<EthBlock> blockObservable(
            boolean fullTransactionObjects, long pollingInterval); Observable<EthBlock> replayBlocksObservable(
            DefaultBlockParameter startBlock, DefaultBlockParameter endBlock,
            boolean fullTransactionObjects); Observable<EthBlock> replayBlocksObservable(
            DefaultBlockParameter startBlock, DefaultBlockParameter endBlock,
            boolean fullTransactionObjects, boolean ascending); Observable<Transaction> replayTransactionsObservable(
            DefaultBlockParameter startBlock, DefaultBlockParameter endBlock); Observable<EthBlock> catchUpToLatestBlockObservable(
            DefaultBlockParameter startBlock, boolean fullTransactionObjects,
            Observable<EthBlock> onCompleteObservable); Observable<EthBlock> catchUpToLatestBlockObservable(
            DefaultBlockParameter startBlock, boolean fullTransactionObjects); Observable<Transaction> catchUpToLatestTransactionObservable(
            DefaultBlockParameter startBlock); Observable<EthBlock> catchUpToLatestAndSubscribeToNewBlocksObservable(
            DefaultBlockParameter startBlock, boolean fullTransactionObjects,
            long pollingInterval); Observable<Transaction> catchUpToLatestAndSubscribeToNewTransactionsObservable(
            DefaultBlockParameter startBlock, long pollingInterval); }
JsonRpc2_0Rx { public Observable<EthBlock> catchUpToLatestAndSubscribeToNewBlocksObservable( DefaultBlockParameter startBlock, boolean fullTransactionObjects, long pollingInterval) { return catchUpToLatestBlockObservable( startBlock, fullTransactionObjects, blockObservable(fullTransactionObjects, pollingInterval)); } JsonRpc2_0Rx(Web3j web3j, ScheduledExecutorService scheduledExecutorService); Observable<String> ethBlockHashObservable(long pollingInterval); Observable<String> ethPendingTransactionHashObservable(long pollingInterval); Observable<Log> ethLogObservable(
            org.web3j.protocol.core.methods.request.EthFilter ethFilter, long pollingInterval); Observable<Transaction> transactionObservable(long pollingInterval); Observable<Transaction> pendingTransactionObservable(long pollingInterval); Observable<EthBlock> blockObservable(
            boolean fullTransactionObjects, long pollingInterval); Observable<EthBlock> replayBlocksObservable(
            DefaultBlockParameter startBlock, DefaultBlockParameter endBlock,
            boolean fullTransactionObjects); Observable<EthBlock> replayBlocksObservable(
            DefaultBlockParameter startBlock, DefaultBlockParameter endBlock,
            boolean fullTransactionObjects, boolean ascending); Observable<Transaction> replayTransactionsObservable(
            DefaultBlockParameter startBlock, DefaultBlockParameter endBlock); Observable<EthBlock> catchUpToLatestBlockObservable(
            DefaultBlockParameter startBlock, boolean fullTransactionObjects,
            Observable<EthBlock> onCompleteObservable); Observable<EthBlock> catchUpToLatestBlockObservable(
            DefaultBlockParameter startBlock, boolean fullTransactionObjects); Observable<Transaction> catchUpToLatestTransactionObservable(
            DefaultBlockParameter startBlock); Observable<EthBlock> catchUpToLatestAndSubscribeToNewBlocksObservable(
            DefaultBlockParameter startBlock, boolean fullTransactionObjects,
            long pollingInterval); Observable<Transaction> catchUpToLatestAndSubscribeToNewTransactionsObservable(
            DefaultBlockParameter startBlock, long pollingInterval);  }