Skip to content

Commit

Permalink
Fix OOB Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Jan 10, 2024
1 parent 5966196 commit e820fdd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import io.deephaven.util.locks.AwareFunctionalLock;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;

/**
Expand All @@ -27,7 +27,7 @@ public class CapturingUpdateGraph implements UpdateGraph {

private final ExecutionContext context;

private final List<Runnable> sources = new ArrayList<>();
private final Queue<Runnable> sources = new ConcurrentLinkedQueue<>();

public CapturingUpdateGraph(@NotNull final ControlledUpdateGraph delegate) {
this.delegate = delegate;
Expand All @@ -52,6 +52,10 @@ void refreshSources() {
sources.forEach(Runnable::run);
}

void markSourcesRefreshedForUnitTests() {
delegate.markSourcesRefreshedForUnitTests();
}

@Override
public LogOutput append(LogOutput logOutput) {
return logOutput.append("CapturingUpdateGraph of ").append(delegate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public void testAddAndRemoveLocations() {

allowingError(() -> updateGraph.getDelegate().runWithinUnitTestCycle(() -> {
updateGraph.refreshSources();
updateGraph.markSourcesRefreshedForUnitTests();
registrar.run();
}), errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0),
TableLocationRemovedException.class).isPresent());
}, false), errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0), TableLocationRemovedException.class).isPresent());
getUpdateErrors().clear();

assertEquals(1, partitionTable.size());
Expand Down Expand Up @@ -147,10 +147,10 @@ public void testAddAndRemoveLocations() {

allowingError(() -> updateGraph.getDelegate().runWithinUnitTestCycle(() -> {
updateGraph.refreshSources();
updateGraph.markSourcesRefreshedForUnitTests();
registrar.run();
}), errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0),
TableLocationRemovedException.class).isPresent());
}, false), errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0), TableLocationRemovedException.class).isPresent());
getUpdateErrors().clear();

assertEquals(2, partitionTable.size());
Expand All @@ -163,10 +163,11 @@ public void testAddAndRemoveLocations() {
// The TableBackedTableLocation has a copy() of the p3 table which is itself a leaf. Erroring P3 will
// cause one error to come from the copied table, and one from the merged() table. We just need to validate
// that the exceptions we see are a ConstituentTableException and an ISE
allowingError(() -> updateGraph.getDelegate().runWithinUnitTestCycle(
() -> p3.notifyListenersOnError(new IllegalStateException("This is a test error"), null)),
errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0), IllegalStateException.class).isPresent());
allowingError(() -> updateGraph.getDelegate().runWithinUnitTestCycle(() -> {
p3.notifyListenersOnError(new IllegalStateException("This is a test error"), null);
updateGraph.markSourcesRefreshedForUnitTests();
}, false), errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0), IllegalStateException.class).isPresent());
}

/**
Expand Down Expand Up @@ -197,10 +198,10 @@ public void testRemoveAndFail() {
allowingError(() -> updateGraph.getDelegate().runWithinUnitTestCycle(() -> {
// This should process the pending update from the refresh above.
updateGraph.refreshSources();
updateGraph.markSourcesRefreshedForUnitTests();
registrar.run();
}),
errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0), TableDataException.class).isPresent());
}, false), errors -> errors.size() == 1 &&
FindExceptionCause.isOrCausedBy(errors.get(0), TableDataException.class).isPresent());
getUpdateErrors().clear();

// Then delete it for real
Expand All @@ -210,8 +211,9 @@ public void testRemoveAndFail() {
// We should NOT get an error here because the failed table should have removed itself from the registrar.
updateGraph.getDelegate().runWithinUnitTestCycle(() -> {
updateGraph.refreshSources();
updateGraph.markSourcesRefreshedForUnitTests();
registrar.run();
});
}, false);

assertEquals(1, partitionTable.size());
try (final CloseableIterator<Table> tableIt = partitionTable.columnIterator("LocationTable")) {
Expand Down Expand Up @@ -240,8 +242,9 @@ public void testCantReadPrev() {

allowingError(() -> updateGraph.runWithinUnitTestCycle(() -> {
updateGraph.refreshSources();
updateGraph.markSourcesRefreshedForUnitTests();
registrar.run();
}), errors -> errors.stream().anyMatch(e -> FindExceptionCause.isOrCausedBy(e,
}, false), errors -> errors.stream().anyMatch(e -> FindExceptionCause.isOrCausedBy(e,
InvalidatedRegionException.class).isPresent()) &&
errors.stream().anyMatch(e -> FindExceptionCause.isOrCausedBy(e,
TableLocationRemovedException.class).isPresent()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public <T> T allowingError(Supplier<T> function, Predicate<List<Throwable>> erro
} finally {
setExpectError(original);
}
if (!errorsAcceptable.test(errors)) {
if (errors == null && !errorsAcceptable.test(errors)) {
TestCase.fail("Unacceptable errors: " + errors);
}
return retval;
Expand Down

0 comments on commit e820fdd

Please sign in to comment.