github.com/apache/beam/sdks/v2@v2.48.2/java/container/boot_test.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one or more 2 // contributor license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright ownership. 4 // The ASF licenses this file to You under the Apache License, Version 2.0 5 // (the "License"); you may not use this file except in compliance with 6 // the License. You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 // boot is the boot code for the Java SDK harness container. It is responsible 17 // for retrieving staged files and invoking the JVM correctly. 18 package main 19 20 import ( 21 "context" 22 "reflect" 23 "testing" 24 25 "github.com/apache/beam/sdks/v2/go/container/tools" 26 ) 27 28 func TestBuildOptionsEmpty(t *testing.T) { 29 ctx, logger := context.Background(), &tools.Logger{} 30 dir := "test/empty" 31 metaOptions, err := LoadMetaOptions(ctx, logger, dir) 32 if err != nil { 33 t.Fatalf("Got error %v running LoadMetaOptions", err) 34 } 35 if metaOptions != nil { 36 t.Fatalf("LoadMetaOptions(%v) = %v, want nil", dir, metaOptions) 37 } 38 39 javaOptions := BuildOptions(ctx, logger, metaOptions) 40 if len(javaOptions.JavaArguments) != 0 || len(javaOptions.Classpath) != 0 || len(javaOptions.Properties) != 0 { 41 t.Errorf("BuildOptions(%v) = %v, want nil", metaOptions, javaOptions) 42 } 43 } 44 45 func TestBuildOptionsDisabled(t *testing.T) { 46 ctx, logger := context.Background(), &tools.Logger{} 47 metaOptions, err := LoadMetaOptions(ctx, logger, "test/disabled") 48 if err != nil { 49 t.Fatalf("Got error %v running LoadMetaOptions", err) 50 } 51 52 javaOptions := BuildOptions(ctx, logger, metaOptions) 53 if len(javaOptions.JavaArguments) != 0 || len(javaOptions.Classpath) != 0 || len(javaOptions.Properties) != 0 { 54 t.Errorf("BuildOptions(%v) = %v, want nil", metaOptions, javaOptions) 55 } 56 } 57 58 func TestBuildOptions(t *testing.T) { 59 ctx, logger := context.Background(), &tools.Logger{} 60 metaOptions, err := LoadMetaOptions(ctx, logger, "test/priority") 61 if err != nil { 62 t.Fatalf("Got error %v running LoadMetaOptions", err) 63 } 64 65 javaOptions := BuildOptions(ctx, logger, metaOptions) 66 wantJavaArguments := []string{"java_args=low", "java_args=high"} 67 wantClasspath := []string{"classpath_high", "classpath_low"} 68 wantProperties := map[string]string{ 69 "priority": "high", 70 } 71 if !reflect.DeepEqual(javaOptions.JavaArguments, wantJavaArguments) { 72 t.Errorf("BuildOptions(%v).JavaArguments = %v, want %v", metaOptions, javaOptions.JavaArguments, wantJavaArguments) 73 } 74 if !reflect.DeepEqual(javaOptions.Classpath, wantClasspath) { 75 t.Errorf("BuildOptions(%v).Classpath = %v, want %v", metaOptions, javaOptions.Classpath, wantClasspath) 76 } 77 if !reflect.DeepEqual(javaOptions.Properties, wantProperties) { 78 t.Errorf("BuildOptions(%v).JavaProperties = %v, want %v", metaOptions, javaOptions.Properties, wantProperties) 79 } 80 }