Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL source: Add comprehensive data type test #3810

Merged
merged 11 commits into from
Jun 7, 2021

Conversation

DoNotPanicUA
Copy link
Contributor

@DoNotPanicUA DoNotPanicUA commented Jun 2, 2021

Issue: #3562

What

We are creating comprehensive integration tests for the MySQL source connector. Such a test guarantees that connector implementation is infallible even in cases when the source contains unexpected/extreme values.
In addition, we provide an abstract implementation of the comprehensive test SourceComprehensiveTest in order to simplify test creation.

How

  1. Prepare a list of cases for testing in issue Create comprehensive data type tests for MySQL #3562.
  2. Implement an abstract comprehensive test in order to simplify the implementation. A common part for the existing acceptance test and the created comprehensive test is moved to a common class SourceAbstractTest.java.
  3. Implement the abstract test with all cases from the issue.

Pre-merge Checklist

  • Run integration tests

Recommended reading order

  1. MySqlSourceComprehensiveTest.java, CdcMySqlSourceComprehensiveTest.java
  2. SourceComprehensiveTest.java, SourceAbstractTest.java
  3. the rest

@DoNotPanicUA DoNotPanicUA linked an issue Jun 2, 2021 that may be closed by this pull request
Copy link
Contributor

@yaroslav-hrytsaienko yaroslav-hrytsaienko left a comment

Choose a reason for hiding this comment

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

@DoNotPanicUA great work! Needs a bit of tuning.

import java.util.Arrays;
import java.util.List;

public class DataTypeTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA I suggest to change the name of the class. Basically it is not a test it self. Maybe something like test data wrapper, or smth like this would be better.

private static final String DEFAULT_INSERT_SQL = "INSERT INTO %1$s VALUES (%2$s, %3$s);";

private final String sourceType;
private final Field.JsonSchemaPrimitive airbyteType;
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA please move jsonSchema to a separate class.

return airbyteType;
}

public String getName() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA please rename the method to getNameWithTestPrefix

return "test_" + testNumber + "_" + sourceType;
}

public String getCreateSQL() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA getCreateSQL-> getCreateSqlQuery

Copy link
Contributor

Choose a reason for hiding this comment

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

same for others

* @param insertValue test value
* @return builder
*/
public DataTypeTestBuilder addInsertValue(String... insertValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA addInsertValue->addInsertValues

* @param createTablePatternSQL creation table sql pattern
* @return builder
*/
public DataTypeTestBuilder createTablePatternSQL(String createTablePatternSQL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA due to JCC createTablePatternSQL->createTablePatternSql

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed everywhere

* @param testEnv - information about the test environment.
* @throws Exception - can throw any exception, test framework will handle.
*/
protected abstract void setup(TestDestinationEnv testEnv) throws Exception;
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA setup-> setupEnvironment , testEnv-> environment

Copy link
Contributor

Choose a reason for hiding this comment

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

same for others

*
* @param test comprehensive data type test
*/
public void addDataTypeTest(DataTypeTest test) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA addDataTypeTest -> addDataTypeTestData


@Override
protected void initTests() {
addDataTypeTest(
Copy link
Contributor

Choose a reason for hiding this comment

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

@DoNotPanicUA in case of datasets are equal please move them to parent class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they are slight different.

@DoNotPanicUA DoNotPanicUA requested a review from tuliren June 3, 2021 11:06
@DoNotPanicUA DoNotPanicUA marked this pull request as ready for review June 3, 2021 13:05
@DoNotPanicUA DoNotPanicUA self-assigned this Jun 4, 2021
@DoNotPanicUA DoNotPanicUA changed the title Aleonets/3562 comprehensive tests MySQL source: Add comprehensive data type test Jun 4, 2021
Copy link
Contributor

@subodh1810 subodh1810 left a comment

Choose a reason for hiding this comment

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

Few changes :

  1. We should split the tests. Each data type should have its own individual tests
  2. There should be individual assertion for each data type. We should check the value is correct and not just that the value is present.
  3. We should try to build the tests in such a way that they can be extensible for different JDBC connectors in the future

final List<AirbyteMessage> recordMessages = allMessages.stream().filter(m -> m.getType() == Type.RECORD).collect(Collectors.toList());

recordMessages.forEach(msg -> LOGGER.debug(msg.toString()));
assertFalse(recordMessages.isEmpty(), "Expected records from source");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should assert proper values instead of just values being present

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

DoNotPanicUA and others added 9 commits June 5, 2021 12:26
…t class SourceTest

+ add test comprehensive for MySQL CDC
+ add javadocs
+ rename SourceTest to SourceAbstractTest
+ clean autogenerated imports
+ proper builder implementation according to lombok style.
+ move up `JsonSchemaPrimitive` enum from inner class level
+ make test builder without mandatory params (simple builder)
@DoNotPanicUA DoNotPanicUA force-pushed the aleonets/3562-comprehensive-tests branch from 562841f to 29b4763 Compare June 5, 2021 09:36
@DoNotPanicUA
Copy link
Contributor Author

Few changes :

  1. We should split the tests. Each data type should have its own individual tests
  2. There should be individual assertion for each data type. We should check the value is correct and not just that the value is present.
  3. We should try to build the tests in such a way that they can be extensible for different JDBC connectors in the future

Hi, @subodh1810.
Thank you for your review.
The first implementation was focused on testing that the streamer is infallible even if source data is quite "tricky". But I agree it's not a "comprehensive" test if we don't check a streamer result.
So, I've added the possibility to specify expected values if it's required and corresponding validations.
In addition, I've added all found bugs (from my perspective) to the table.

About your third point. I realize that big difference between JDBC sources and I don't see common data tests for all JDBC sources. So, I decided to create the builder which allows you to describe your tests for any JDBC source. All common operations I moved to the abstract class.
If you have some ideas on how to build common tests for all JDBC sources, please call me at any convenient time for you.

Copy link
Contributor

@subodh1810 subodh1810 left a comment

Choose a reason for hiding this comment

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

@DoNotPanicUA can you run the tests for jdbc sources using /test connector=source-mysql

.airbyteType(JsonSchemaPrimitive.STRING)
.addInsertValues("null", "1", "127", "-128")
// @TODO returns number instead of boolean
// .addExpectedValues(null, "true", "false", "false")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be fixed by the PR #3890

@subodh1810
Copy link
Contributor

subodh1810 commented Jun 7, 2021

/test connector=source-mysql

🕑 source-mysql https://github.com/airbytehq/airbyte/actions/runs/914242949
✅ source-mysql https://github.com/airbytehq/airbyte/actions/runs/914242949

Copy link
Contributor

@subodh1810 subodh1810 left a comment

Choose a reason for hiding this comment

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

Can you create a follow up task to fix the TODOs. Also please run the tests for all the JDBC source connectors using the github command /test connector to make sure the change would not cause any problem. Rest looks good.

@DoNotPanicUA
Copy link
Contributor Author

DoNotPanicUA commented Jun 7, 2021

/test connector=source-jdbc

🕑 source-jdbc https://github.com/airbytehq/airbyte/actions/runs/914351340
✅ source-jdbc https://github.com/airbytehq/airbyte/actions/runs/914351340

@DoNotPanicUA
Copy link
Contributor Author

DoNotPanicUA commented Jun 7, 2021

/test connector=source-mssql

🕑 source-mssql https://github.com/airbytehq/airbyte/actions/runs/914351570
✅ source-mssql https://github.com/airbytehq/airbyte/actions/runs/914351570

@DoNotPanicUA
Copy link
Contributor Author

DoNotPanicUA commented Jun 7, 2021

/test connector=source-oracle

🕑 source-oracle https://github.com/airbytehq/airbyte/actions/runs/914351799
✅ source-oracle https://github.com/airbytehq/airbyte/actions/runs/914351799

@DoNotPanicUA
Copy link
Contributor Author

DoNotPanicUA commented Jun 7, 2021

/test connector=source-postgres

🕑 source-postgres https://github.com/airbytehq/airbyte/actions/runs/914352372
✅ source-postgres https://github.com/airbytehq/airbyte/actions/runs/914352372

@DoNotPanicUA
Copy link
Contributor Author

DoNotPanicUA commented Jun 7, 2021

/test connector=source-redshift

🕑 source-redshift https://github.com/airbytehq/airbyte/actions/runs/914352793
✅ source-redshift https://github.com/airbytehq/airbyte/actions/runs/914352793

@DoNotPanicUA
Copy link
Contributor Author

DoNotPanicUA commented Jun 7, 2021

/test connector=source-clickhouse

🕑 source-clickhouse https://github.com/airbytehq/airbyte/actions/runs/914353077
✅ source-clickhouse https://github.com/airbytehq/airbyte/actions/runs/914353077

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.

Create comprehensive data type tests for MySQL
4 participants