|
13 | 13 | import org.elasticsearch.test.VersionUtils;
|
14 | 14 | import org.elasticsearch.test.http.MockResponse;
|
15 | 15 | import org.elasticsearch.xpack.sql.client.ClientVersion;
|
| 16 | +import org.elasticsearch.xpack.sql.proto.SqlVersion; |
16 | 17 |
|
17 | 18 | import java.io.IOException;
|
18 | 19 | import java.sql.SQLException;
|
|
26 | 27 | public class VersionParityTests extends WebServerTestCase {
|
27 | 28 |
|
28 | 29 | public void testExceptionThrownOnIncompatibleVersions() throws IOException, SQLException {
|
29 |
| - Version version = VersionUtils.randomVersionBetween(random(), null, VersionUtils.getPreviousVersion(Version.V_7_7_0)); |
30 |
| - logger.info("Checking exception is thrown for version {}", version); |
31 |
| - prepareResponse(version); |
32 |
| - |
33 | 30 | String url = JdbcConfiguration.URL_PREFIX + webServerAddress();
|
34 |
| - SQLException ex = expectThrows(SQLException.class, () -> new JdbcHttpClient(JdbcConfiguration.create(url, null, 0))); |
35 |
| - assertEquals("This version of the JDBC driver is only compatible with Elasticsearch version " + |
36 |
| - ClientVersion.CURRENT.majorMinorToString() + " or newer; attempting to connect to a server " + |
37 |
| - "version " + version.toString(), ex.getMessage()); |
| 31 | + Version firstVersion = VersionUtils.getFirstVersion(); |
| 32 | + Version version = Version.V_7_7_0; |
| 33 | + do { |
| 34 | + version = VersionUtils.getPreviousVersion(version); |
| 35 | + logger.info("Checking exception is thrown for version {}", version); |
| 36 | + |
| 37 | + prepareResponse(version); |
| 38 | + // Client's version is wired up to patch level, excluding the qualifier => generate the test version as the server does it. |
| 39 | + String versionString = SqlVersion.fromString(version.toString()).toString(); |
| 40 | + |
| 41 | + SQLException ex = expectThrows(SQLException.class, () -> new JdbcHttpClient(JdbcConfiguration.create(url, null, 0))); |
| 42 | + assertEquals("This version of the JDBC driver is only compatible with Elasticsearch version " + |
| 43 | + ClientVersion.CURRENT.majorMinorToString() + " or newer; attempting to connect to a server " + |
| 44 | + "version " + versionString, ex.getMessage()); |
| 45 | + } while (version.compareTo(firstVersion) > 0); |
38 | 46 | }
|
39 | 47 |
|
40 | 48 | public void testNoExceptionThrownForCompatibleVersions() throws IOException {
|
|
0 commit comments