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 localDeploymentDirectory = 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,16 +138,20 @@ public SiddhiRunnerContainer withConfig(String confPath) {
* @return self
*/
public SiddhiRunnerContainer withSiddhiApps(String deploymentDirectory) {
File siddhiApps = new File(deploymentDirectory);
setLocalDeploymentDirectory(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 (!localDeploymentDirectory.isDirectory()) {
deploymentPath = DEPLOYMENT_DIRECTORY.concat(File.pathSeparator).concat(localDeploymentDirectory.getName());
}
withFileSystemBind(deploymentDirectory, deploymentPath, BindMode.READ_ONLY);
initCommand.append(BLANK_SPACE).append(DEPLOY_APP_SYSTEM_PARAMETER).append("=").append(DEPLOYMENT_DIRECTORY);
return this;
}

public static void setLocalDeploymentDirectory(String deploymentDirectory) {
localDeploymentDirectory = new File(deploymentDirectory);
}

/**
* Mounts the provided JARs in the Siddhi Runner's classpath.
*
Expand Down Expand Up @@ -187,7 +192,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,12 +214,33 @@ private int getStartupTimeoutSeconds() {
@Override
protected void waitUntilContainerStarted() {
logger().info("Waiting for Siddhi Runner Container to start...");
if (localDeploymentDirectory != null) {
String[] siddhiAppsArray = localDeploymentDirectory.list();
if (siddhiAppsArray != null) {
for (String siddhiApp : siddhiAppsArray) {
String fileName = siddhiApp.substring(0, siddhiApp.length() - ".siddhi".length());
retryAppDeploymentSuccess(true, fileName);
}
logger().info("All Siddhi Apps deployed successfully.");
}
} else {
pcnfernando marked this conversation as resolved.
Show resolved Hide resolved
retryAppDeploymentSuccess(false, null);
}
}

private void retryAppDeploymentSuccess(boolean isDeploymentDirectory, String fileName) {
retryUntilSuccess(getStartupTimeoutSeconds(), TimeUnit.SECONDS, () -> {
if (!isRunning()) {
throw new ContainerLaunchException("Siddhi Runner Container failed to start");
}
HTTPClient.HTTPResponseMessage httpResponseMessage = callHealthAPI();
if (httpResponseMessage.getResponseCode() == 200) {
if (isDeploymentDirectory) {
String logs = this.getLogs();
if (!logs.contains("Siddhi App " + fileName + " deployed successfully")) {
throw new Exception("Siddhi App " + fileName + " deployment failed.");
}
}
logger().info("Siddhi Runner Health API reached successfully.");
return null;
} else {
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