-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveDistributedQueries.java
Show resolved
Hide resolved
...trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/TestSqlServerDistributedQueries.java
Show resolved
Hide resolved
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 withcloseAfterClass
I know it is implemented correctly. - more boilerplate, like a need to create field.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
...trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/TestSqlServerDistributedQueries.java
Show resolved
Hide resolved
@@ -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) |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 withcloseAfterClass
I know it is implemented correctly. - more boilerplate, like a need to create field.
5a312cf
to
007939f
Compare
@findepi CA, PTAL |
007939f
to
6f2f189
Compare
No description provided.