From 4bbd2d448a27764f36e246dd82c7612476778110 Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Tue, 24 Nov 2026 18:35:13 -0800 Subject: [PATCH] PHOENIX-8083 Split BackwardCompatibilityIT by client version BackwardCompatibilityIT runs close to the 7200 second fork timeout in CI. BackwardCompatibilityIT now runs the first half of the compatible client versions. The new BackwardCompatibility2IT runs the other half in a separate fork. Each test JVM now writes its result files to its own directory. Thus the two classes do not overwrite the result files of each other in parallel forks. BackwardCompatibilityForSplittableSyscatIT still runs all client versions. Co-Authored-By: Claude Opus 5.5 --- .../end2end/BackwardCompatibility2IT.java | 45 +++++++++++++++++ .../end2end/BackwardCompatibilityIT.java | 2 +- .../BackwardCompatibilityTestUtil.java | 50 ++++++++++++++----- 3 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibility2IT.java diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibility2IT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibility2IT.java new file mode 100644 index 00000000000..bb6e2071bfe --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibility2IT.java @@ -0,0 +1,45 @@ +/* + * 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.phoenix.end2end; + +import static org.apache.phoenix.end2end.BackwardCompatibilityTestUtil.computeClientVersions; + +import java.util.Collection; +import org.apache.phoenix.end2end.BackwardCompatibilityTestUtil.MavenCoordinates; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Runs the tests of BackwardCompatibilityIT with the other half of the compatible client versions. + * The split keeps each test class within the fork timeout. + */ +@RunWith(Parameterized.class) +@Category(NeedsOwnMiniClusterTest.class) +public class BackwardCompatibility2IT extends BackwardCompatibilityIT { + + public BackwardCompatibility2IT(MavenCoordinates compatibleClientVersion) { + super(compatibleClientVersion); + } + + @Parameters(name = "BackwardCompatibility2IT_compatibleClientVersion={0}") + public static synchronized Collection data() throws Exception { + return computeClientVersions(1, 2); + } +} diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityIT.java index a2487cd7789..26573093759 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityIT.java @@ -108,7 +108,7 @@ public BackwardCompatibilityIT(MavenCoordinates compatibleClientVersion) { @Parameters(name = "BackwardCompatibilityIT_compatibleClientVersion={0}") public static synchronized Collection data() throws Exception { - return computeClientVersions(); + return computeClientVersions(0, 2); } @Before diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityTestUtil.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityTestUtil.java index 8f434185edc..55ee9faac1a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityTestUtil.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BackwardCompatibilityTestUtil.java @@ -33,6 +33,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; @@ -117,6 +118,8 @@ public final class BackwardCompatibilityTestUtil { public static final String JAVA_TMP_DIR = "java.io.tmpdir"; public static final String JAVA_HOME = "java.home"; + private static File resultDir; + public enum UpgradeProps { NONE, SET_MAX_LOOK_BACK_AGE @@ -166,6 +169,37 @@ public static List computeClientVersions() throws Exception { return result; } + /** + * Returns every shardCount-th client version, from index shard. Test classes use this to split + * the client versions between them. + */ + public static List computeClientVersions(int shard, int shardCount) + throws Exception { + List versions = computeClientVersions(); + List result = new ArrayList<>(); + for (int i = shard; i < versions.size(); i += shardCount) { + result.add(versions.get(i)); + } + return result; + } + + // Each test JVM writes its result files to its own directory. Thus test classes that run in + // parallel forks do not overwrite the result files of each other. + private static synchronized File getResultDir() throws IOException { + if (resultDir == null) { + URL fileUrl = + BackwardCompatibilityIT.class.getClassLoader().getResource(RESULTS_AND_GOLD_FILES_DIR); + assertNotNull(fileUrl); + resultDir = + Files.createTempDirectory(new File(fileUrl.getFile()).toPath(), RESULT_PREFIX).toFile(); + } + return resultDir; + } + + private static String getResultFilePath(String operation) throws IOException { + return new File(getResultDir(), RESULT_PREFIX + operation + TEXT_EXTENSION).getAbsolutePath(); + } + public static void executeQueryWithClientVersionGroup(ClientVersionGroup clientVersionGroup, String operation, String zkQuorum) throws Exception { List cmdParams = Lists.newArrayList(); @@ -185,11 +219,7 @@ public static void executeQueryWithClientVersionGroup(ClientVersionGroup clientV .getResource(SQL_DIR + operation + SQL_EXTENSION); assertNotNull(fileUrl); cmdParams.add(new File(fileUrl.getFile()).getAbsolutePath()); - fileUrl = - BackwardCompatibilityIT.class.getClassLoader().getResource(RESULTS_AND_GOLD_FILES_DIR); - assertNotNull(fileUrl); - String resultFilePath = new File(fileUrl.getFile()).getAbsolutePath() + "/" + RESULT_PREFIX - + operation + TEXT_EXTENSION; + String resultFilePath = getResultFilePath(operation); cmdParams.add(resultFilePath); cmdParams.add(System.getProperty(JAVA_TMP_DIR)); cmdParams.add(System.getProperty(JAVA_HOME)); @@ -314,8 +344,8 @@ public static void assertExpectedOutput(String result) throws Exception { List resultFile = Lists.newArrayList(); List goldFile = Lists.newArrayList(); String line; - try (BufferedReader resultFileReader = getBufferedReaderForResource( - RESULTS_AND_GOLD_FILES_DIR + RESULT_PREFIX + result + TEXT_EXTENSION)) { + try (BufferedReader resultFileReader = + new BufferedReader(new FileReader(getResultFilePath(result)))) { while ((line = resultFileReader.readLine()) != null) { resultFile.add(line.trim()); } @@ -370,11 +400,7 @@ public static void executeQueriesWithCurrentVersion(String operation, String url ResultSet rs; String[] sqlCommands = sb.toString().split(";"); - URL fileUrl = - BackwardCompatibilityIT.class.getClassLoader().getResource(RESULTS_AND_GOLD_FILES_DIR); - assertNotNull(fileUrl); - final String resultFile = new File(fileUrl.getFile()).getAbsolutePath() + "/" + RESULT_PREFIX - + operation + TEXT_EXTENSION; + final String resultFile = getResultFilePath(operation); try (BufferedWriter br = new BufferedWriter(new FileWriter(resultFile))) { for (String command : sqlCommands) { try (PreparedStatement stmt = conn.prepareStatement(command)) {