Skip to content

Commit

Permalink
Disable RemotePreparedStatementParametersTest on JDK 23 or higher
Browse files Browse the repository at this point in the history
Add class Version
  • Loading branch information
julianhyde committed Sep 18, 2024
1 parent 28a9c72 commit ddc741e
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.calcite.test.schemata.hr.Employee;
import org.apache.calcite.util.TestUtil;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.Version;

import com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -82,7 +83,7 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import static java.util.Objects.requireNonNull;

Expand All @@ -107,9 +108,8 @@ class CalciteRemoteDriverTest {
private static @Nullable HttpServer start;

@BeforeAll public static void beforeClass() throws Exception {
assumeTrue(TestUtil.getJavaMajorVersion() < 23
|| (TestUtil.AVATICA_VERSION != null
&& TestUtil.AVATICA_VERSION.compareTo("1.25.0") > 0),
assumeFalse(TestUtil.getJavaMajorVersion() >= 23
&& TestUtil.AVATICA_VERSION.compareTo(Version.of(1, 25)) > 0,
"Cannot run on JDK 23 and higher with Avatica version 1.25 or lower; "
+ "enable when [CALCITE-6588] is fixed in Avatica");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@
*/
package org.apache.calcite.chinook;

import org.apache.calcite.util.TestUtil;
import org.apache.calcite.util.Version;

import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import static org.junit.jupiter.api.Assumptions.assumeFalse;

/**
* Tests against parameters in prepared statement when using underlying JDBC
* sub-schema.
*/
class RemotePreparedStatementParametersTest {

@Test void testSimpleStringParameterShouldWorkWithCalcite() throws Exception {
assumeFalse(TestUtil.getJavaMajorVersion() >= 23
&& TestUtil.AVATICA_VERSION.compareTo(Version.of(1, 25)) > 0,
"Cannot run on JDK 23 and higher with Avatica version 1.25 or lower; "
+ "enable when [CALCITE-6588] is fixed in Avatica");

// given
ChinookAvaticaServer server = new ChinookAvaticaServer();
server.startWithCalcite();
Expand All @@ -44,6 +54,11 @@ class RemotePreparedStatementParametersTest {
}

@Test void testSeveralParametersShouldWorkWithCalcite() throws Exception {
assumeFalse(TestUtil.getJavaMajorVersion() >= 23
&& TestUtil.AVATICA_VERSION.compareTo(Version.of(1, 25)) > 0,
"Cannot run on JDK 23 and higher with Avatica version 1.25 or lower; "
+ "enable when [CALCITE-6588] is fixed in Avatica");

// given
ChinookAvaticaServer server = new ChinookAvaticaServer();
server.startWithCalcite();
Expand All @@ -60,6 +75,11 @@ class RemotePreparedStatementParametersTest {
}

@Test void testParametersShouldWorkWithRaw() throws Exception {
assumeFalse(TestUtil.getJavaMajorVersion() >= 23
&& TestUtil.AVATICA_VERSION.compareTo(Version.of(1, 25)) > 0,
"Cannot run on JDK 23 and higher with Avatica version 1.25 or lower; "
+ "enable when [CALCITE-6588] is fixed in Avatica");

// given
ChinookAvaticaServer server = new ChinookAvaticaServer();
server.startWithRaw();
Expand Down
7 changes: 5 additions & 2 deletions testkit/src/main/java/org/apache/calcite/util/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.apache.calcite.util.Util.first;

import static org.junit.jupiter.api.Assertions.fail;

import static java.lang.Integer.parseInt;
Expand All @@ -55,8 +57,9 @@ public abstract class TestUtil {
private static final String JAVA_VERSION =
System.getProperties().getProperty("java.version");

public static final String AVATICA_VERSION =
System.getProperty("calcite.avatica.version");
public static final Version AVATICA_VERSION =
Version.of(first(System.getProperty("calcite.avatica.version"), "0"));

private static final Supplier<Integer> GUAVA_MAJOR_VERSION =
Suppliers.memoize(TestUtil::computeGuavaMajorVersion);

Expand Down
65 changes: 65 additions & 0 deletions testkit/src/main/java/org/apache/calcite/util/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.calcite.util;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;

import java.util.ArrayList;
import java.util.List;

import static java.lang.Integer.parseInt;

/**
* Version string parsed into major and minor parts.
*/
public class Version implements Comparable<Version> {
private static final Ordering<Iterable<Integer>> ORDERING =
Ordering.<Integer>natural().lexicographical();

public final List<Integer> integers;
public final String string;

/** Private constructor. */
private Version(List<Integer> integers, String string) {
this.integers = ImmutableList.copyOf(integers);
this.string = string;
}

/** Creates a Version by parsing a string. */
public static Version of(String s) {
final String[] strings = s.split("[.-]");
List<Integer> integers = new ArrayList<>();
for (String string : strings) {
try {
integers.add(parseInt(string));
} catch (NumberFormatException e) {
break;
}
}
return new Version(integers, s);
}

/** Creates a Version from a sequence of integers. */
public static Version of(int... integers) {
return new Version(ImmutableIntList.copyOf(integers), "");
}

@Override public int compareTo(Version version) {
return ORDERING.compare(this.integers, version.integers);
}
}
47 changes: 47 additions & 0 deletions testkit/src/test/java/org/apache/calcite/util/TestUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.hasToString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -101,6 +104,50 @@ private void testJavaVersion(int expectedMajorVersion, String versionString) {
versionString);
}

/** Unit test for {@link Version}. */
@SuppressWarnings("EqualsWithItself")
@Test void testVersion() {
Version vEmpty = Version.of("");
assertThat(vEmpty.integers, empty());
assertThat(vEmpty.string, emptyString());

final Version v1 = Version.of("1");
assertThat(v1.integers, hasSize(1));
assertThat(v1.integers, hasToString("[1]"));

final Version v1_8_3 = Version.of("1.8.3-jre"); // "-jre" is ignored
assertThat(v1_8_3.integers, hasSize(3));
assertThat(v1_8_3.integers, hasToString("[1, 8, 3]"));
assertThat(v1_8_3.string, is("1.8.3-jre"));

final Version v1_19 = Version.of("1.19");
assertThat(v1_19.integers, hasSize(2));
assertThat(v1_19.integers, hasToString("[1, 19]"));

final Version v1_23 = Version.of("1.23");
assertThat(v1_23.integers, hasSize(2));
assertThat(v1_23.integers, hasToString("[1, 23]"));

final Version v1_23_0 = Version.of("1.23.0");
assertThat(v1_23_0.integers, hasSize(3));
assertThat(v1_23_0.integers, hasToString("[1, 23, 0]"));

final Version v1_23_1 = Version.of("1.23.1");
assertThat(v1_23_1.integers, hasSize(3));
assertThat(v1_23_1.integers, hasToString("[1, 23, 1]"));

// 1 < 1.8.3 < 1.19 < 1.23 < 1.23.0 < 1.23.1
assertThat(vEmpty.compareTo(v1), is(-1));
assertThat(v1.compareTo(v1_23), is(-1));
assertThat(v1_8_3.compareTo(v1_19), is(-1));
assertThat(v1_19.compareTo(v1_23), is(-1));
assertThat(v1_23.compareTo(v1_23_0), is(-1));
assertThat(v1_23_0.compareTo(v1_23_1), is(-1));
assertThat(v1_23_1.compareTo(v1), is(1));

assertThat(v1.compareTo(v1), is(0));
}

@Test void testGuavaMajorVersion() {
int majorVersion = TestUtil.getGuavaMajorVersion();
assertTrue(majorVersion >= 2,
Expand Down

0 comments on commit ddc741e

Please sign in to comment.