Skip to content

Commit

Permalink
Consolidate test setup/teardown (#1581)
Browse files Browse the repository at this point in the history
This patch consolidates various setup/teardown code into LiveTableTestCase for JUnit 3 tests, and EngineCleanup for JUnit4 tests, and adds the EngineCleanup test rule to other tests that were currently missing it. Those tests that were previously missing it often had incomplete cleanup, which has mostly been removed through this change.

Fixes #1549
  • Loading branch information
niloc132 authored Nov 24, 2021
1 parent fec97ad commit 96218b7
Show file tree
Hide file tree
Showing 48 changed files with 616 additions and 813 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import io.deephaven.db.tables.select.QueryScope;
import io.deephaven.db.tables.utils.TableTools;
import io.deephaven.db.v2.select.IncrementalReleaseFilter;
import io.deephaven.db.v2.utils.AsyncClientErrorNotifier;
import io.deephaven.test.junit4.EngineCleanup;
import io.deephaven.test.types.ParallelTest;
import io.deephaven.util.ExceptionDetails;
import junit.framework.TestCase;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand Down Expand Up @@ -81,12 +79,6 @@ private <R> R incrementalBenchmark(Table inputTable, Function<Table, R> function
return result;
}

@BeforeClass
static public void setup() {
LiveTableMonitor.DEFAULT.enableUnitTestMode();
AsyncClientErrorNotifier.setReporter(t -> {
System.err.println("Received error notification: " + new ExceptionDetails(t).getFullStackTrace());
TestCase.fail(t.getMessage());
});
}
@Rule
public final EngineCleanup rule = new EngineCleanup();
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.deephaven.db.v2.utils;

import io.deephaven.datastructures.util.CollectionUtil;
import io.deephaven.db.tables.Table;
import io.deephaven.db.tables.TableDefinition;
import io.deephaven.db.tables.utils.TableTools;
import io.deephaven.db.util.config.InputTableStatusListener;
import io.deephaven.db.v2.QueryTable;
import io.deephaven.db.v2.sources.ArrayBackedColumnSource;
import io.deephaven.db.v2.sources.ColumnSource;
import io.deephaven.db.v2.sources.NullValueColumnSource;
import io.deephaven.db.v2.sources.WritableChunkSink;
import io.deephaven.db.v2.sources.chunk.*;
import io.deephaven.db.v2.sources.chunk.Attributes;
import io.deephaven.db.v2.sources.chunk.Chunk;
import io.deephaven.db.v2.sources.chunk.ChunkSource;
import io.deephaven.db.v2.sources.chunk.SharedContext;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
Expand Down Expand Up @@ -88,29 +89,31 @@ private AppendOnlyArrayBackedMutableTable(@NotNull TableDefinition definition,
@Override
protected void processPendingTable(Table table, boolean allowEdits, IndexChangeRecorder indexChangeRecorder,
Consumer<String> errorNotifier) {
final Index addIndex = table.getIndex();
final long firstRow = nextRow;
final long lastRow = firstRow + addIndex.intSize() - 1;
final OrderedKeys destinations = OrderedKeys.forRange(firstRow, lastRow);
destinations.forAllLongs(indexChangeRecorder::addIndex);
nextRow = lastRow + 1;

final SharedContext sharedContext = SharedContext.makeSharedContext();
final int chunkCapacity = table.intSize();

getColumnSourceMap().forEach((name, cs) -> {
final ArrayBackedColumnSource<?> arrayBackedColumnSource = (ArrayBackedColumnSource<?>) cs;
arrayBackedColumnSource.ensureCapacity(nextRow);
final ColumnSource<?> sourceColumnSource = table.getColumnSource(name);
try (final WritableChunkSink.FillFromContext ffc =
arrayBackedColumnSource.makeFillFromContext(chunkCapacity);
final ChunkSource.GetContext getContext =
sourceColumnSource.makeGetContext(chunkCapacity, sharedContext)) {
final Chunk<? extends Attributes.Values> valuesChunk =
sourceColumnSource.getChunk(getContext, addIndex);
arrayBackedColumnSource.fillFromChunk(ffc, valuesChunk, destinations);
try (final Index addIndex = table.getIndex().clone()) {
final long firstRow = nextRow;
final long lastRow = firstRow + addIndex.intSize() - 1;
try (OrderedKeys destinations = OrderedKeys.forRange(firstRow, lastRow)) {
destinations.forAllLongs(indexChangeRecorder::addIndex);
nextRow = lastRow + 1;

final SharedContext sharedContext = SharedContext.makeSharedContext();
final int chunkCapacity = table.intSize();

getColumnSourceMap().forEach((name, cs) -> {
final ArrayBackedColumnSource<?> arrayBackedColumnSource = (ArrayBackedColumnSource<?>) cs;
arrayBackedColumnSource.ensureCapacity(nextRow);
final ColumnSource<?> sourceColumnSource = table.getColumnSource(name);
try (final WritableChunkSink.FillFromContext ffc =
arrayBackedColumnSource.makeFillFromContext(chunkCapacity);
final ChunkSource.GetContext getContext =
sourceColumnSource.makeGetContext(chunkCapacity, sharedContext)) {
final Chunk<? extends Attributes.Values> valuesChunk =
sourceColumnSource.getChunk(getContext, addIndex);
arrayBackedColumnSource.fillFromChunk(ffc, valuesChunk, destinations);
}
});
}
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ private TransposeFillContext(final int chunkCapacity) {
outputPositions[ii] = WritableIntChunk.makeWritableChunk(chunkCapacity);
}
}

@Override
public void close() {
tempValues.close();
Arrays.stream(innerContexts).forEach(Context::close);
Arrays.stream(innerKeys).forEach(WritableLongChunk::close);
Arrays.stream(outputPositions).forEach(WritableIntChunk::close);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ protected void processPendingTable(Table table, boolean allowEdits, IndexChangeR

final SharedContext sharedContext = SharedContext.makeSharedContext();

final Index addIndex = table.getIndex();

long rowToInsert = nextRow;
final StringBuilder errorBuilder = new StringBuilder();

try (final WritableLongChunk<Attributes.KeyIndices> destinations =
WritableLongChunk.makeWritableChunk(chunkCapacity)) {
try (final Index addIndex = table.getIndex().clone();
final WritableLongChunk<Attributes.KeyIndices> destinations =
WritableLongChunk.makeWritableChunk(chunkCapacity)) {
try (final ChunkSource.GetContext getContext = keySource.makeGetContext(chunkCapacity, sharedContext);
final ChunkBoxer.BoxerKernel boxer = ChunkBoxer.getBoxer(keySource.getChunkType(), chunkCapacity)) {
final Chunk<? extends Attributes.Values> keys = keySource.getChunk(getContext, addIndex);
Expand Down Expand Up @@ -204,8 +203,10 @@ protected void processPendingDelete(Table table, IndexChangeRecorder indexChange
try (final WritableLongChunk<Attributes.KeyIndices> destinations =
WritableLongChunk.makeWritableChunk(chunkCapacity)) {
try (final ChunkSource.GetContext getContext = keySource.makeGetContext(chunkCapacity, sharedContext);
final ChunkBoxer.BoxerKernel boxer = ChunkBoxer.getBoxer(keySource.getChunkType(), chunkCapacity)) {
final Chunk<? extends Attributes.Values> keys = keySource.getChunk(getContext, table.getIndex());
final ChunkBoxer.BoxerKernel boxer = ChunkBoxer.getBoxer(keySource.getChunkType(), chunkCapacity);
final Index tableIndex = table.getIndex().clone();) {

final Chunk<? extends Attributes.Values> keys = keySource.getChunk(getContext, tableIndex);
final ObjectChunk<?, ? extends Attributes.Values> boxed = boxer.box(keys);
destinations.setSize(0);
for (int ii = 0; ii < boxed.size(); ++ii) {
Expand All @@ -222,9 +223,9 @@ protected void processPendingDelete(Table table, IndexChangeRecorder indexChange
// null out the values, so that we do not hold onto garbage forever, we keep the keys
for (ObjectArraySource<?> objectArraySource : arrayValueSources) {
try (final WritableChunkSink.FillFromContext ffc =
objectArraySource.makeFillFromContext(chunkCapacity)) {
final WritableObjectChunk<?, Attributes.Values> nullChunk =
WritableObjectChunk.makeWritableChunk(chunkCapacity);
objectArraySource.makeFillFromContext(chunkCapacity);
final WritableObjectChunk<?, Attributes.Values> nullChunk =
WritableObjectChunk.makeWritableChunk(chunkCapacity);) {
nullChunk.fillWithNullValue(0, chunkCapacity);
objectArraySource.fillFromChunkUnordered(ffc, nullChunk, destinations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import io.deephaven.db.tables.utils.DBDateTime;
import io.deephaven.db.tables.utils.DBTimeUtils;
import io.deephaven.db.tables.utils.TableTools;
import io.deephaven.db.v2.LiveTableTestCase;
import io.deephaven.db.v2.TstUtils;
import io.deephaven.db.v2.select.*;
import io.deephaven.db.v2.utils.Index;
import junit.framework.TestCase;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -22,7 +22,7 @@
import java.util.Arrays;
import java.util.Collections;

public class SelectFilterFactoryTest extends TestCase {
public class SelectFilterFactoryTest extends LiveTableTestCase {

public void testIn() {
assertEquals(MatchFilter.class, SelectFilterFactory.getExpression("Opra in oprasOfInterest").getClass());
Expand Down
19 changes: 5 additions & 14 deletions DB/src/test/java/io/deephaven/db/tables/utils/TestWindowCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,25 @@
import io.deephaven.db.v2.utils.Index;
import io.deephaven.db.v2.utils.TimeProvider;
import io.deephaven.db.v2.utils.UpdatePerformanceTracker;
import io.deephaven.test.junit4.JUnit4LiveTableTestCase;
import io.deephaven.test.junit4.EngineCleanup;
import io.deephaven.test.types.OutOfBandTest;
import junit.framework.TestCase;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import static io.deephaven.db.tables.utils.TableTools.intCol;
import static io.deephaven.db.v2.TstUtils.*;

@Category(OutOfBandTest.class)
public class TestWindowCheck {
private final JUnit4LiveTableTestCase base = new JUnit4LiveTableTestCase();

@Before
public void setUp() throws Exception {
base.setUp();
}

@After
public void tearDown() throws Exception {
base.tearDown();
}
@Rule
public final EngineCleanup base = new EngineCleanup();

/**
* Run a window check over the course of a simulated day.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import io.deephaven.db.tables.live.LiveTableMonitor;
import io.deephaven.db.tables.utils.TableTools;
import io.deephaven.db.v2.*;
import io.deephaven.test.junit4.JUnit4LiveTableTestCase;
import io.deephaven.test.junit4.EngineCleanup;
import io.deephaven.util.QueryConstants;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.util.Optional;
Expand All @@ -19,17 +18,8 @@
import static io.deephaven.db.v2.TstUtils.*;

public class TestTableAssertions {
JUnit4LiveTableTestCase testCase = new JUnit4LiveTableTestCase();

@Before
public void before() throws Exception {
testCase.setUp();
}

@After
public void after() throws Exception {
testCase.tearDown();
}
@Rule
public final EngineCleanup base = new EngineCleanup();

@Test
public void testStatic() {
Expand Down
9 changes: 4 additions & 5 deletions DB/src/test/java/io/deephaven/db/v2/FuzzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import io.deephaven.db.util.liveness.LivenessScopeStack;
import io.deephaven.db.v2.utils.RuntimeMemory;
import io.deephaven.db.v2.utils.TimeProvider;
import io.deephaven.test.junit4.JUnit4LiveTableTestCase;
import io.deephaven.test.junit4.EngineCleanup;
import io.deephaven.test.types.SerialTest;
import io.deephaven.util.SafeCloseable;
import org.apache.commons.lang3.mutable.MutableLong;
import org.jetbrains.annotations.Nullable;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -38,7 +39,8 @@ public class FuzzerTest {
private static final boolean REALTIME_FUZZER_ENABLED =
Configuration.getInstance().getBooleanWithDefault("FuzzerTest.realTime", false);

JUnit4LiveTableTestCase framework = new JUnit4LiveTableTestCase();
@Rule
public final EngineCleanup framework = new EngineCleanup();

private static class FuzzDescriptor {
final long querySeed;
Expand Down Expand Up @@ -89,15 +91,12 @@ private void setupPersistence() {

@Before
public void setUp() throws Exception {
framework.setUp();
setupPersistence();
}

@After
public void tearDown() throws Exception {
QueryScope.setScope(new QueryScope.StandaloneImpl());
cleanupPersistence();
framework.tearDown();
}

private GroovyDeephavenSession getGroovySession() throws IOException {
Expand Down
26 changes: 0 additions & 26 deletions DB/src/test/java/io/deephaven/db/v2/IndexGroupingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,27 @@

import io.deephaven.base.verify.Assert;
import io.deephaven.base.verify.Require;
import io.deephaven.compilertools.CompilerTools;
import io.deephaven.configuration.Configuration;
import io.deephaven.db.tables.Table;
import io.deephaven.db.tables.live.LiveTableMonitor;
import io.deephaven.db.tables.utils.TableTools;
import io.deephaven.db.v2.sources.ColumnSource;
import io.deephaven.db.v2.tuples.TupleSource;
import io.deephaven.db.v2.tuples.TupleSourceFactory;
import io.deephaven.db.v2.utils.Index;
import io.deephaven.db.v2.utils.UpdatePerformanceTracker;
import io.deephaven.test.types.OutOfBandTest;
import org.apache.commons.lang3.mutable.MutableInt;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import org.junit.experimental.categories.Category;

import static io.deephaven.db.tables.utils.TableTools.show;
import static io.deephaven.db.v2.TstUtils.getTable;

@SuppressWarnings("ClassInitializerMayBeStatic")
@Category(OutOfBandTest.class)
public class IndexGroupingTest extends LiveTableTestCase {

private static final boolean ENABLE_COMPILER_TOOLS_LOGGING = Configuration.getInstance()
.getBooleanForClassWithDefault(IndexGroupingTest.class, "CompilerTools.logEnabled", false);

private boolean oldCompilerToolsLogEnabled;

@Before
@Override
public void setUp() throws Exception {
super.setUp();
UpdatePerformanceTracker.getInstance().enableUnitTestMode();
oldCompilerToolsLogEnabled = CompilerTools.setLogEnabled(ENABLE_COMPILER_TOOLS_LOGGING);
}

@After
@Override
public void tearDown() throws Exception {
CompilerTools.setLogEnabled(oldCompilerToolsLogEnabled);
super.tearDown();
}

private static ArrayList<ArrayList<String>> powerSet(Set<String> originalSet) {
return powerSet(originalSet.stream().collect(Collectors.toList()));
}
Expand Down
24 changes: 0 additions & 24 deletions DB/src/test/java/io/deephaven/db/v2/JUnit4QueryTableTestBase.java

This file was deleted.

Loading

0 comments on commit 96218b7

Please sign in to comment.