Class TableTestRule
- All Implemented Interfaces:
org.junit.rules.TestRule
@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 Summary
Modifier and TypeMethodDescriptionvoidafter()voidallowingError(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.<T> TallowingError(Supplier<T> function, Predicate<List<Throwable>> errorsAcceptable) voidConfigure a rule that enables theChunkPoolReleaseTrackingand performs a check after the test.static TableTestRuleA 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.static booleanReturns the current rule setting indicating whether to print table updates, can be used within test cases to decide whether to print more verbose information.static TableTestRuleA convenience rule builder that performs the proper setup and teardown for test cases that extend com.illumon.iris.db.v2.QueryTableTestBase.setCompilerToolsLogEnabled(boolean compilerToolsLogEnabled) Configure a rule that callsCompilerTools.setLogEnabled(boolean)to set the value for the duration of the unit test.Sets a new update error reporter on the rule that is suitable for unit testing.setExpectError(boolean expectError) This can be set totruewithin a unit test to indicate that an error is expected.setLiveTableMonitorCheckTableOperations(boolean ltmCheckTableOperations) Configure a rule that callsLiveTableMonitor.setCheckTableOperations(boolean)to set the value for the duration of the unit test.Configure a rule that has theLiveTableMonitorenabled for unit testing mode.static booleansetPrintTableUpdates(boolean newPrintTableUpdates) Configures this rule to print table updates if set to true.setQueryTableMemoizeResults(boolean memoizeResults) Configure a rule that callsQueryTable.setMemoizeResults(boolean)to set the value for the duration of the unit test.Configure a rule that sets theSystemicObjectTrackerto terminate queries only for errors within certain important objects.Configure a rule that has theUpdatePerformanceTrackerconfigured for unit testing mode.voidIfCompilerTools.setLogEnabled(boolean)has been configured for this rule, this method will reset it to its prior value.voidIfsetErrorReporter()has been configured for this rule, this method will reset it to its prior value.voidIfLiveTableMonitor.setCheckTableOperations(boolean)has been configured for this rule, this method will reset it to its prior value.voidvoidIfQueryTable.setMemoizeResults(boolean)has been configured for this rule, this method will reset it to its prior value.voidCleanup the strict chunk release tracking, which detects leaked chunks.Methods inherited from class org.junit.rules.ExternalResource
apply, before
-
Method Details
-
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
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 likeliveTableTestRule(), 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
Configure a rule that has theUpdatePerformanceTrackerconfigured for unit testing mode.- Returns:
- JUnit rule
-
setThreadSystemic
Configure a rule that sets theSystemicObjectTrackerto terminate queries only for errors within certain important objects.- Returns:
- JUnit rule
-
enableStrictChunkReleaseTracking
Configure a rule that enables theChunkPoolReleaseTrackingand performs a check after the test.- Returns:
- JUnit rule
-
unsetStrictChunkReleaseTracking
public void unsetStrictChunkReleaseTracking()Cleanup the strict chunk release tracking, which detects leaked chunks. -
setLiveTableMonitorUnitTestMode
Configure a rule that has theLiveTableMonitorenabled for unit testing mode.- Returns:
- JUnit rule
-
unsetLiveTableMonitorUnitTestMode
public void unsetLiveTableMonitorUnitTestMode()CallsLiveTableMonitor.resetForUnitTests(). This method will be called automatically after each test that includes the rule, it is not necessary to explicitly call it. -
setLiveTableMonitorCheckTableOperations
Configure a rule that callsLiveTableMonitor.setCheckTableOperations(boolean)to set the value for the duration of the unit test.- Parameters:
ltmCheckTableOperations-- Returns:
- JUnit rule
-
unsetLiveTableMonitorCheckTableOperations
public void unsetLiveTableMonitorCheckTableOperations()IfLiveTableMonitor.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
Configure a rule that callsQueryTable.setMemoizeResults(boolean)to set the value for the duration of the unit test.- Parameters:
memoizeResults-- Returns:
- JUnit rule
-
unsetQueryTableMemoizeResults
public void unsetQueryTableMemoizeResults()IfQueryTable.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
Configure a rule that callsCompilerTools.setLogEnabled(boolean)to set the value for the duration of the unit test.- Parameters:
compilerToolsLogEnabled-- Returns:
- JUnit rule
-
unsetCompilerToolsLogEnabled
public void unsetCompilerToolsLogEnabled()IfCompilerTools.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
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 usingliveTableTestRule()orqueryTableTestRule().- Returns:
- JUnit rule configured with a new test update error reporter.
-
unsetErrorReporter
public void unsetErrorReporter()IfsetErrorReporter()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
This can be set totruewithin a unit test to indicate that an error is expected. Rather than use this method directly, you can useallowingError(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:
afterin classorg.junit.rules.ExternalResource
-
clearErrors
public void clearErrors() -
getUpdateErrors
-
getErrorExpectation
-
allowingError
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- APredicatethat makes assertions that can use the errors generated.
-
allowingError
-
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.
-