Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<MavenCoordinates> data() throws Exception {
return computeClientVersions(1, 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public BackwardCompatibilityIT(MavenCoordinates compatibleClientVersion) {

@Parameters(name = "BackwardCompatibilityIT_compatibleClientVersion={0}")
public static synchronized Collection<MavenCoordinates> data() throws Exception {
return computeClientVersions();
return computeClientVersions(0, 2);
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -166,6 +169,37 @@ public static List<MavenCoordinates> 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<MavenCoordinates> computeClientVersions(int shard, int shardCount)
throws Exception {
List<MavenCoordinates> versions = computeClientVersions();
List<MavenCoordinates> 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<String> cmdParams = Lists.newArrayList();
Expand All @@ -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));
Expand Down Expand Up @@ -314,8 +344,8 @@ public static void assertExpectedOutput(String result) throws Exception {
List<String> resultFile = Lists.newArrayList();
List<String> 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());
}
Expand Down Expand Up @@ -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)) {
Expand Down
Loading