Skip to content

Bring in the JUnit Assume feature to Test Case testPollOnDemand #12436

@Codegass

Description

@Codegass

Description & Motivation

Hi,

I would like to propose an idea of using Assume feature offered in JUnit 4&5 for some of the test cases in Druid. The Assume function is to replace Assertion in precondition checking. As mentioned in the document:

Assume functions is a set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information.

I notice that the test case testPollOnDemand can benefit from the Assume feature.

Right now this case is asserting the precondition(dataSourcesSnapshot) before the actual testing target(sqlSegmentsMetadataManager.forceOrWaitOngoingDatabasePoll()) is executed.

So test testPollOnDemand may fail due to 2 reasons:

  • The functions related to the testing precondition have bug (here is the sqlSegmentsMetadataManager.getDataSourcesSnapshot() sqlSegmentsMetadataManager.useLatestSnapshotIfWithinDelay()).
  • The functions related to Poll on Demand have bugs.(What we actually want to check with this test)

Here I suggest replacing the assertNull function with the assumeThat function, so when the precondition fails, JUnit can skip it instead of report a failure. This can help us to focus on failure that is raise by the target testing function, and filter the precondition failure.

Proposed Changes

Before

    DataSourcesSnapshot dataSourcesSnapshot = sqlSegmentsMetadataManager.getDataSourcesSnapshot();
    Assert.assertNull(dataSourcesSnapshot);
    // This should return false and not wait/poll anything as we did not schedule periodic poll
    Assert.assertFalse(sqlSegmentsMetadataManager.useLatestSnapshotIfWithinDelay());
    Assert.assertNull(dataSourcesSnapshot);

After

    DataSourcesSnapshot dataSourcesSnapshot = sqlSegmentsMetadataManager.getDataSourcesSnapshot();
    Assume.assumeThat(dataSourcesSnapshot, is(null));
    // This should return false and not wait/poll anything as we did not schedule periodic poll
    Assume.assumeFalse(sqlSegmentsMetadataManager.useLatestSnapshotIfWithinDelay());
    Assume.assumeThat(dataSourcesSnapshot, is(null));

Please let me know if you think this proposal makes sense, I would be more than happy to try the refactoring. (If not, comments are appreciated.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions