@Test public void testSeen() { PeerAddress peer = createMock(PeerAddress.class); Sha256Hash brokenHash = createMock(Sha256Hash.class); Sha256Hash correctHash = createMock(Sha256Hash.class); TransactionConfidence brokenConfidence = createMock(TransactionConfidence.class); expect(brokenConfidence.getTransactionHash()).andReturn(brokenHash); expect(brokenConfidence.markBroadcastBy(peer)).andThrow(new ArithmeticException("some error")); TransactionConfidence correctConfidence = createMock(TransactionConfidence.class); expect(correctConfidence.getTransactionHash()).andReturn(correctHash); expect(correctConfidence.markBroadcastBy(peer)).andReturn(true); correctConfidence.queueListeners(anyObject(TransactionConfidence.Listener.ChangeReason.class)); expectLastCall(); TransactionConfidence.Factory factory = createMock(TransactionConfidence.Factory.class); expect(factory.createConfidence(brokenHash)).andReturn(brokenConfidence); expect(factory.createConfidence(correctHash)).andReturn(correctConfidence); replay(factory, brokenConfidence, correctConfidence); TxConfidenceTable table = new TxConfidenceTable(1, factory); try { table.seen(brokenHash, peer); } catch (ArithmeticException expected) { } assertNotNull(table.seen(correctHash, peer)); }
public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer) { TransactionConfidence confidence; boolean fresh = false; lock.lock(); try { cleanTable(); confidence = getOrCreate(hash); fresh = confidence.markBroadcastBy(byPeer); } finally { lock.unlock(); } if (fresh) confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); return confidence; }
TxConfidenceTable { public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer) { TransactionConfidence confidence; boolean fresh = false; lock.lock(); try { cleanTable(); confidence = getOrCreate(hash); fresh = confidence.markBroadcastBy(byPeer); } finally { lock.unlock(); } if (fresh) confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); return confidence; } }
TxConfidenceTable { public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer) { TransactionConfidence confidence; boolean fresh = false; lock.lock(); try { cleanTable(); confidence = getOrCreate(hash); fresh = confidence.markBroadcastBy(byPeer); } finally { lock.unlock(); } if (fresh) confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); return confidence; } TxConfidenceTable(final int size);   TxConfidenceTable(final int size, TransactionConfidence.Factory confidenceFactory);  TxConfidenceTable(); }
TxConfidenceTable { public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer) { TransactionConfidence confidence; boolean fresh = false; lock.lock(); try { cleanTable(); confidence = getOrCreate(hash); fresh = confidence.markBroadcastBy(byPeer); } finally { lock.unlock(); } if (fresh) confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); return confidence; } TxConfidenceTable(final int size);   TxConfidenceTable(final int size, TransactionConfidence.Factory confidenceFactory);  TxConfidenceTable(); int numBroadcastPeers(Sha256Hash txHash); TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer); TransactionConfidence getOrCreate(Sha256Hash hash); @Nullable TransactionConfidence get(Sha256Hash hash); }
TxConfidenceTable { public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer) { TransactionConfidence confidence; boolean fresh = false; lock.lock(); try { cleanTable(); confidence = getOrCreate(hash); fresh = confidence.markBroadcastBy(byPeer); } finally { lock.unlock(); } if (fresh) confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); return confidence; } TxConfidenceTable(final int size);   TxConfidenceTable(final int size, TransactionConfidence.Factory confidenceFactory);  TxConfidenceTable(); int numBroadcastPeers(Sha256Hash txHash); TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer); TransactionConfidence getOrCreate(Sha256Hash hash); @Nullable TransactionConfidence get(Sha256Hash hash); static final int MAX_SIZE; }