@Override public RVVException clone() { RVVExceptionT clone = new RVVExceptionT(previousVersion, nextVersion); if (this.received != null) { clone.received = new TreeSet<Long>(this.received); } return clone; }
@Override public void add(long receivedVersion) { if (receivedVersion == this.previousVersion + 1) { this.previousVersion = receivedVersion; if (this.received != null) { consumeReceivedVersions(); } } else if (receivedVersion == this.nextVersion - 1) { this.nextVersion = receivedVersion; if (this.received != null) { consumeReceivedVersions(); } } else if (this.previousVersion < receivedVersion && receivedVersion < this.nextVersion) { addReceived(receivedVersion); } }
@Test public void testRVVExceptionT() { RVVExceptionT ex = new RVVExceptionT(5, 10); ex.add(8); ex.add(6); assertEquals(8, ex.getHighestReceivedVersion()); }
protected boolean sameAs(RVVExceptionB ex) { if (!super.sameAs(ex)) { return false; } for (ReceivedVersionsReverseIterator it = receivedVersionsReverseIterator(); it.hasNext();) { if (!ex.contains(it.next())) { return false; } } for (ReceivedVersionsReverseIterator it = ex.receivedVersionsReverseIterator(); it.hasNext();) { if (!contains(it.next())) { return false; } } return true; }
/** * For test purposes only. This isn't quite accurate, because I think two RVVs that have * effectively same exceptions may represent the exceptions differently. This method is testing * for an exact match of exception format. */ @Override public boolean sameAs(RVVException ex) { if (ex instanceof RVVExceptionT) { return ((RVVExceptionT) ex).sameAs(this); } if (!super.sameAs(ex)) { return false; } RVVExceptionB other = (RVVExceptionB) ex; if (this.received == null) { if (other.received != null && !other.received.isEmpty()) { return false; } } else if (!this.received.equals(other.received)) return false; return true; }
@Override public RVVException changeForm() { // Convert the exception to a bitset exception RVVExceptionB ex = new RVVExceptionB(previousVersion, nextVersion); for (ReceivedVersionsReverseIterator it = this.receivedVersionsReverseIterator(); it .hasNext();) { long next = it.next(); ex.add(next); } return ex; }
/** Use this method to create a new RVVException */ static RVVException createException(long previousVersion, long nextVersion, long initialExceptionCount) { // arbitrary cutoff of 100 bytes to use a treeSet instead of bitSet // But if we are deserializing an exception too many received versions use a // bitset anyway. long delta = nextVersion - previousVersion; if (UseTreeSetsForTesting || (delta > RVV_MAX_BITSET_SPAN && initialExceptionCount * 512 < delta)) { return new RVVExceptionT(previousVersion, nextVersion); } return new RVVExceptionB(previousVersion, nextVersion); }
@Test public void testRVVExceptionTOutput() throws Exception { testExceptionOutput(new RVVExceptionT(50, 100)); }