Skip to content

Commit

Permalink
[BEAM-13695] Add jamm jvm options to Java 11 (apache#17178)
Browse files Browse the repository at this point in the history
* Add jamm jvm options to Java 11

* fix test comments
  • Loading branch information
kileys committed May 11, 2022
1 parent 6ee09b6 commit a167424
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sdks/java/container/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ func BuildOptions(metaOptions []*MetaOption) *Options {
continue
}

options.JavaArguments = append(options.JavaArguments, meta.Options.JavaArguments...)
// Rightmost takes precedence
options.JavaArguments = append(meta.Options.JavaArguments, options.JavaArguments...)

for key, value := range meta.Options.Properties {
_, exists := options.Properties[key]
Expand Down
74 changes: 74 additions & 0 deletions sdks/java/container/boot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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.

// boot is the boot code for the Java SDK harness container. It is responsible
// for retrieving staged files and invoking the JVM correctly.
package main

import (
"reflect"
"testing"
)

func TestBuildOptionsEmpty(t *testing.T) {
dir := "test/empty"
metaOptions, err := LoadMetaOptions(dir)
if err != nil {
t.Fatalf("Got error %v running LoadMetaOptions", err)
}
if metaOptions != nil {
t.Fatalf("LoadMetaOptions(%v) = %v, want nil", dir, metaOptions)
}

javaOptions := BuildOptions(metaOptions)
if len(javaOptions.JavaArguments) != 0 || len(javaOptions.Classpath) != 0 || len(javaOptions.Properties) != 0 {
t.Errorf("BuildOptions(%v) = %v, want nil", metaOptions, javaOptions)
}
}

func TestBuildOptionsDisabled(t *testing.T) {
metaOptions, err := LoadMetaOptions("test/disabled")
if err != nil {
t.Fatalf("Got error %v running LoadMetaOptions", err)
}

javaOptions := BuildOptions(metaOptions)
if len(javaOptions.JavaArguments) != 0 || len(javaOptions.Classpath) != 0 || len(javaOptions.Properties) != 0 {
t.Errorf("BuildOptions(%v) = %v, want nil", metaOptions, javaOptions)
}
}

func TestBuildOptions(t *testing.T) {
metaOptions, err := LoadMetaOptions("test/priority")
if err != nil {
t.Fatalf("Got error %v running LoadMetaOptions", err)
}

javaOptions := BuildOptions(metaOptions)
wantJavaArguments := []string{"java_args=low", "java_args=high"}
wantClasspath := []string{"classpath_high", "classpath_low"}
wantProperties := map[string]string{
"priority":"high",
}
if !reflect.DeepEqual(javaOptions.JavaArguments, wantJavaArguments) {
t.Errorf("BuildOptions(%v).JavaArguments = %v, want %v", metaOptions, javaOptions.JavaArguments, wantJavaArguments)
}
if !reflect.DeepEqual(javaOptions.Classpath, wantClasspath) {
t.Errorf("BuildOptions(%v).Classpath = %v, want %v", metaOptions, javaOptions.Classpath, wantClasspath)
}
if !reflect.DeepEqual(javaOptions.Properties, wantProperties) {
t.Errorf("BuildOptions(%v).JavaProperties = %v, want %v", metaOptions, javaOptions.Properties, wantProperties)
}
}
2 changes: 1 addition & 1 deletion sdks/java/container/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ task copyGolangLicenses(type: Copy) {
}

task copyJdkOptions(type: Copy) {
if (imageJavaVersion == "17") {
if (imageJavaVersion == "17" || imageJavaVersion == "11") {
from "option-jamm.json"
into "build/target/options"
}
Expand Down
13 changes: 13 additions & 0 deletions sdks/java/container/java11/option-jamm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "jamm",
"enabled": true,
"options": {
"java_arguments": [
"--add-modules=jamm",
"--module-path=/opt/apache/beam/jars/jamm.jar",
"--add-opens=java.base/java.lang=jamm",
"--add-opens=java.base/java.lang.ref=jamm",
"--add-opens=java.base/java.util=jamm"
]
}
}
6 changes: 6 additions & 0 deletions sdks/java/container/test/disabled/option-disabled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test-disabled",
"enabled": false,
"options": {
}
}
1 change: 1 addition & 0 deletions sdks/java/container/test/empty/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Empty directory to test boot options
16 changes: 16 additions & 0 deletions sdks/java/container/test/priority/option-high.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "high",
"enabled": true,
"priority": 100,
"options": {
"java_arguments": [
"java_args=high"
],
"classpath": [
"classpath_high"
],
"properties": {
"priority": "high"
}
}
}
16 changes: 16 additions & 0 deletions sdks/java/container/test/priority/option-low.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "low",
"enabled": true,
"priority": 0,
"options": {
"java_arguments": [
"java_args=low"
],
"classpath": [
"classpath_low"
],
"properties": {
"priority": "low"
}
}
}

0 comments on commit a167424

Please sign in to comment.