Skip to content

Commit 4a81c8f

Browse files
authored
Fix test on incompatible client versions (#56234)
The incomatible client version test is changed to: - iterate on all versions prior to the allowed one_s; - format the exception message just as the server does it. The defect stemed from the fact that the clients will not send a version's qualifier, but just major.minor.revision, so the raised error/exception_message won't contain it, while the test expected it.
1 parent 80f5032 commit 4a81c8f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/VersionParityTests.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.test.VersionUtils;
1414
import org.elasticsearch.test.http.MockResponse;
1515
import org.elasticsearch.xpack.sql.client.ClientVersion;
16+
import org.elasticsearch.xpack.sql.proto.SqlVersion;
1617

1718
import java.io.IOException;
1819
import java.sql.SQLException;
@@ -26,15 +27,22 @@
2627
public class VersionParityTests extends WebServerTestCase {
2728

2829
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-
3330
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);
3846
}
3947

4048
public void testNoExceptionThrownForCompatibleVersions() throws IOException {

0 commit comments

Comments
 (0)