Skip to content

Commit

Permalink
Standalone Upgrade Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo authored and tlbueno committed Sep 19, 2024
1 parent 76fbfef commit 7cd3897
Show file tree
Hide file tree
Showing 27 changed files with 993 additions and 92 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ operator-suite/container/scripts/run-test.sh --help
| COLLECT_TEST_DATA | Whether to gather test data on error or not | `true` | `true`, `false` |
| TESTS | Which tests to execute (maven syntax) | not set | <mvn-regexp> |

## More information
For more information about subprojects - refer to README.md files in `operator-suite` or `standalone-suite` folders, which contain more details about usage, more environment variables, etc.

## Hints
- keep code clean
14 changes: 14 additions & 0 deletions common/src/main/java/io/brokerqe/claire/ArtemisConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ public interface ArtemisConstants {


// Log Strings
static String getArtemisVersionString(String version) {
// Red Hat AMQ Broker 7.11.1.GA
return String.format("Red Hat AMQ Broker %s.GA", version);
}

static String getArtemisVersionStringOld(String version) {
// Red Hat AMQ 7.10.1.GA
return String.format("Red Hat AMQ %s.GA", version);
}

static String getArtemisStartingServerVersionString(String version) {
return String.format("Starting ActiveMQ Artemis Server version %s", version);
}

String IS_LIVE_LOG_MSG = " INFO [org.apache.activemq.artemis.core.server] AMQ221007: Server is now";
String USING_CUSTOM_LOG_MSG = "There is a custom logger configuration defined in JAVA_ARGS_APPEND: -Dlog4j2.configurationFile=";
String USING_DEFAULT_LOG_MSG = "Using default logging configuration(console only)";
Expand Down
7 changes: 5 additions & 2 deletions common/src/main/java/io/brokerqe/claire/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface Constants {
// Platform related strings
String LINE_SEPARATOR = System.getProperty("line.separator");
String FILE_SEPARATOR = System.getProperty("file.separator");
String TMP_DIR_SYSTEM = System.getProperty("java.io.tmpdir");
String DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss";

// Test tags
Expand Down Expand Up @@ -70,7 +71,9 @@ public interface Constants {

// Networking
String AMQP = "amqp";
String TCP = "tcp";
String AMQP_URL_PREFIX = AMQP + "://";
String TCP_URL_PREFIX = TCP + "://";
String HTTP = "http";
String HTTPS = "https";
String GET = "GET";
Expand Down Expand Up @@ -146,8 +149,8 @@ public interface Constants {

String ARTEMIS_DEFAULT_CFG_DIR = "artemis/artemis_default_cfg";
String ARTEMIS_TEST_CFG_DIR = "test-cfg";
String ARTEMIS_DEFAULT_CFG_BIN_DIR = ARTEMIS_DEFAULT_CFG_DIR + FILE_SEPARATOR + ArtemisConstants.BIN_DIR;
String ARTEMIS_DEFAULT_CFG_LIB_DIR = ARTEMIS_DEFAULT_CFG_DIR + FILE_SEPARATOR + ArtemisConstants.LIB_DIR;
String ARTEMIS_DEFAULT_CFG_BIN_DIR = ARTEMIS_DEFAULT_CFG_DIR + ArtemisConstants.BIN_DIR;
String ARTEMIS_DEFAULT_CFG_LIB_DIR = ARTEMIS_DEFAULT_CFG_DIR + ArtemisConstants.LIB_DIR;

String PREFIX_SYSTEMTESTS_CLIENTS = "systemtests-clients";
String PREFIX_SYSTEMTESTS_CLI_PROTON_DOTNET = "systemtests-cli-proton-dotnet";
Expand Down
11 changes: 10 additions & 1 deletion common/src/main/java/io/brokerqe/claire/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public String getCertificatesLocation() {

static final Logger LOGGER = LoggerFactory.getLogger(Environment.class);
protected String databaseFile;
protected String testUpgradePlan;
private Database database;
private static Environment environment;
private Properties appProperties;
Expand All @@ -62,7 +63,15 @@ public String getJdbcDatabaseFile() {
return databaseFile;
}

protected ArtemisVersion convertArtemisVersion(String version) {
public String getTestUpgradePlanContent() {
if (testUpgradePlan != null) {
return TestUtils.readFileContent(new File(testUpgradePlan));
} else {
throw new IllegalArgumentException(Constants.EV_UPGRADE_PLAN + " variable has not been set!");
}
}

public ArtemisVersion convertArtemisVersion(String version) {
ArtemisVersion versionRet;
if (isUpstreamArtemis()) {
return ArtemisVersion.values()[ArtemisVersion.values().length - 1];
Expand Down
85 changes: 85 additions & 0 deletions common/src/main/java/io/brokerqe/claire/LocalExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright Strimzi and Broker QE authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.brokerqe.claire;

import io.brokerqe.claire.exception.ClaireNotImplementedException;
import io.brokerqe.claire.executor.Executor;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.Duration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;


public class LocalExecutor implements Executor {

private String commandDataOutput;
private int exitCode;
@Override
public Object executeCommand(String... cmd) {
return executeCommand(Duration.ofSeconds(60).toSeconds(), cmd);
}

@Override
public Object executeCommand(long maxExecMs, String... cmd) {
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.directory(new File(System.getProperty("user.home")));
try {
Process process = builder.start();
StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), System.out::println);
streamGobbler.run();

ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(streamGobbler);
exitCode = process.waitFor();
executor.shutdown();
commandDataOutput = streamGobbler.toString();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}

return exitCode;
}

@Override
public void execBackgroundCommand(String... cmd) {
throw new ClaireNotImplementedException("Not implemented yet");
}

@Override
public boolean isBackgroundCommandFinished() {
throw new ClaireNotImplementedException("Not implemented yet");
}

@Override
public String getBackgroundCommandData(int waitTime) {
throw new ClaireNotImplementedException("Not implemented yet");
}

@Override
public String getCommandData(long timeout) {
return commandDataOutput;
}
}

class StreamGobbler implements Runnable {
private InputStream inputStream;
private Consumer<String> consumer;

public StreamGobbler(InputStream inputStream, Consumer<String> consumer) {
this.inputStream = inputStream;
this.consumer = consumer;
}

@Override
public void run() {
new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumer);
}
}
72 changes: 69 additions & 3 deletions common/src/main/java/io/brokerqe/claire/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -62,7 +63,9 @@
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
Expand All @@ -83,6 +86,21 @@ public static Path getProjectRelativeFilePath(String projectRelativeFile) {
return Paths.get(Constants.PROJECT_USER_DIR, projectRelativeFile).toAbsolutePath();
}

// ========== Execute command Operations ==========

public static String executeLocalCommand(String cmd) {
return executeLocalCommand(cmd.split(" "));
}

public static String executeLocalCommand(String... cmd) {
LocalExecutor executor = new LocalExecutor();
LOGGER.debug("[CMD][local] {}", Arrays.stream(cmd).toArray());
executor.executeCommand(cmd);
String output = executor.getCommandData(Duration.ofSeconds(10).toSeconds());
LOGGER.debug("[CMD][local] Output\n{}", output);
return output;
}

// ========== Junit Test Operations ==========
public static String getClassName(ExtensionContext extensionContext) {
return extensionContext.getRequiredTestClass().getName();
Expand Down Expand Up @@ -312,9 +330,12 @@ public static String getElementByXpathFromXml(String elementXPathExpression, Fil
// ========== Network Operations ==========
public static void getFileFromUrl(String stringUrl, String outputFile) {
if (!Files.exists(Paths.get(outputFile))) {
LOGGER.debug("Downloading {} to {}", stringUrl, outputFile);
LOGGER.debug("[Download] {} to {}", stringUrl, outputFile);
try {
URL url = new URL(stringUrl);
if (stringUrl.startsWith("https")) {
makeInsecureHttpsRequest(stringUrl);
}
ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
Expand Down Expand Up @@ -470,6 +491,34 @@ public static void copyDirectoryFlat(String source, String target) {
}
}

public static void copyDirectories(String source, String target) {
try {
Path sourceDir = Paths.get(source);
Path targetDir = Paths.get(target);
LOGGER.debug("[Copy] Recursively {} -> {}", source, target);
Files.walk(sourceDir)
.forEach(sourcePath -> {
try {
Path targetPath = targetDir.resolve(sourceDir.relativize(sourcePath));
Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void moveDirectory(String srcDir, String newDir) {
try {
LOGGER.debug("[Move] {} -> {}", srcDir, newDir);
FileUtils.moveDirectory(new File(srcDir), new File(newDir));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void copyFile(String source, String target) {
try {
Files.copy(Path.of(source), Path.of(target), StandardCopyOption.REPLACE_EXISTING);
Expand All @@ -488,8 +537,24 @@ public static Path findFile(String directory, String filename) {
}
}

public static String replaceFileContent(String filePath, String toReplace, String replaceWith) {
String newFilePath = filePath + "_tmpFile" + TestUtils.getRandomString(3);
public static List<Path> searchForGlobFile(String directory, String globPattern, int maxDepth) {
List<Path> paths;
try {
paths = Files.find(Paths.get(directory), maxDepth, (path, attr) -> {
LOGGER.debug(path.toString());
return FileSystems.getDefault().getPathMatcher(globPattern).matches(path);
}).toList();
} catch (IOException e) {
throw new RuntimeException(e);
}
return paths;
}

public static String replaceFileContent(String filePath, String toReplace, String replaceWith, boolean inPlace) {
String newFilePath = filePath;
if (!inPlace) {
newFilePath += "_tmpFile" + TestUtils.getRandomString(3);
}
String data = readFileContent(new File(filePath));
data = data.replace(toReplace, replaceWith);
TestUtils.createFile(newFilePath, data);
Expand Down Expand Up @@ -560,6 +625,7 @@ public static void unTar(final String inputFile, final String outputDir) {

public static void unzip(String archivePath, String unarchivePath) {
try {
LOGGER.debug("[Unzip] {} -> {}", archivePath, unarchivePath);
new ZipFile(Paths.get(archivePath).toFile()).extractAll(unarchivePath);
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/io/brokerqe/claire/clients/Protocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Broker QE authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.brokerqe.claire.clients;

public enum Protocol {
AMQP,
AMQPS,
CORE,
CORES
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*/
package io.brokerqe.claire.clients.bundled;

import io.brokerqe.claire.clients.Protocol;

import java.util.Locale;

public class BundledAmqpMessagingClient extends BundledMessagingClient {

public BundledAmqpMessagingClient(BundledClientOptions options) {
Expand All @@ -12,6 +16,6 @@ public BundledAmqpMessagingClient(BundledClientOptions options) {

@Override
String getProtocol() {
return "amqp";
return Protocol.AMQP.name().toLowerCase(Locale.ROOT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.brokerqe.claire.clients.bundled;

import io.brokerqe.claire.clients.DeployableClient;
import io.brokerqe.claire.clients.Protocol;

public class BundledClientOptions {
DeployableClient deployableClient;
Expand All @@ -18,6 +19,7 @@ public class BundledClientOptions {
String password;
Boolean persistenceDisabled = false;
Boolean multicast = false;
Protocol protocol;

public BundledClientOptions withDeployableClient(DeployableClient deployableClient) {
this.deployableClient = deployableClient;
Expand Down Expand Up @@ -66,6 +68,54 @@ public BundledClientOptions withPersistenceDisabled(Boolean persistenceDisabled)
public BundledClientOptions withMulticast(Boolean multicast) {
this.multicast = multicast;
return this;
}

public BundledClientOptions withProtocol(Protocol protocol) {
this.protocol = protocol;
return this;
}

public DeployableClient getDeployableClient() {
return deployableClient;
}

public String getDestinationUrl() {
return destinationUrl;
}

public String getDestinationPort() {
return destinationPort;
}

public String getDestinationAddress() {
return destinationAddress;
}

public String getDestinationQueue() {
return destinationQueue;
}

public int getMessageCount() {
return messageCount;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public Boolean getPersistenceDisabled() {
return persistenceDisabled;
}

public Boolean getMulticast() {
return multicast;
}

public Protocol getProtocol() {
return protocol;
}
}
Loading

0 comments on commit 7cd3897

Please sign in to comment.