Skip to content

Commit 47e6ee9

Browse files
committed
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. (cherry picked from commit 4a81c8f)
1 parent 819fb0e commit 47e6ee9

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

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

+16-7
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,14 +27,22 @@
2627
public class VersionParityTests extends WebServerTestCase {
2728

2829
public void testExceptionThrownOnIncompatibleVersions() throws IOException, SQLException {
29-
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.CURRENT));
30-
prepareResponse(version);
31-
3230
String url = JdbcConfiguration.URL_PREFIX + webServerAddress();
33-
SQLException ex = expectThrows(SQLException.class, () -> new JdbcHttpClient(JdbcConfiguration.create(url, null, 0)));
34-
assertEquals("This version of the JDBC driver is only compatible with Elasticsearch version " +
35-
ClientVersion.CURRENT.majorMinorToString() + " or newer; attempting to connect to a server " +
36-
"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);
3746
}
3847

3948
public void testNoExceptionThrownForCompatibleVersions() throws IOException {

0 commit comments

Comments
 (0)