diff --git a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingAction.java b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingAction.java index 76d9da90..2158cf25 100644 --- a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingAction.java +++ b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingAction.java @@ -40,6 +40,9 @@ public class VerifyKameletBindingAction extends AbstractKameletAction { private final String bindingName; + private final int maxAttempts; + private final long delayBetweenAttempts; + /** * Constructor using given builder. * @param builder @@ -47,6 +50,8 @@ public class VerifyKameletBindingAction extends AbstractKameletAction { public VerifyKameletBindingAction(Builder builder) { super("verify-kamelet-binding", builder); this.bindingName = builder.bindingName; + this.maxAttempts = builder.maxAttempts; + this.delayBetweenAttempts = builder.delayBetweenAttempts; } @Override @@ -66,20 +71,46 @@ public void doExecute(TestContext context) { private void verifyLocalKameletBinding(String name, TestContext context) { Long pid = context.getVariable(name + ":pid", Long.class); - Map properties = camel().get(pid); - if ((!properties.isEmpty() && properties.get("STATUS").equals("Running"))) { - LOG.info(String.format("Verified Kamelet binding '%s' state 'Running' - All values OK!", name)); - } else { - throw new ValidationException(String.format("Failed to retrieve Kamelet binding '%s' in state 'Running'", name)); + + for (int i = 0; i < maxAttempts; i++) { + Map properties = camel().get(pid); + if ((!properties.isEmpty() && properties.get("STATUS").equals("Running"))) { + LOG.info(String.format("Verified Kamelet binding '%s' state 'Running' - All values OK!", name)); + return; + } + + LOG.info(String.format("Waiting for Kamelet binding '%s' to be in state 'Running'- retry in %s ms", name, delayBetweenAttempts)); + try { + Thread.sleep(delayBetweenAttempts); + } catch (InterruptedException e) { + LOG.warn("Interrupted while waiting for Kamelet binding", e); + } } + + throw new ValidationException(String.format("Failed to retrieve Kamelet binding '%s' in state 'Running'", name)); } private void verifyKameletBinding(String namespace, String name) { CustomResourceDefinitionContext ctx = CamelKSupport.kameletBindingCRDContext(CamelKSettings.getKameletApiVersion()); - KameletBinding binding = getKubernetesClient().customResources(ctx, KameletBinding.class, KameletBindingList.class) - .inNamespace(namespace) - .withName(name) - .get(); + + KameletBinding binding = null; + for (int i = 0; i < maxAttempts; i++) { + binding = getKubernetesClient().customResources(ctx, KameletBinding.class, KameletBindingList.class) + .inNamespace(namespace) + .withName(name) + .get(); + + if (binding == null) { + LOG.info(String.format("Waiting for Kamelet binding '%s' - retry in %s ms", name, delayBetweenAttempts)); + try { + Thread.sleep(delayBetweenAttempts); + } catch (InterruptedException e) { + LOG.warn("Interrupted while waiting for Kamelet binding", e); + } + } else { + break; + } + } if (binding == null) { throw new ValidationException(String.format("Failed to retrieve Kamelet binding '%s' in namespace '%s'", name, namespace)); @@ -97,6 +128,10 @@ public static final class Builder extends AbstractKameletAction.Builder> getAll() { } private static void detectJBang() { - ProcessAndOutput result = version(); + ProcessAndOutput result = getVersion(); if (result.getProcess().exitValue() == OK_EXIT_CODE) { LOG.info("Found JBang v" + result.getOutput()); } else { LOG.warn("JBang not found. Downloading ..."); download(); - result = version(); + result = getVersion(); if (result.getProcess().exitValue() == OK_EXIT_CODE) { LOG.info("Using JBang v" + result.getOutput()); } @@ -264,7 +272,7 @@ private static void download() { installDir = installPath.resolve(homePath); } - private static ProcessAndOutput version() { + private static ProcessAndOutput getVersion() { return execute(jBang("version")); } diff --git a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/jbang/ProcessAndOutput.java b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/jbang/ProcessAndOutput.java index 64de2c35..bfa94fb4 100644 --- a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/jbang/ProcessAndOutput.java +++ b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/jbang/ProcessAndOutput.java @@ -144,7 +144,7 @@ public Long getCamelProcessId() { try { if (isUnix()) { // wait for descendant process to be available - await().atMost(5000L, TimeUnit.MILLISECONDS) + await().atMost(15000L, TimeUnit.MILLISECONDS) .until(() -> process.descendants().findAny().isPresent()); return process.descendants() .filter(p -> p.info().commandLine().orElse("").contains(CamelJBangSettings.getCamelApp())) diff --git a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationActionTest.java b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationActionTest.java index 93346c6e..776a6881 100644 --- a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationActionTest.java +++ b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationActionTest.java @@ -172,6 +172,7 @@ public void shouldCreateIntegrationWithConfigModeline() { @Test public void shouldCreateLocalJBangIntegration() { + camel(); CreateIntegrationAction action = new CreateIntegrationAction.Builder() .client(kubernetesClient) .integration("foo") diff --git a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/DeleteIntegrationActionTest.java b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/DeleteIntegrationActionTest.java index 79c46492..6f8f1deb 100644 --- a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/DeleteIntegrationActionTest.java +++ b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/DeleteIntegrationActionTest.java @@ -52,6 +52,7 @@ public class DeleteIntegrationActionTest { @BeforeClass public static void setup() throws IOException { sampleIntegration = new ClassPathResource("simple.groovy").getFile().toPath(); + camel(); } @Test diff --git a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/VerifyIntegrationActionTest.java b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/VerifyIntegrationActionTest.java index ad4f2aae..d6747b46 100644 --- a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/VerifyIntegrationActionTest.java +++ b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/VerifyIntegrationActionTest.java @@ -52,6 +52,7 @@ public class VerifyIntegrationActionTest { @BeforeClass public static void setup() throws IOException { sampleIntegration = new ClassPathResource("simple.groovy").getFile().toPath(); + camel(); } @Test diff --git a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/CreateKameletBindingActionTest.java b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/CreateKameletBindingActionTest.java index 0ae9262f..6c3011e5 100644 --- a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/CreateKameletBindingActionTest.java +++ b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/CreateKameletBindingActionTest.java @@ -32,6 +32,7 @@ import org.citrusframework.yaks.YaksClusterType; import org.citrusframework.yaks.camelk.actions.integration.CreateIntegrationActionTest; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,9 +53,13 @@ public class CreateKameletBindingActionTest { private final TestContext context = TestContextFactory.newInstance().getObject(); + @BeforeClass + public static void setup() throws IOException { + camel(); + } + @Test public void shouldCreateLocalJBangKameletBinding() throws IOException { - System.setProperty("yaks.jbang.camel.dump.integration.output", "true"); CreateKameletBindingAction action = new CreateKameletBindingAction.Builder() .client(kubernetesClient) .binding("timer-to-log-binding") diff --git a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/DeleteKameletBindingActionTest.java b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/DeleteKameletBindingActionTest.java index 37d714aa..313c4ea4 100644 --- a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/DeleteKameletBindingActionTest.java +++ b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/DeleteKameletBindingActionTest.java @@ -52,6 +52,7 @@ public class DeleteKameletBindingActionTest { @BeforeClass public static void setup() throws IOException { sampleBinding = new ClassPathResource("timer-to-log-binding.yaml").getFile().toPath(); + camel(); } @Test diff --git a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingActionTest.java b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingActionTest.java index ccfed2c3..531b2e6e 100644 --- a/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingActionTest.java +++ b/java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingActionTest.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.HashMap; -import java.util.concurrent.TimeUnit; import com.consol.citrus.context.TestContext; import com.consol.citrus.context.TestContextFactory; @@ -33,18 +32,12 @@ import org.citrusframework.yaks.camelk.jbang.ProcessAndOutput; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; -import static org.awaitility.Awaitility.await; import static org.citrusframework.yaks.camelk.jbang.CamelJBang.camel; public class VerifyKameletBindingActionTest { - /** Logger */ - private static final Logger LOG = LoggerFactory.getLogger(VerifyKameletBindingActionTest.class); - private final KubernetesMockServer k8sServer = new KubernetesMockServer(new Context(), new MockWebServer(), new HashMap<>(), new KubernetesCrudDispatcher(), false); @@ -57,24 +50,24 @@ public class VerifyKameletBindingActionTest { @BeforeClass public static void setup() throws IOException { sampleBinding = new ClassPathResource("timer-to-log-binding.yaml").getFile().toPath(); + camel(); } @Test public void shouldVerifyLocalJBangIntegration() { - ProcessAndOutput pao = camel().run("timer-to-log-binding.yaml", sampleBinding); + ProcessAndOutput pao = camel().run("timer-to-log-binding", sampleBinding); Long pid = pao.getCamelProcessId(); try { VerifyKameletBindingAction action = new VerifyKameletBindingAction.Builder() .client(kubernetesClient) - .isAvailable("timer-to-log-binding.yaml") + .isAvailable("timer-to-log-binding") .clusterType(YaksClusterType.LOCAL) + .maxAttempts(10) .build(); - context.setVariable("timer-to-log-binding.yaml:pid", pid); - context.setVariable("timer-to-log-binding.yaml:process:" + pid, pao); - - await().atMost(30000L, TimeUnit.MILLISECONDS).until(() -> !camel().get(pid).isEmpty()); + context.setVariable("timer-to-log-binding:pid", pid); + context.setVariable("timer-to-log-binding:process:" + pid, pao); action.execute(context); } finally {