This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit fef713026fe268df9d8fdff3afd7f410c9f41635 Author: nferraro <ni.ferr...@gmail.com> AuthorDate: Fri Sep 7 18:18:36 2018 +0200 Fix integration with new runtime classes --- pkg/build/build_manager_integration_test.go | 15 ++++++------ pkg/build/local/local_builder.go | 4 ++-- pkg/build/local/local_builder_integration_test.go | 27 ++++++++++++++++++---- pkg/util/digest/digest.go | 6 +++++ .../java/org/apache/camel/k/jvm/Application.java | 6 ++--- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/pkg/build/build_manager_integration_test.go b/pkg/build/build_manager_integration_test.go index dcf7c9e..5d19201 100644 --- a/pkg/build/build_manager_integration_test.go +++ b/pkg/build/build_manager_integration_test.go @@ -26,18 +26,19 @@ import ( build "github.com/apache/camel-k/pkg/build/api" "time" "github.com/apache/camel-k/pkg/util/test" + "github.com/apache/camel-k/pkg/util/digest" ) func TestBuild(t *testing.T) { ctx := context.TODO() buildManager := NewBuildManager(ctx, test.GetTargetNamespace()) identifier := build.BuildIdentifier{ - Name: "example", - Digest: "sadsadasdsadasdafwefwef", + Name: "man-test", + Digest: digest.Random(), } buildManager.Start(build.BuildSource{ Identifier: identifier, - Code: code(), + Code: code(), }) deadline := time.Now().Add(5 * time.Minute) @@ -60,12 +61,12 @@ func TestFailedBuild(t *testing.T) { ctx := context.TODO() buildManager := NewBuildManager(ctx, test.GetTargetNamespace()) identifier := build.BuildIdentifier{ - Name: "example", - Digest: "545454", + Name: "man-test-2", + Digest: digest.Random(), } buildManager.Start(build.BuildSource{ Identifier: identifier, - Code: code() + "XX", + Code: code() + "XX", }) deadline := time.Now().Add(5 * time.Minute) @@ -98,4 +99,4 @@ public class Routes extends RouteBuilder { } ` -} \ No newline at end of file +} diff --git a/pkg/build/local/local_builder.go b/pkg/build/local/local_builder.go index e5f85ba..98830d6 100644 --- a/pkg/build/local/local_builder.go +++ b/pkg/build/local/local_builder.go @@ -115,8 +115,8 @@ func (b *localBuilder) execute(source build.BuildSource) (string, error) { "kamel/Routes.java": source.Code, }, Env: map[string]string{ - "JAVA_MAIN_CLASS": "org.apache.camel.k.jvm.Application", - "KAMEL_CLASS": "kamel.Routes", + "JAVA_MAIN_CLASS": "org.apache.camel.k.jvm.Application", + "CAMEL_K_ROUTES_URI": "classpath:kamel.Routes", }, Dependencies: []maven.Dependency{ { diff --git a/pkg/build/local/local_builder_integration_test.go b/pkg/build/local/local_builder_integration_test.go index 8403c6c..fcb9eb6 100644 --- a/pkg/build/local/local_builder_integration_test.go +++ b/pkg/build/local/local_builder_integration_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/assert" build "github.com/apache/camel-k/pkg/build/api" "github.com/apache/camel-k/pkg/util/test" + "github.com/apache/camel-k/pkg/util/digest" ) func TestBuild(t *testing.T) { @@ -33,10 +34,14 @@ func TestBuild(t *testing.T) { builder := NewLocalBuilder(ctx, test.GetTargetNamespace()) execution := builder.Build(build.BuildSource{ + Identifier: build.BuildIdentifier{ + Name: "test0", + Digest: digest.Random(), + }, Code: code(), }) - res := <- execution + res := <-execution assert.Nil(t, res.Error, "Build failed") } @@ -47,15 +52,23 @@ func TestDoubleBuild(t *testing.T) { builder := NewLocalBuilder(ctx, test.GetTargetNamespace()) execution1 := builder.Build(build.BuildSource{ + Identifier: build.BuildIdentifier{ + Name: "test1", + Digest: digest.Random(), + }, Code: code(), }) execution2 := builder.Build(build.BuildSource{ + Identifier: build.BuildIdentifier{ + Name: "test2", + Digest: digest.Random(), + }, Code: code(), }) - res1 := <- execution1 - res2 := <- execution2 + res1 := <-execution1 + res2 := <-execution2 assert.Nil(t, res1.Error, "Build failed") assert.Nil(t, res2.Error, "Build failed") @@ -67,10 +80,14 @@ func TestFailedBuild(t *testing.T) { builder := NewLocalBuilder(ctx, test.GetTargetNamespace()) execution := builder.Build(build.BuildSource{ + Identifier: build.BuildIdentifier{ + Name: "test3", + Digest: digest.Random(), + }, Code: code() + "-", }) - res := <- execution + res := <-execution assert.NotNil(t, res.Error, "Build should fail") } @@ -90,4 +107,4 @@ public class Routes extends RouteBuilder { } ` -} \ No newline at end of file +} diff --git a/pkg/util/digest/digest.go b/pkg/util/digest/digest.go index c29c018..5354718 100644 --- a/pkg/util/digest/digest.go +++ b/pkg/util/digest/digest.go @@ -22,6 +22,8 @@ import ( "crypto/sha256" "github.com/apache/camel-k/version" "encoding/base64" + "strconv" + "math/rand" ) // Compute a digest of the fields that are relevant for the deployment @@ -37,3 +39,7 @@ func Compute(integration *v1alpha1.Integration) string { // Add a letter at the beginning and use URL safe encoding return "v" + base64.RawURLEncoding.EncodeToString(hash.Sum(nil)) } + +func Random() string { + return "v" + strconv.FormatInt(rand.Int63(), 10) +} diff --git a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Application.java b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Application.java index 90d3f4d..dbca9f1 100644 --- a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Application.java +++ b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Application.java @@ -20,15 +20,15 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.main.Main; public class Application { - public static final String ENV_KAMEL_ROUTES_URI = "KAMEL_ROUTES_PATH"; + public static final String ENV_CAMEL_K_ROUTES_URI = "CAMEL_K_ROUTES_URI"; public static final String SCHEME_CLASSPATH = "classpath:"; public static final String SCHEME_FILE = "file:"; public static void main(String[] args) throws Exception { - final String resource = System.getenv(ENV_KAMEL_ROUTES_URI); + final String resource = System.getenv(ENV_CAMEL_K_ROUTES_URI); if (resource == null || resource.trim().length() == 0) { - throw new IllegalStateException("No valid resource found in " + ENV_KAMEL_ROUTES_URI + " environment variable"); + throw new IllegalStateException("No valid resource found in " + ENV_CAMEL_K_ROUTES_URI + " environment variable"); } if (!resource.startsWith(SCHEME_CLASSPATH) && !resource.startsWith(SCHEME_FILE)) { throw new IllegalStateException("No valid resource format, expected scheme:path, found " + resource);