Skip to content

Commit

Permalink
Fix test on incompatible client versions (#56234)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bpintea committed May 27, 2020
1 parent 819fb0e commit 47e6ee9
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.http.MockResponse;
import org.elasticsearch.xpack.sql.client.ClientVersion;
import org.elasticsearch.xpack.sql.proto.SqlVersion;

import java.io.IOException;
import java.sql.SQLException;
Expand All @@ -26,14 +27,22 @@
public class VersionParityTests extends WebServerTestCase {

public void testExceptionThrownOnIncompatibleVersions() throws IOException, SQLException {
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.CURRENT));
prepareResponse(version);

String url = JdbcConfiguration.URL_PREFIX + webServerAddress();
SQLException ex = expectThrows(SQLException.class, () -> new JdbcHttpClient(JdbcConfiguration.create(url, null, 0)));
assertEquals("This version of the JDBC driver is only compatible with Elasticsearch version " +
ClientVersion.CURRENT.majorMinorToString() + " or newer; attempting to connect to a server " +
"version " + version.toString(), ex.getMessage());
Version firstVersion = VersionUtils.getFirstVersion();
Version version = Version.V_7_7_0;
do {
version = VersionUtils.getPreviousVersion(version);
logger.info("Checking exception is thrown for version {}", version);

prepareResponse(version);
// Client's version is wired up to patch level, excluding the qualifier => generate the test version as the server does it.
String versionString = SqlVersion.fromString(version.toString()).toString();

SQLException ex = expectThrows(SQLException.class, () -> new JdbcHttpClient(JdbcConfiguration.create(url, null, 0)));
assertEquals("This version of the JDBC driver is only compatible with Elasticsearch version " +
ClientVersion.CURRENT.majorMinorToString() + " or newer; attempting to connect to a server " +
"version " + versionString, ex.getMessage());
} while (version.compareTo(firstVersion) > 0);
}

public void testNoExceptionThrownForCompatibleVersions() throws IOException {
Expand Down

0 comments on commit 47e6ee9

Please sign in to comment.