Skip to content

Comments

[BEAM-2515] BeamSql: refactor the MockedBeamSqlTable and related tests#3478

Closed
xumingming wants to merge 5 commits intoapache:DSL_SQLfrom
xumingming:BEAM-2515-refactor-mock
Closed

[BEAM-2515] BeamSql: refactor the MockedBeamSqlTable and related tests#3478
xumingming wants to merge 5 commits intoapache:DSL_SQLfrom
xumingming:BEAM-2515-refactor-mock

Conversation

@xumingming
Copy link
Contributor

Summary:

  • rename MockedBeamSqlTable to MockedBoundedTable
  • Use the RowsBuilder to build rows in Unit Test.
  • use PAssert rather than assertEquals when test PCollections.

@xumingming
Copy link
Contributor Author

R: @xumingmin
R: @takidau

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f2ad396 on xumingming:BEAM-2515-refactor-mock into ** on apache:DSL_SQL**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f2ad396 on xumingming:BEAM-2515-refactor-mock into ** on apache:DSL_SQL**.

Copy link
Contributor

@takidau takidau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. A couple javadoc requests, but otherwise looks solid.

this.rows.add(row);
}

public RowsBuilder addRows(final Object... args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better name, thanks!

*/
public class MockedBoundedTable extends MockedTable {
public static final ConcurrentLinkedQueue<BeamSqlRow> CONTENT = new ConcurrentLinkedQueue<>();
private List<BeamSqlRow> rows = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

return new MockedBoundedTable(buildBeamSqlRecordType(args));
}

public MockedBoundedTable addRows(Object... args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc

* Mocked table for bounded data sources.
*/
public class MockedBoundedTable extends MockedTable {
public static final ConcurrentLinkedQueue<BeamSqlRow> CONTENT = new ConcurrentLinkedQueue<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc

Copy link

@mingmxu mingmxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Mock package is much more clear. Just one question about the test data set, I see each unit test class prepared its own table, is it possible to test on the same set?

public class MockedUnboundedTable extends MockedTable {
private List<Pair<Duration, List<BeamSqlRow>>> timestampedRows = new ArrayList<>();
/** rows flow out from this table with the specified watermark instant. */
private final List<Pair<Duration, List<BeamSqlRow>>> timestampedRows = new ArrayList<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for L102-L105, is it better to add data first, and then advance watermark?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I did it in purpose, Let's look at some examples. First example:

     addRows(
            Duration.ZERO,
            1, 1, 1, FIRST_DATE,
            1, 2, 2, FIRST_DATE
        )

It means these data are added after the specified watermark(ZERO) -- just after the first window starts. Another example:

        .addRows(
            WINDOW_SIZE.minus(Duration.standardSeconds(1)),
            2, 2, 3, SECOND_DATE,
            2, 3, 3, SECOND_DATE
        )

It means these data are emitted just before the first window close. One more example:

        .addRows(
            WINDOW_SIZE.plus(Duration.standardSeconds(1)),
            2, 2, 3, SECOND_DATE,
            2, 3, 3, SECOND_DATE
        )

It means these data are emitted just after the first window close, and after the second window starts.

Very handy and easy to use, right :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, interesting design!

@xumingming
Copy link
Contributor Author

@xumingmin For the test data set, sometimes we need to test the normal case -- the test would pass; sometimes we need to test the exception case -- the test need to fail, the test data for these two kinds of case will differ.

Another perspective: If we want to use one common test data set to test every cases of every relational algebra(join, union, values etc), the test data set will need diversity. Change to the common data set will affect all of tests, it will make the tests brittle -- which will bring unnecessary maintainance burden.

I prefer prepare separate data set for each test.

@xumingming
Copy link
Contributor Author

Retest this please.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 7786e51 on xumingming:BEAM-2515-refactor-mock into ** on apache:DSL_SQL**.

@mingmxu
Copy link

mingmxu commented Jul 1, 2017

Make sense for different functions like JOIN/UNION/..., would be helpful to separate the prepare() part which can be leveraged to test DSL methods.

@xumingming
Copy link
Contributor Author

I agree, the data set can be reused to test DSL methods, but let's leave to DSL Unit Tests PR, when it is needed?

Copy link

@mingmxu mingmxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Let's do the change in DSL join tests (BEAM-2550)

@xumingming
Copy link
Contributor Author

@lukecwik can you help merge this one? @xumingmin and @takidau have already reviewed and approved this PR, just need a merge. (Other ISSUE is blocked by this one).

asfgit pushed a commit that referenced this pull request Jul 5, 2017
@lukecwik
Copy link
Member

lukecwik commented Jul 5, 2017

Merged, please close PR

@xumingming xumingming closed this Jul 6, 2017
@xumingming xumingming deleted the BEAM-2515-refactor-mock branch July 6, 2017 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants