Skip to content

Commit

Permalink
Fix TestTimeSeriesFilter to not accidentally preserve (absent GC) the…
Browse files Browse the repository at this point in the history
… TimeSeriesFilters from previous validation rounds
  • Loading branch information
rcaudy committed Nov 23, 2024
1 parent 88955c7 commit 40bcc8a
Showing 1 changed file with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import io.deephaven.api.filter.Filter;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.liveness.LivenessReferent;
import io.deephaven.engine.liveness.ReferenceCountedLivenessReferent;
import io.deephaven.engine.rowset.RowSet;
import io.deephaven.engine.rowset.WritableRowSet;
import io.deephaven.engine.table.Table;
Expand All @@ -24,10 +26,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;

import static io.deephaven.engine.testutil.TstUtils.*;
Expand Down Expand Up @@ -153,7 +152,7 @@ public void testIncremental() throws ParseException {
final TimeSeriesFilter exclusionFilter =
TimeSeriesFilter.newBuilder().columnName("Date").period("PT01:00:00").clock(testClock).invert(true)
.build();
final ArrayList<WeakReference<TimeSeriesFilter>> filtersToRefresh = new ArrayList<>();
final List<WeakReference<TimeSeriesFilter>> filtersToRefresh = Collections.synchronizedList(new ArrayList<>());

final ControlledUpdateGraph updateGraph = ExecutionContext.getContext().getUpdateGraph().cast();
EvalNugget[] en = makeNuggets(table, inclusionFilter, filtersToRefresh, updateGraph, exclusionFilter);
Expand Down Expand Up @@ -192,7 +191,7 @@ public void testIncremental2() throws ParseException {
final TimeSeriesFilter exclusionFilter =
TimeSeriesFilter.newBuilder().columnName("Date").period("PT01:00:00").clock(testClock).invert(true)
.build();
final ArrayList<WeakReference<TimeSeriesFilter>> filtersToRefresh = new ArrayList<>();
final List<WeakReference<TimeSeriesFilter>> filtersToRefresh = Collections.synchronizedList(new ArrayList<>());

EvalNugget[] en = makeNuggets(table, inclusionFilter, filtersToRefresh, updateGraph, exclusionFilter);

Expand All @@ -214,18 +213,36 @@ public void testIncremental2() throws ParseException {
}

private static EvalNugget @NotNull [] makeNuggets(QueryTable table, TimeSeriesFilter inclusionFilter,
ArrayList<WeakReference<TimeSeriesFilter>> filtersToRefresh, ControlledUpdateGraph updateGraph,
List<WeakReference<TimeSeriesFilter>> filtersToRefresh, ControlledUpdateGraph updateGraph,
TimeSeriesFilter exclusionFilter) {
final Table withInstant = table.update("Date=DateTimeUtils.epochNanosToInstant(Date.getTime() * 1000000L)");
return new EvalNugget[] {
EvalNugget.from(() -> {
final TimeSeriesFilter inclusionCopy = inclusionFilter.copy();
filtersToRefresh.add(new WeakReference<>(inclusionCopy));
final WeakReference<TimeSeriesFilter> filterRef = new WeakReference<>(inclusionCopy);
final LivenessReferent sentinel = new ReferenceCountedLivenessReferent() {
@Override
public void destroy() {
super.destroy();
filtersToRefresh.remove(filterRef);
}
};
inclusionCopy.manage(sentinel);
filtersToRefresh.add(filterRef);
return updateGraph.exclusiveLock().computeLocked(() -> withInstant.where(inclusionCopy));
}),
EvalNugget.from(() -> {
final TimeSeriesFilter exclusionCopy = exclusionFilter.copy();
filtersToRefresh.add(new WeakReference<>(exclusionCopy));
final WeakReference<TimeSeriesFilter> filterRef = new WeakReference<>(exclusionCopy);
final LivenessReferent sentinel = new ReferenceCountedLivenessReferent() {
@Override
public void destroy() {
super.destroy();
filtersToRefresh.remove(filterRef);
}
};
exclusionCopy.manage(sentinel);
filtersToRefresh.add(filterRef);
return updateGraph.exclusiveLock().computeLocked(() -> withInstant.where(exclusionCopy));
}),
};
Expand Down

0 comments on commit 40bcc8a

Please sign in to comment.