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

Cleanup in MySQL and SQL Server tests #6759

Merged
merged 5 commits into from
Feb 1, 2021

Conversation

kokosing
Copy link
Member

No description provided.

@cla-bot cla-bot bot added the cla-signed label Jan 29, 2021
@kokosing kokosing requested a review from losipiuk January 29, 2021 15:14
@@ -137,7 +137,7 @@ public void testImplementSum()
Optional.empty()); // filter not supported
}

private void testImplementAggregation(AggregateFunction aggregateFunction, Map<String, ColumnHandle> assignments, Optional<String> expectedExpression)
private static void testImplementAggregation(AggregateFunction aggregateFunction, Map<String, ColumnHandle> assignments, Optional<String> expectedExpression)
Copy link
Member

Choose a reason for hiding this comment

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

Same applies to all TestXxxClient classes, as they are copies.
Not much benefit though IMO

Copy link
Member Author

Choose a reason for hiding this comment

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

I got warnings in IDE. I don't like warnings, but I do like static methods.

Copy link
Member

Choose a reason for hiding this comment

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

i don't have a warning here

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Did we decide to use that?

I got warnings in IDE. I don't like warnings, but I do like static methods.

i don't like either.

but "method can be static" is test code is counter productive -- the tests themselves are isntance methods, so we shouldn't care if a test helper is an instance method as well, especially when it implements a test's logic (as case here) as compared to being ordinary utility method (those should definitely be static)


private void execute(String sql)
{
mysqlServer.execute(sql, mysqlServer.getUsername(), mysqlServer.getPassword());
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong direction IMO.
Subclass TestGlobalTransactionMySqlIntegrationSmokeTest initializes the server on its own.
Instead of this, we should remove the server field in this class.

please drop this commit for now

Copy link
Member Author

Choose a reason for hiding this comment

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

Notice that parameters mysqlServer.getUsername(), mysqlServer.getPassword() are useless as these are defaults. Then method exists only for mysqlServer.execute(sql);. Inlining this makes it easier.

Instead of this, we should remove the server field in this class.

I agree that this would be better. However, it is common that we inject infra for tests like that.

Do you suggest that we should make execute abstract? That would be on the other hand increase boilerplate on implementation side.

Copy link
Member

Choose a reason for hiding this comment

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

Do you suggest that we should make execute abstract?

Yes, i think so, but let's out of scope here

@AfterClass(alwaysRun = true)
public final void destroy()
{
mysqlServer.close();
Copy link
Member

Choose a reason for hiding this comment

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

I see closeAfterClass benefits, especially where state management is hard to do without it. That was the reason why we added that method.
But no, it does not improve readability. It makes is less clear that the resources is properly disposed of after the test class.

Copy link
Member Author

Choose a reason for hiding this comment

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

But no, it does not improve readability.

I don't agree.

Pros of closeAfterClass:

  • it is concise. Used when resource is created is like try-with-resources you know already that it is going to bel deallocated properly.
  • It is also correct. Resources are deallocated in proper order.

Cons of @AfterClass kind of deallocation:

  • it is detached from allocation. You need to find a place where object is deallocated. In this commit I removed a case where object was created in one class and destroyed in other. Since it is detached one can even deallocate thing several times.
  • I always need to double check if alwaysRun is used. Wasted energy, while with closeAfterClass I know it is implemented correctly.
  • more boilerplate, like a need to create field.

Copy link
Member

Choose a reason for hiding this comment

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

You missed the fact @AfterClass cleanup is standard and globally applicable, whereas closeAfterClass is available in these tests only.

I am not OK making closeAfterClass a rule. I am 'whatever' on a change here

Copy link
Member Author

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Responded to comments, no code changes yet.

@@ -137,7 +137,7 @@ public void testImplementSum()
Optional.empty()); // filter not supported
}

private void testImplementAggregation(AggregateFunction aggregateFunction, Map<String, ColumnHandle> assignments, Optional<String> expectedExpression)
private static void testImplementAggregation(AggregateFunction aggregateFunction, Map<String, ColumnHandle> assignments, Optional<String> expectedExpression)
Copy link
Member Author

Choose a reason for hiding this comment

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

I got warnings in IDE. I don't like warnings, but I do like static methods.


private void execute(String sql)
{
mysqlServer.execute(sql, mysqlServer.getUsername(), mysqlServer.getPassword());
Copy link
Member Author

Choose a reason for hiding this comment

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

Notice that parameters mysqlServer.getUsername(), mysqlServer.getPassword() are useless as these are defaults. Then method exists only for mysqlServer.execute(sql);. Inlining this makes it easier.

Instead of this, we should remove the server field in this class.

I agree that this would be better. However, it is common that we inject infra for tests like that.

Do you suggest that we should make execute abstract? That would be on the other hand increase boilerplate on implementation side.

@AfterClass(alwaysRun = true)
public final void destroy()
{
mysqlServer.close();
Copy link
Member Author

Choose a reason for hiding this comment

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

But no, it does not improve readability.

I don't agree.

Pros of closeAfterClass:

  • it is concise. Used when resource is created is like try-with-resources you know already that it is going to bel deallocated properly.
  • It is also correct. Resources are deallocated in proper order.

Cons of @AfterClass kind of deallocation:

  • it is detached from allocation. You need to find a place where object is deallocated. In this commit I removed a case where object was created in one class and destroyed in other. Since it is detached one can even deallocate thing several times.
  • I always need to double check if alwaysRun is used. Wasted energy, while with closeAfterClass I know it is implemented correctly.
  • more boilerplate, like a need to create field.

@kokosing kokosing force-pushed the origin/master/271_close branch from 5a312cf to 007939f Compare January 30, 2021 22:08
@kokosing
Copy link
Member Author

@findepi CA, PTAL

@kokosing kokosing merged commit d55d899 into trinodb:master Feb 1, 2021
@kokosing kokosing deleted the origin/master/271_close branch February 1, 2021 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants