-
Notifications
You must be signed in to change notification settings - Fork 25.6k
SQL: test coverage for JdbcResultSet #32813
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
Changes from 6 commits
deb0b03
34bd90f
54834c9
7ce8fd8
9d802a9
906ca43
f14cb8a
493fc85
c32a997
24ec3bf
6325807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,7 +92,7 @@ public void testThrownExceptionsWhenSettingStringValues() throws SQLException { | |
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
|
|
||
| SQLException sqle = expectThrows(SQLException.class, () -> jps.setObject(1, "foo bar", Types.INTEGER)); | ||
| assertEquals("Conversion from type [VARCHAR] to [Integer] not supported", sqle.getMessage()); | ||
| assertEquals("Unable to convert value [foo bar] to an Integer", sqle.getMessage()); | ||
|
||
| } | ||
|
|
||
| public void testSettingByteTypeValues() throws SQLException { | ||
|
|
@@ -361,7 +361,7 @@ public Object[] getAttributes() throws SQLException { | |
| public void testSettingTimestampValues() throws SQLException { | ||
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
|
|
||
| Timestamp someTimestamp = new Timestamp(randomMillisSinceEpoch()); | ||
| Timestamp someTimestamp = new Timestamp(randomLong()); | ||
| jps.setTimestamp(1, someTimestamp); | ||
| assertEquals(someTimestamp.getTime(), ((Date)value(jps)).getTime()); | ||
| assertEquals(TIMESTAMP, jdbcType(jps)); | ||
|
|
@@ -372,7 +372,7 @@ public void testSettingTimestampValues() throws SQLException { | |
| assertEquals(1456708675000L, convertFromUTCtoCalendar(((Date)value(jps)), nonDefaultCal)); | ||
| assertEquals(TIMESTAMP, jdbcType(jps)); | ||
|
|
||
| long beforeEpochTime = -randomMillisSinceEpoch(); | ||
| long beforeEpochTime = randomLongBetween(Long.MIN_VALUE, 0); | ||
| jps.setTimestamp(1, new Timestamp(beforeEpochTime), nonDefaultCal); | ||
| assertEquals(beforeEpochTime, convertFromUTCtoCalendar(((Date)value(jps)), nonDefaultCal)); | ||
| assertTrue(value(jps) instanceof java.util.Date); | ||
|
|
@@ -384,7 +384,7 @@ public void testSettingTimestampValues() throws SQLException { | |
|
|
||
| public void testThrownExceptionsWhenSettingTimestampValues() throws SQLException { | ||
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
| Timestamp someTimestamp = new Timestamp(randomMillisSinceEpoch()); | ||
| Timestamp someTimestamp = new Timestamp(randomLong()); | ||
|
|
||
| SQLException sqle = expectThrows(SQLFeatureNotSupportedException.class, () -> jps.setObject(1, someTimestamp, Types.INTEGER)); | ||
| assertEquals("Conversion from type java.sql.Timestamp to INTEGER not supported", sqle.getMessage()); | ||
|
|
@@ -416,12 +416,12 @@ public void testThrownExceptionsWhenSettingTimeValues() throws SQLException { | |
| public void testSettingSqlDateValues() throws SQLException { | ||
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
|
|
||
| java.sql.Date someSqlDate = new java.sql.Date(randomMillisSinceEpoch()); | ||
| java.sql.Date someSqlDate = new java.sql.Date(randomLong()); | ||
| jps.setDate(1, someSqlDate); | ||
| assertEquals(someSqlDate.getTime(), ((Date)value(jps)).getTime()); | ||
| assertEquals(TIMESTAMP, jdbcType(jps)); | ||
|
|
||
| someSqlDate = new java.sql.Date(randomMillisSinceEpoch()); | ||
| someSqlDate = new java.sql.Date(randomLong()); | ||
| Calendar nonDefaultCal = randomCalendar(); | ||
| jps.setDate(1, someSqlDate, nonDefaultCal); | ||
| assertEquals(someSqlDate.getTime(), convertFromUTCtoCalendar(((Date)value(jps)), nonDefaultCal)); | ||
|
|
@@ -435,17 +435,17 @@ public void testSettingSqlDateValues() throws SQLException { | |
|
|
||
| public void testThrownExceptionsWhenSettingSqlDateValues() throws SQLException { | ||
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
| java.sql.Date someSqlDate = new java.sql.Date(randomMillisSinceEpoch()); | ||
| java.sql.Date someSqlDate = new java.sql.Date(randomLong()); | ||
|
|
||
| SQLException sqle = expectThrows(SQLFeatureNotSupportedException.class, | ||
| () -> jps.setObject(1, new java.sql.Date(randomMillisSinceEpoch()), Types.DOUBLE)); | ||
| () -> jps.setObject(1, new java.sql.Date(randomLong()), Types.DOUBLE)); | ||
| assertEquals("Conversion from type " + someSqlDate.getClass().getName() + " to DOUBLE not supported", sqle.getMessage()); | ||
| } | ||
|
|
||
| public void testSettingCalendarValues() throws SQLException { | ||
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
| Calendar someCalendar = randomCalendar(); | ||
| someCalendar.setTimeInMillis(randomMillisSinceEpoch()); | ||
| someCalendar.setTimeInMillis(randomLong()); | ||
|
|
||
| jps.setObject(1, someCalendar); | ||
| assertEquals(someCalendar.getTime(), (Date) value(jps)); | ||
|
|
@@ -472,7 +472,7 @@ public void testThrownExceptionsWhenSettingCalendarValues() throws SQLException | |
|
|
||
| public void testSettingDateValues() throws SQLException { | ||
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
| Date someDate = new Date(randomMillisSinceEpoch()); | ||
| Date someDate = new Date(randomLong()); | ||
|
|
||
| jps.setObject(1, someDate); | ||
| assertEquals(someDate, (Date) value(jps)); | ||
|
|
@@ -486,7 +486,7 @@ public void testSettingDateValues() throws SQLException { | |
|
|
||
| public void testThrownExceptionsWhenSettingDateValues() throws SQLException { | ||
| JdbcPreparedStatement jps = createJdbcPreparedStatement(); | ||
| Date someDate = new Date(randomMillisSinceEpoch()); | ||
| Date someDate = new Date(randomLong()); | ||
|
|
||
| SQLException sqle = expectThrows(SQLFeatureNotSupportedException.class, () -> jps.setObject(1, someDate, Types.BIGINT)); | ||
| assertEquals("Conversion from type " + someDate.getClass().getName() + " to BIGINT not supported", sqle.getMessage()); | ||
|
|
@@ -549,10 +549,6 @@ public void testThrownExceptionsWhenSettingByteArrayValues() throws SQLException | |
| assertEquals("Conversion from type byte[] to DOUBLE not supported", sqle.getMessage()); | ||
| } | ||
|
|
||
| private long randomMillisSinceEpoch() { | ||
| return randomLongBetween(0, System.currentTimeMillis()); | ||
| } | ||
|
|
||
| private JdbcPreparedStatement createJdbcPreparedStatement() throws SQLException { | ||
| return new JdbcPreparedStatement(null, JdbcConfiguration.create("jdbc:es://l:1", null, 0), "?"); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.qa.sql.nosecurity; | ||
|
|
||
| import org.elasticsearch.xpack.qa.sql.jdbc.ResultSetTestCase; | ||
|
|
||
| /* | ||
| * Integration testing class for "no security" (cluster running without the Security plugin, | ||
| * or the Security is disbled) scenario. Runs all tests in the base class. | ||
| */ | ||
| public class JdbcResultSetIT extends ResultSetTestCase { | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a JavaDoc here that just describes why nothing needs to be added to this class, at first glance it looks quite strange to extends a test class and not add any test or override any methods. I'm sure there is a reason but its not obvious on first looking why doing this is right
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that confuses people. The reasons for this is that we want to run the same tests in two or three very different integration clusters. We should probably update all tests like this with comments explaining it. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.qa.sql.security; | ||
|
|
||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.xpack.qa.sql.jdbc.ResultSetTestCase; | ||
|
|
||
| import java.util.Properties; | ||
|
|
||
| /* | ||
| * Integration testing class for "with security" (cluster running with the Security plugin, | ||
| * and the Security is enabled) scenario. Runs all tests in the base class, the only changed | ||
| * bit is the "environment". | ||
| */ | ||
| public class JdbcResultSetIT extends ResultSetTestCase { | ||
|
||
| @Override | ||
| protected Settings restClientSettings() { | ||
| return RestSqlIT.securitySettings(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getProtocol() { | ||
| return RestSqlIT.SSL_ENABLED ? "https" : "http"; | ||
| } | ||
|
|
||
| @Override | ||
| protected Properties connectionProperties() { | ||
| Properties sp = super.connectionProperties(); | ||
| sp.putAll(JdbcSecurityIT.adminProperties()); | ||
| return sp; | ||
| } | ||
| } | ||
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.
yikes