Skip to content

Commit

Permalink
Fix apache#1234: added e2e test for master
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Feb 21, 2020
1 parent 946c89d commit 067ff80
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addons/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func findAdditionalDependencies(e *trait.Environment, meta metadata.IntegrationM
parts := strings.Split(endpoint, ":")
if len(parts) > 2 {
// syntax "master:lockname:endpoint:..."
childComponent := parts[2]
childComponent := strings.ReplaceAll(parts[2], "/", "")
if artifact := e.CamelCatalog.GetArtifactByScheme(childComponent); artifact != nil {
dependencies = append(dependencies, artifact.GetDependencyID())
}
Expand Down
28 changes: 28 additions & 0 deletions e2e/files/Master.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.camel.builder.RouteBuilder;

public class Java extends RouteBuilder {
@Override
public void configure() throws Exception {
from("master:lock:timer:tick")
.setHeader("m").constant("string!")
.setBody().simple("Magic${header.m}")
.log("${body}");
}
}
15 changes: 15 additions & 0 deletions e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ func TestRunSimpleExamples(t *testing.T) {
Expect(kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
})

t.Run("run java with master", func(t *testing.T) {
RegisterTestingT(t)
Expect(kamel("run", "-n", ns, "files/Master.java").Execute()).Should(BeNil())
Eventually(integrationPodPhase(ns, "master"), 5*time.Minute).Should(Equal(v1.PodRunning))
Eventually(integrationLogs(ns, "master"), 1*time.Minute).Should(ContainSubstring("Magicstring!"))
Eventually(configMap(ns, "master-lock"), 10*time.Second).ShouldNot(BeNil())
// Start a second integration with the same lock (it should not start the route)
Expect(kamel("run", "-n", ns, "files/Master.java", "--name", "second",
"-t", "master.configmap=master", "-t", "master.label-value=master").Execute()).Should(BeNil())
Eventually(integrationPodPhase(ns, "second"), 5*time.Minute).Should(Equal(v1.PodRunning))
Eventually(integrationLogs(ns, "second"), 1*time.Minute).Should(ContainSubstring("started in"))
Eventually(integrationLogs(ns, "second"), 30*time.Second).ShouldNot(ContainSubstring("Magicstring!"))
Expect(kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
})

t.Run("run xml", func(t *testing.T) {
RegisterTestingT(t)
Expect(kamel("run", "-n", ns, "files/xml.xml").Execute()).Should(BeNil())
Expand Down
19 changes: 18 additions & 1 deletion e2e/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func integrationPod(ns string, name string) func() *corev1.Pod {
lst := corev1.PodList{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: v1.SchemeGroupVersion.String(),
APIVersion: corev1.SchemeGroupVersion.String(),
},
}
err := testClient.List(testContext, &lst,
Expand All @@ -229,6 +229,23 @@ func integrationPod(ns string, name string) func() *corev1.Pod {
}
}

func configMap(ns string, name string) func() *corev1.ConfigMap {
return func() *corev1.ConfigMap {
cm := corev1.ConfigMap{}
key := k8sclient.ObjectKey{
Namespace: ns,
Name: name,
}
err := testClient.Get(testContext, key, &cm)
if err != nil && k8serrors.IsNotFound(err) {
return nil
} else if err != nil {
panic(err)
}
return &cm
}
}

func integrationCronJob(ns string, name string) func() *v1beta1.CronJob {
return func() *v1beta1.CronJob {
lst := v1beta1.CronJobList{
Expand Down

0 comments on commit 067ff80

Please sign in to comment.