Skip to content

Commit

Permalink
Maybe fixes CI race conditions... not mergable in the current state (… (
Browse files Browse the repository at this point in the history
#1244)

* Fix for race condition on startup. Try to insure that all addons are started before returning from furnace.startAsync()

* Fixed missing break
  • Loading branch information
jsight committed Nov 29, 2017
1 parent 1f6585a commit b9859a0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 35 deletions.
41 changes: 39 additions & 2 deletions bootstrap/src/main/java/org/jboss/windup/bootstrap/Bootstrap.java
Expand Up @@ -19,11 +19,13 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.lang3.StringUtils;
import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.addons.Addon;
import org.jboss.forge.furnace.repositories.AddonRepository;
import org.jboss.forge.furnace.repositories.AddonRepositoryMode;
import org.jboss.forge.furnace.repositories.MutableAddonRepository;
Expand Down Expand Up @@ -301,8 +303,7 @@ private void run(List<String> args)

try
{
Future<Furnace> future = furnace.startAsync();
future.get(); // use future.get() to wait until it is started
startFurnace();
}
catch (Exception e)
{
Expand Down Expand Up @@ -338,6 +339,7 @@ private void run(List<String> args)

if (!executePhase(CommandPhase.POST_EXECUTION, commands) || commands.isEmpty())
return;

}
catch (Throwable t)
{
Expand All @@ -346,6 +348,41 @@ private void run(List<String> args)
}
}

private void startFurnace() throws InterruptedException, ExecutionException
{
Future<Furnace> future = furnace.startAsync();
future.get(); // use future.get() to wait until it is started
long startTime = System.currentTimeMillis();
long maxWait = 1000L * 30L; // only wait at most 30 seconds for addons to start
while (true)
{
long currentTime = System.currentTimeMillis();
long timeWaited = currentTime - startTime;

boolean allStarted = true;
for (Addon addon : furnace.getAddonRegistry().getAddons())
{
if (!addon.getStatus().isStarted())
{
allStarted = false;
}
}
if (allStarted)
break;

if (timeWaited > maxWait)
{
System.err.println("WARN: Not all addons started!");
for (Addon addon : furnace.getAddonRegistry().getAddons())
{
if (!addon.getStatus().isStarted())
System.err.println("WARN: " + addon.getId() + " status: " + addon.getStatus());
}
break;
}
}
}

private void stop()
{
if (furnace != null && !furnace.getStatus().isStopped())
Expand Down
@@ -1,48 +1,56 @@
package org.jboss.windup.tests.bootstrap.migrate;

import org.apache.commons.io.FileUtils;
import org.jboss.windup.tests.bootstrap.AbstractBootstrapTestWithRules;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.jboss.windup.tests.bootstrap.AbstractBootstrapTestWithRules;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class NoInputOrOutputPathTest extends AbstractBootstrapTestWithRules {
public class NoInputOrOutputPathTest extends AbstractBootstrapTestWithRules
{

private static final String TEST_FILE_WAR = "../test-files/Windup1x-javaee-example-tiny.war";
private static final File TEST_FILE_OUTPUT_DIR = new File(TEST_FILE_WAR+".report");
private static final File TEST_FILE_OUTPUT_DIR = new File(TEST_FILE_WAR + ".report");

@Rule
public final TemporaryFolder tmp = new TemporaryFolder();

@Before
public void cleanup() {
try {
public void cleanup()
{
try
{
FileUtils.deleteDirectory(TEST_FILE_OUTPUT_DIR);
} catch (IOException ex) {}
}
catch (IOException ex)
{
}
}

/**
* Test should show error about empty output argument
*/
@Test()
public void InputAndNoOutputPath() {
public void InputAndNoOutputPath()
{
bootstrap("--input", TEST_FILE_WAR,
"--output",
"--target", "eap7");
"--output",
"--target", "eap7");

try
{
System.out.println(TEST_FILE_OUTPUT_DIR.getCanonicalPath()+" -> comparison");
assertTrue(capturedOutput().contains("Output Path:"+TEST_FILE_OUTPUT_DIR.getCanonicalPath()));
} catch (IOException ex) {
System.out.println(TEST_FILE_OUTPUT_DIR.getCanonicalPath() + " -> comparison");
assertTrue(capturedOutput().contains("Output Path:" + TEST_FILE_OUTPUT_DIR.getCanonicalPath()));
}
catch (IOException ex)
{
fail("Something happend while getting canonical path.");
}
}
Expand All @@ -51,16 +59,19 @@ public void InputAndNoOutputPath() {
* Test should show error about empty output argument
*/
@Test()
public void InputAndNoOutputPathAsLastOption() {
public void InputAndNoOutputPathAsLastOption()
{
bootstrap("--input", TEST_FILE_WAR,
"--target", "eap7",
"--output");
"--target", "eap7",
"--output");

try
{
System.out.println(TEST_FILE_OUTPUT_DIR.getCanonicalPath()+" -> comparison");
assertTrue(capturedOutput().contains("Output Path:"+TEST_FILE_OUTPUT_DIR.getCanonicalPath()));
} catch (IOException ex) {
System.out.println(TEST_FILE_OUTPUT_DIR.getCanonicalPath() + " -> comparison");
assertTrue(capturedOutput().contains("Output Path:" + TEST_FILE_OUTPUT_DIR.getCanonicalPath()));
}
catch (IOException ex)
{
fail("Something happend while getting canonical path.");
}
}
Expand All @@ -69,24 +80,28 @@ public void InputAndNoOutputPathAsLastOption() {
* Test should show error about space and therefore empty output argument
*/
@Test
public void InputAndSpaceAsOutputPath() {
public void InputAndSpaceAsOutputPath()
{
bootstrap("--input", TEST_FILE_WAR,
"--output", " ",
"--target", "eap7");
"--output", " ",
"--target", "eap7");
try
{
System.out.println(TEST_FILE_OUTPUT_DIR.getCanonicalPath()+" -> comparison");
assertTrue(capturedOutput().contains("Output Path:" +TEST_FILE_OUTPUT_DIR.getCanonicalPath()));
} catch (IOException ex) {
System.out.println(TEST_FILE_OUTPUT_DIR.getCanonicalPath() + " -> comparison");
assertTrue(capturedOutput().contains("Output Path:" + TEST_FILE_OUTPUT_DIR.getCanonicalPath()));
}
catch (IOException ex)
{
fail("Something happend while getting canonical path.");
}
}

/**
* Test should show error about empty input argument
*/
@Test
public void NoInputPath() {
public void NoInputPath()
{
bootstrap("--input", " ", "--target", "eap7");

assertTrue(capturedOutput().contains("ERROR: input must be specified."));
Expand Down

0 comments on commit b9859a0

Please sign in to comment.