Class TableTestRule

java.lang.Object
org.junit.rules.ExternalResource
io.deephaven.engine.testutil.v2.utils.rules.TableTestRule
All Implemented Interfaces:
org.junit.rules.TestRule

public class TableTestRule extends org.junit.rules.ExternalResource
A JUnit rule that can be used in tests so that each test will be set up with the right options for a live table test case. Usage in most cases will be to add the following to your test classes.
    @Rule
     public TableTestRule tableTestRule = TableTestRule.liveTableTestRule();
 

That sets some common options used for live table test cases, such as setting the LiveTableMonitor up for unit test mode, disables table memoization, and sets the system to only terminate queries only for errors within certain important objects.

Using TableTestRule.queryTableTestRule(); will additionally set the compiler tools log to be disabled, sets the LiveTableMonitor's check table operations setting to false, and sets the update performance tracker to unit test mode.

If a custom configuration is desired, the rule can be created with the options that are desired, such as TableTestRule.setLiveTableMonitorUnitTestMode().setLiveTableMonitorCheckTableOperations(false).setQueryTableMemoizeResults(false) In all cases, the rule only needs to be created, and values will be set before each test case, and reset afterward.

  • Method Details

    • liveTableTestRule

      public static TableTestRule liveTableTestRule()
      A rule builder that performs the proper setup and teardown before and after unit tests that use live tables, including setting the LiveTableMonitor up for unit test mode, disabling table memoization, and setting the system to terminate queries only for errors within certain important objects.
      Returns:
      JUnit rule configured for live test table testing.
    • queryTableTestRule

      public static TableTestRule queryTableTestRule()
      A convenience rule builder that performs the proper setup and teardown for test cases that extend com.illumon.iris.db.v2.QueryTableTestBase. It is configured like liveTableTestRule(), and additionally sets the compiler tools log to be disabled, sets the LiveTableMonitor's check table operations setting to false, sets the update performance tracker to unit test mode.
      Returns:
      JUnit rule configured for tests extending QueryTestTableBase.
    • setUpdatePerformanceTrackerUnitTestMode

      public TableTestRule setUpdatePerformanceTrackerUnitTestMode()
      Configure a rule that has the UpdatePerformanceTracker configured for unit testing mode.
      Returns:
      JUnit rule
    • setThreadSystemic

      public TableTestRule setThreadSystemic()
      Configure a rule that sets the SystemicObjectTracker to terminate queries only for errors within certain important objects.
      Returns:
      JUnit rule
    • enableStrictChunkReleaseTracking

      public TableTestRule enableStrictChunkReleaseTracking()
      Configure a rule that enables the ChunkPoolReleaseTracking and performs a check after the test.
      Returns:
      JUnit rule
    • unsetStrictChunkReleaseTracking

      public void unsetStrictChunkReleaseTracking()
      Cleanup the strict chunk release tracking, which detects leaked chunks.
    • setLiveTableMonitorUnitTestMode

      public TableTestRule setLiveTableMonitorUnitTestMode()
      Configure a rule that has the LiveTableMonitor enabled for unit testing mode.
      Returns:
      JUnit rule
    • unsetLiveTableMonitorUnitTestMode

      public void unsetLiveTableMonitorUnitTestMode()
      Calls LiveTableMonitor.resetForUnitTests(). This method will be called automatically after each test that includes the rule, it is not necessary to explicitly call it.
    • setLiveTableMonitorCheckTableOperations

      public TableTestRule setLiveTableMonitorCheckTableOperations(boolean ltmCheckTableOperations)
      Configure a rule that calls LiveTableMonitor.setCheckTableOperations(boolean) to set the value for the duration of the unit test.
      Parameters:
      ltmCheckTableOperations -
      Returns:
      JUnit rule
    • unsetLiveTableMonitorCheckTableOperations

      public void unsetLiveTableMonitorCheckTableOperations()
      If LiveTableMonitor.setCheckTableOperations(boolean) has been configured for this rule, this method will reset it to its prior value. This method will be called automatically after each test, it is not necessary to explicitly call it.
    • setQueryTableMemoizeResults

      public TableTestRule setQueryTableMemoizeResults(boolean memoizeResults)
      Configure a rule that calls QueryTable.setMemoizeResults(boolean) to set the value for the duration of the unit test.
      Parameters:
      memoizeResults -
      Returns:
      JUnit rule
    • unsetQueryTableMemoizeResults

      public void unsetQueryTableMemoizeResults()
      If QueryTable.setMemoizeResults(boolean) has been configured for this rule, this method will reset it to its prior value. This method will be called automatically after each test, it is not necessary to explicitly call it.
    • setCompilerToolsLogEnabled

      public TableTestRule setCompilerToolsLogEnabled(boolean compilerToolsLogEnabled)
      Configure a rule that calls CompilerTools.setLogEnabled(boolean) to set the value for the duration of the unit test.
      Parameters:
      compilerToolsLogEnabled -
      Returns:
      JUnit rule
    • unsetCompilerToolsLogEnabled

      public void unsetCompilerToolsLogEnabled()
      If CompilerTools.setLogEnabled(boolean) has been configured for this rule, this method will reset it to its prior value. This method will be called automatically after each test, it is not necessary to explicitly call it.
    • setErrorReporter

      public TableTestRule setErrorReporter()
      Sets a new update error reporter on the rule that is suitable for unit testing. It is typically not necessary to explicitly configure this, one is set if using liveTableTestRule() or queryTableTestRule().
      Returns:
      JUnit rule configured with a new test update error reporter.
    • unsetErrorReporter

      public void unsetErrorReporter()
      If setErrorReporter() has been configured for this rule, this method will reset it to its prior value. This method will be called automatically after each test, it is not necessary to explicitly call it.
    • setExpectError

      public TableTestRule setExpectError(boolean expectError)
      This can be set to true within a unit test to indicate that an error is expected. Rather than use this method directly, you can use allowingError(java.lang.Runnable, java.util.function.Predicate<java.util.List<java.lang.Throwable>>).
      Parameters:
      expectError - Set to true if an error is expected to be thrown.
      Returns:
      JUnit rule configured to expect errors.
    • after

      public void after()
      Overrides:
      after in class org.junit.rules.ExternalResource
    • clearErrors

      public void clearErrors()
    • getUpdateErrors

      public List<Throwable> getUpdateErrors()
    • getErrorExpectation

      public TestUpdateErrorReporter.ErrorExpectation getErrorExpectation()
    • allowingError

      public void allowingError(Runnable function, Predicate<List<Throwable>> errorsAcceptable)
      This method can be used to call a table function that is expected to generate an error, and provide a predicate that can make assertions using the errors that are captured by the error reporter. For example:
      
       QueryTable myTable = ...
       tableTestRule.allowingError(() -> {
            table.getIndex().remove(..); // some table op that throws an Exception
       }, throwables -> {
           assertEquals(1, tableTestRule.getUpdateErrors().size());
           final Throwable throwable = throwables.get(0);
           assertEquals(IllegalStateException.class, throwable.getClass());
           return true;
       });
       
      Parameters:
      function - Runnable that is expected to generate a table update error.
      errorsAcceptable - A Predicate that makes assertions that can use the errors generated.
    • allowingError

      public <T> T allowingError(Supplier<T> function, Predicate<List<Throwable>> errorsAcceptable)
    • setPrintTableUpdates

      public static boolean setPrintTableUpdates(boolean newPrintTableUpdates)
      Configures this rule to print table updates if set to true.
      Parameters:
      newPrintTableUpdates - New printTableUpdates configuration setting.
      Returns:
      The old printTableUpdates value.
    • printTableUpdates

      public static boolean printTableUpdates()
      Returns the current rule setting indicating whether to print table updates, can be used within test cases to decide whether to print more verbose information.
      Returns:
      printTableUpdates configuration.