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

HHH-13724 Add testing configs and dialect for CockroachDB #3280

Closed

Conversation

rafiss
Copy link
Contributor

@rafiss rafiss commented Mar 2, 2020

This adds a CockroachDB dialect and build configuration for testing with CockroachDB.

Tests that use features that CockroachDB does not support yet are annotated with SkipForDialect.

@rafiss rafiss changed the title HHH-13724 Add CockroachDB dialects and configs for testing HHH-13724 Add testing configs and dialect for CockroachDB Mar 2, 2020
*/
public class CockroachDB201Dialect extends CockroachDB192Dialect {
public CockroachDB201Dialect() {
super();
Copy link
Contributor

Choose a reason for hiding this comment

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

technically the default invocation of super can be omitted. it is only necessary when parameter(s) needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that other dialects include the explicit super() call. e.g. PostgreSQL94Dialect.

@@ -107,6 +107,16 @@ else if (Clob.class.isAssignableFrom( type )) {
: value;
return (X) clob;
}
else if ( String.class.isAssignableFrom( type ) ) {
if ( ClobImplementer.class.isInstance( value ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So two patterns show up above and it seems great to make them consistent. I think 'isAssignableFrom' is better than the deprecated 'Class#isInstance()', though even instanceof is enough for only static class is used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Class#isInstance isn't deprecated, but I agree that instanceof is better here since we have the class available statically.

I can't replace with isAssignableFrom because that method accepts parameter ofClass<?>, which is not the type of value`

@@ -232,6 +235,8 @@ public void testMultiselectWithPredicates() {
}

@Test
@SkipForDialect(CockroachDB192Dialect.class)
@RequiresDialect(CockroachDB201Dialect.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we still need @SkipForDialect if we have provided @RequiresDialect already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Actually, I'm not sure how I should implement this. Previously, this test would run against all dialects. Now I want it to run against all dialects except for CockroachDB192Dialect. But if I just use @SkipForDialect(CockroachDB192Dialect.class) then this will also skip the test for CockroachDB201Dialect since it is a sub-class of the 19.2 dialect.

Copy link
Contributor

Choose a reason for hiding this comment

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

have you tried with the property strictMatching it is present in both @RequiresDialect and @SkipForDialect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah found it -- there is a strictMatching property i can use here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dreab8 thanks! I didn't refresh so I missed your comment.

@rafiss rafiss force-pushed the HHH-13724-cockroachdb-dialects branch from 8c6a5b9 to 41f2ffc Compare March 4, 2020 04:24
@NathanQingyangXu
Copy link
Contributor

getting closer. now only checkStyle issue shows up during building

public boolean supportsMixedTypeArithmetic() {
return true;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid the introduction of these 2 methods and instead use @SkipForDialect annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I've removed these new methods

@rafiss rafiss force-pushed the HHH-13724-cockroachdb-dialects branch from a3be89f to d4c502e Compare March 26, 2020 04:07
Also add appropriate Skip/Require for the 19.2 and 20.1 dialects
- use instanceOf instead of isInstance()
- fix Skip/Require dialect annotations
- add license header
Remove the supportsLoFunction and supportsMixedTypeArithmetic dialect
checks
@rafiss rafiss force-pushed the HHH-13724-cockroachdb-dialects branch from 4744ff9 to 2ed5f84 Compare April 22, 2020 16:04
This required updating the tests to avoid dropping and recreating a
table in the same transaction, and skipping some tests that will not
work with CockroachDB.
@@ -41,9 +41,12 @@
public void setup() {
doInHibernate(
this::sessionFactory, session -> {
session.createSQLQuery( "DROP TABLE IF EXISTS MAIN_TABLE cascade" ).executeUpdate();
Copy link
Contributor

Choose a reason for hiding this comment

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

here
session.createSQLQuery( getDialect().getDropTableString( "MAIN_TABLE" ) ).executeUpdate();

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

session.createSQLQuery( "drop table MATERIAL_RATINGS cascade" ).executeUpdate();
session.createSQLQuery( "drop table BUILDING_RATINGS cascade" ).executeUpdate();
session.createSQLQuery( "drop table ASSOCIATION_TABLE cascade" ).executeUpdate();
session.createSQLQuery( "drop table MAIN_TABLE cascade" ).executeUpdate();
Copy link
Contributor

Choose a reason for hiding this comment

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

here has to be

session.createSQLQuery( getDialect().getDropTableString( "MATERIAL_RATINGS" ) ).executeUpdate();
					session.createSQLQuery( getDialect().getDropTableString( "BUILDING_RATINGS" ) ).executeUpdate();
					session.createSQLQuery( getDialect().getDropTableString( "ASSOCIATION_TABLE" ) ).executeUpdate();
					session.createSQLQuery( getDialect().getDropTableString( "MAIN_TABLE" ) ).executeUpdate();

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

Copy link
Contributor Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Thank you for all the comments! I have updated these drop table statements

session.createSQLQuery( "drop table MATERIAL_RATINGS cascade" ).executeUpdate();
session.createSQLQuery( "drop table BUILDING_RATINGS cascade" ).executeUpdate();
session.createSQLQuery( "drop table ASSOCIATION_TABLE cascade" ).executeUpdate();
session.createSQLQuery( "drop table MAIN_TABLE cascade" ).executeUpdate();
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

@@ -41,9 +41,12 @@
public void setup() {
doInHibernate(
this::sessionFactory, session -> {
session.createSQLQuery( "DROP TABLE IF EXISTS MAIN_TABLE cascade" ).executeUpdate();
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

@@ -126,7 +126,7 @@ protected void doBind(PreparedStatement st, X value, int index, WrapperOptions o
CharacterStream.class,
options
);
st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
st.setCharacterStream( index, characterStream.asReader() );
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 this change is unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks -- went back to the original version

@@ -137,7 +137,7 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
CharacterStream.class,
options
);
st.setCharacterStream( name, characterStream.asReader(), characterStream.getLength() );
st.setCharacterStream( name, characterStream.asReader() );
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

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

@@ -61,6 +61,7 @@
private static final Logger log = Logger.getLogger( LockTest.class );

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -145,6 +145,7 @@ public void testNativeSql() {
}

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -170,6 +171,7 @@ public void testPessimisticForcedIncrementOverall() {
}

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -67,6 +67,7 @@ public void releaseResources() {

@Test(timeout = 1000 * 30) //30 seconds
@TestForIssue(jiraKey = "HHH-11617")
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -249,6 +252,7 @@ public void testConstraints() throws Exception {
}

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -392,6 +396,7 @@ public void testMultiTable() throws Exception {
}

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -1095,6 +1090,7 @@ public void testDeleteEmpty() throws Exception {
}

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -71,6 +70,7 @@ public void testSQLServerSkipLocked() {

@Test
@RequiresDialect({ PostgreSQL95Dialect.class })
@RequiresDialectFeature(DialectChecks.SupportSkipLocked.class)
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 @RequiresDialectFeature can be removed

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

@@ -201,6 +201,7 @@ public void testRefreshWithExplicitLowerLevelLockMode() {

@Test
@TestForIssue(jiraKey = "HHH-12257")
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed with @SkipForDialect( value = CockroachDB192Dialect.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.

done

@@ -54,6 +56,7 @@ public void createTestData() {
@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL81Dialect.class,
SQLServer2005Dialect.class } )
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
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 @RequiresDialectFeature can be removed

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

@@ -79,6 +82,7 @@ public void testNoWait()

@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL95Dialect.class })
@RequiresDialectFeature(DialectChecks.SupportNoWait.class)
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 @RequiresDialectFeature can be removed

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

session.createSQLQuery( getDialect().getDropTableString( "MATERIAL_RATINGS" ) ).executeUpdate();
session.createSQLQuery( getDialect().getDropTableString( "BUILDING_RATINGS" ) ).executeUpdate();
session.createSQLQuery( getDialect().getDropTableString( "ASSOCIATION_TABLE" ) ).executeUpdate();
session.createSQLQuery( getDialect().getDropTableString( "MAIN_TABLE" ) ).executeUpdate();
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is causing a failure with Oracle, it has to be reverted to

session.createSQLQuery( "delete from MATERIAL_RATINGS" ).executeUpdate();
session.createSQLQuery( "delete from BUILDING_RATINGS" ).executeUpdate();
session.createSQLQuery( "delete from ASSOCIATION_TABLE" ).executeUpdate();
session.createSQLQuery( "delete from MAIN_TABLE" ).executeUpdate();

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

@@ -227,6 +226,7 @@ public void testRevisionsCounts() throws Exception {
}

@Test
@SkipForDialect(value = CockroachDB192Dialect.class, comment = "requires serial_normalization=sql_sequence setting")
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems this should be

@SkipForDialects( value = {
			@SkipForDialect(value = CockroachDB192Dialect.class, comment = "requires serial_normalization=sql_sequence setting"),
			@SkipForDialect(value = Oracle8iDialect.class,
					comment = "Oracle does not support identity key generation")
	})

otherwise the

@SkipForDialect(value = Oracle8iDialect.class,
				comment = "Oracle does not support identity key generation")

of the test class declaration is ignored and the test fails on Oracle.

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, didn't realize the method-level and class-level annotations could conflict.

Copy link
Contributor Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Thank you for your comments! I have addressed them.

Out of curiosity, why is SkipForDialect preferred instead of RequiresDialectFeature?

My reasoning for using RequiresDialectFeature is that a later version of CockroachDB will add support for the NoWait feature, and the dialect will return true for supportsNoWait(). Then the tests marked with @RequiresDialectFeature(DialectChecks.SupportNoWait.class) will automatically start running with that new dialect version.

If we use @SkipForDialect( value = CockroachDB192Dialect.class ), then we have to remember to come back to every test that is marked with this annotation, and manually determine which features the test uses and decide if it should be enabled for the new dialect.

@@ -137,7 +137,7 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
CharacterStream.class,
options
);
st.setCharacterStream( name, characterStream.asReader(), characterStream.getLength() );
st.setCharacterStream( name, characterStream.asReader() );
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

@@ -61,6 +61,7 @@
private static final Logger log = Logger.getLogger( LockTest.class );

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.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.

done

@@ -67,6 +67,7 @@ public void releaseResources() {

@Test(timeout = 1000 * 30) //30 seconds
@TestForIssue(jiraKey = "HHH-11617")
@RequiresDialectFeature(DialectChecks.SupportNoWait.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.

done

@@ -145,6 +145,7 @@ public void testNativeSql() {
}

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.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.

done

@@ -170,6 +171,7 @@ public void testPessimisticForcedIncrementOverall() {
}

@Test
@RequiresDialectFeature(DialectChecks.SupportNoWait.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.

done

@@ -201,6 +201,7 @@ public void testRefreshWithExplicitLowerLevelLockMode() {

@Test
@TestForIssue(jiraKey = "HHH-12257")
@RequiresDialectFeature(DialectChecks.SupportNoWait.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.

done

@@ -54,6 +56,7 @@ public void createTestData() {
@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL81Dialect.class,
SQLServer2005Dialect.class } )
@RequiresDialectFeature(DialectChecks.SupportNoWait.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.

done

@@ -79,6 +82,7 @@ public void testNoWait()

@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL95Dialect.class })
@RequiresDialectFeature(DialectChecks.SupportNoWait.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.

done

session.createSQLQuery( getDialect().getDropTableString( "MATERIAL_RATINGS" ) ).executeUpdate();
session.createSQLQuery( getDialect().getDropTableString( "BUILDING_RATINGS" ) ).executeUpdate();
session.createSQLQuery( getDialect().getDropTableString( "ASSOCIATION_TABLE" ) ).executeUpdate();
session.createSQLQuery( getDialect().getDropTableString( "MAIN_TABLE" ) ).executeUpdate();
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

@@ -227,6 +226,7 @@ public void testRevisionsCounts() throws Exception {
}

@Test
@SkipForDialect(value = CockroachDB192Dialect.class, comment = "requires serial_normalization=sql_sequence setting")
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, didn't realize the method-level and class-level annotations could conflict.

@dreab8
Copy link
Contributor

dreab8 commented Jul 1, 2020

Thanks Rafi for the changes,
in this specific case I asked to use SkipForDialect instead of RequiresDialectFeature(DialectChecks.SupportNoWait.class) only because I noticed that the tests run fire with the H2 dialect which supportsNoWait() method returns false.

@dreab8
Copy link
Contributor

dreab8 commented Jul 11, 2020

Thanks Rafi,

I'm closing this PR in favour of #3459 where I rebased the PR on top of master, squashed the commits and fixed an issue with a test recently added.

@dreab8 dreab8 closed this Jul 11, 2020
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.

3 participants