Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test framework healthy container check. #816

Merged
merged 15 commits into from
Jan 6, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class SiddhiRunnerContainer extends GenericContainer<SiddhiRunnerContaine
private static final String OVERRIDE_CONF_SYSTEM_PARAMETER = "-Dconfig";
private static final String DEPLOY_APP_SYSTEM_PARAMETER = "-Dapps";
private static final String BLANK_SPACE = " ";
private static File SIDDHI_APPS = null;
private List<Integer> portsToExpose = new ArrayList<>(defaultExposePorts);
private String initScriptPath = "/home/siddhi_user/init.sh";
private StringBuilder initCommand = new StringBuilder(initScriptPath);
Expand Down Expand Up @@ -137,10 +138,10 @@ public SiddhiRunnerContainer withConfig(String confPath) {
* @return self
*/
public SiddhiRunnerContainer withSiddhiApps(String deploymentDirectory) {
File siddhiApps = new File(deploymentDirectory);
SIDDHI_APPS = new File(deploymentDirectory);
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
String deploymentPath = DEPLOYMENT_DIRECTORY;
if (!siddhiApps.isDirectory()) {
deploymentPath = DEPLOYMENT_DIRECTORY.concat(File.pathSeparator).concat(siddhiApps.getName());
if (!SIDDHI_APPS.isDirectory()) {
deploymentPath = DEPLOYMENT_DIRECTORY.concat(File.pathSeparator).concat(SIDDHI_APPS.getName());
}
withFileSystemBind(deploymentDirectory, deploymentPath, BindMode.READ_ONLY);
initCommand.append(BLANK_SPACE).append(DEPLOY_APP_SYSTEM_PARAMETER).append("=").append(DEPLOYMENT_DIRECTORY);
Expand All @@ -150,7 +151,7 @@ public SiddhiRunnerContainer withSiddhiApps(String deploymentDirectory) {
/**
* Mounts the provided JARs in the Siddhi Runner's classpath.
*
* @param jarPath Absolute path of the extra JAR file/directory
* @param jarPath Absolute path of the extra JAR file/directory
* @param isBundle Flag representing whether the file/directory contains bundles
* @return self
*/
Expand Down Expand Up @@ -187,7 +188,7 @@ private void mountJarFile(String jarPath, boolean isBundle) {
}
}

private void mountFile (String sourcePath, String outputPath) {
private void mountFile(String sourcePath, String outputPath) {
int mountMode = 444;
MountableFile mountableFile = MountableFile.forHostPath(sourcePath,
mountMode);
Expand All @@ -209,18 +210,42 @@ private int getStartupTimeoutSeconds() {
@Override
protected void waitUntilContainerStarted() {
logger().info("Waiting for Siddhi Runner Container to start...");
retryUntilSuccess(getStartupTimeoutSeconds(), TimeUnit.SECONDS, () -> {
if (!isRunning()) {
throw new ContainerLaunchException("Siddhi Runner Container failed to start");
}
HTTPClient.HTTPResponseMessage httpResponseMessage = callHealthAPI();
if (httpResponseMessage.getResponseCode() == 200) {
logger().info("Siddhi Runner Health API reached successfully.");
return null;
} else {
throw new ConnectException("Failed to connect with the Siddhi Runner health API");
if (SIDDHI_APPS != null) {
String[] siddhiApps = SIDDHI_APPS.list();
for (String siddhiApp : siddhiApps) {
String fileName = siddhiApp.substring(0, siddhiApp.length() - 7);
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
retryUntilSuccess(getStartupTimeoutSeconds(), TimeUnit.SECONDS, () -> {
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
if (!isRunning()) {
throw new ContainerLaunchException("Siddhi Runner Container failed to start");
}
HTTPClient.HTTPResponseMessage httpResponseMessage = callHealthAPI();
if (httpResponseMessage.getResponseCode() == 200) {
String logs = this.getLogs();
if (logs.contains("Siddhi App " + fileName + " deployed successfully")) {
logger().info("Siddhi Runner Health API reached successfully.");
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
} else {
throw new Exception("Siddhi App AppDeploymentTestResource deployment failed.");
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
}
return null;
} else {
throw new ConnectException("Failed to connect with the Siddhi Runner health API");
}
});
}
});
} else {
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
retryUntilSuccess(getStartupTimeoutSeconds(), TimeUnit.SECONDS, () -> {
if (!isRunning()) {
throw new ContainerLaunchException("Siddhi Runner Container failed to start");
}
HTTPClient.HTTPResponseMessage httpResponseMessage = callHealthAPI();
if (httpResponseMessage.getResponseCode() == 200) {
logger().info("Siddhi Runner Health API reached successfully.");
return null;
} else {
throw new ConnectException("Failed to connect with the Siddhi Runner health API");
}
});
}
}

private HTTPClient.HTTPResponseMessage callHealthAPI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class TemperatureAlertAppTest {
private NatsClient natsClient;
private WaitingConsumer siddhiLogConsumer = new WaitingConsumer();

private static final String DATABSE_NAME = "TemperaureDB";
private static final String DATABSE_NAME = "TemperatureDB";
private static final String DATABSE_HOST = "mysqldb";
private static final String NATS_CLUSTER_ID = "TemperatureCluster";
private static final String NATS_CLUSTER_HOST = "nats-streaming";
Expand Down Expand Up @@ -200,7 +200,6 @@ public void testDBPersistence() throws SQLException, InterruptedException, IOExc
"}");
ResultSet resultSet = null;
try {
Thread.sleep(1000);
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
resultSet = DatabaseClient.executeQuery(mySQLContainer, "SELECT * FROM InternalDevicesTempTable");
Assert.assertNotNull(resultSet);
Assert.assertEquals("C250i", resultSet.getString(2));
Expand Down