Skip to content

Commit

Permalink
Merge pull request apache#12541: [BEAM-10682] Add workflow to run Jav…
Browse files Browse the repository at this point in the history
…a tests on Linux/Windows/Mac
  • Loading branch information
kamilwu authored Aug 24, 2020
2 parents 4172ce2 + e164d17 commit 094d06c
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg)
![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg)
![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg)

See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
24 changes: 21 additions & 3 deletions .github/workflows/cancel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
# under the License.

name: Cancel

on: [push, pull_request]

jobs:
cancel:
name: 'Cancel Previous Runs'

cancel_build_wheels:
name: 'Cancel Previous Runs of python source distribution and wheels build'
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- name: Get workflow id
- name: Get build_wheels workflow id
run: |
WORKFLOW_ID=$(curl "Authorization: token ${{ github.token }}" https://api.github.com/repos/${{ github.repository }}/actions/workflows/build_wheels.yml | jq '.id')
echo "Workflow id: ${WORKFLOW_ID}"
Expand All @@ -32,3 +35,18 @@ jobs:
with:
workflow_id: ${{ env.WORKFLOW_ID }}
access_token: ${{ github.token }}

cancel_java_tests:
name: 'Cancel Previous Runs of Java Tests'
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- name: Get java_tests workflow id
run: |
WORKFLOW_ID=$(curl "Authorization: token ${{ github.token }}" https://api.github.com/repos/${{ github.repository }}/actions/workflows/java_tests.yml | jq '.id')
echo "Workflow id: ${WORKFLOW_ID}"
echo "::set-env name=WORKFLOW_ID::${WORKFLOW_ID}"
- uses: styfle/[email protected]
with:
workflow_id: ${{ env.WORKFLOW_ID }}
access_token: ${{ github.token }}
162 changes: 162 additions & 0 deletions .github/workflows/java_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# 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.

# To learn more about GitHub Actions in Apache Beam check the CI.md

name: Java Tests

on:
workflow_dispatch:
inputs:
runDataflow:
description: 'Type "true" if you want to run Dataflow tests (GCP variables must be configured, check CI.md)'
default: false
schedule:
- cron: '10 2 * * *'
push:
branches: ['master', 'release-*']
tags: 'v*'
pull_request:
branches: ['master', 'release-*']
tags: 'v*'
paths: ['sdks/java/**', 'model/**', 'runners/**', 'examples/java/**', 'examples/kotlin/**', 'release/**']


jobs:

check_gcp_variables:
timeout-minutes: 5
name: "Check GCP variables set"
runs-on: ubuntu-latest
outputs:
gcp-variables-set: ${{ steps.check_gcp_variables.outputs.gcp-variables-set }}
steps:
- uses: actions/checkout@v2
- name: "Check are GCP variables set"
run: "./scripts/ci/ci_check_are_gcp_variables_set.sh"
id: check_gcp_variables
env:
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_SA_EMAIL: ${{ secrets.GCP_SA_EMAIL }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_TESTING_BUCKET: ${{ secrets.GCP_TESTING_BUCKET }}
GCP_REGION: "not-needed-here"
GCP_PYTHON_WHEELS_BUCKET: "not-needed-here"

java_unit_tests:
name: 'Java Unit Tests'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
# :sdks:java:core:test
- name: Run :sdks:java:core:test
run: ./gradlew :sdks:java:core:test
- name: Upload test logs for :sdks:java:core:test
uses: actions/upload-artifact@v2
if: always()
with:
name: java_unit_tests-sdks-java-core-test-${{ matrix.os }}
path: sdks/java/core/build/reports/tests/test
# :sdks:java:harness:test
- name: Run :sdks:java:harness:test
if: always()
run: ./gradlew :sdks:java:harness:test
- name: Upload test logs for :sdks:java:harness:test
uses: actions/upload-artifact@v2
if: always()
with:
name: java_unit_tests-sdks-java-harness-test-${{ matrix.os }}
path: sdks/java/harness/build/reports/tests/test
# :runners:core-java:test
- name: Run :runners:core-java:test
if: always()
run: ./gradlew :runners:core-java:test
- name: Upload test logs for :runners:core-java:test
uses: actions/upload-artifact@v2
if: always()
with:
name: java_unit_tests-runners-core-java-test-${{ matrix.os }}
path: runners/core-java/build/reports/tests/test

java_wordcount_direct_runner:
name: 'Java Wordcount Direct Runner'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run WordCount Unix
shell: bash
run: |
bash ./gradlew -p examples/ \
integrationTest -DintegrationTestPipelineOptions='[
"--runner=DirectRunner", "--tempRoot=./tmp" ]' \
--tests org.apache.beam.examples.WordCountIT \
-DintegrationTestRunner=direct
- name: Upload test logs
uses: actions/upload-artifact@v2
if: always()
with:
name: java_wordcount_direct_runner-${{matrix.os}}
path: examples/java/build/reports/tests/integrationTest

java_wordcount_dataflow:
name: 'Java Wordcount Dataflow'
needs:
- check_gcp_variables
runs-on: ${{ matrix.os }}
if: |
needs.check_gcp_variables.outputs.gcp-variables-set == 'true' && (
(github.event_name == 'push' || github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.runDataflow == 'true')
)
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Authenticate on GCP
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
export_default_credentials: true
- name: Run WordCount
shell: bash
run: |
bash ./gradlew -p examples/ \
integrationTest -DintegrationTestPipelineOptions='[
"--runner=DataflowRunner", "--project=${{ secrets.GCP_PROJECT_ID }}", "--tempRoot=gs://${{ secrets.GCP_TESTING_BUCKET }}/tmp/"]' \
--tests org.apache.beam.examples.WordCountIT \
-DintegrationTestRunner=dataflow
- name: Upload test logs
uses: actions/upload-artifact@v2
if: always()
with:
name: java_wordcount_dataflow-${{matrix.os}}
path: examples/java/build/reports/tests/integrationTest
9 changes: 9 additions & 0 deletions CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ Service Account shall have following permissions ([IAM roles](https://cloud.goog
| Python Wordcount Direct Runner | Runs python WordCount example with Direct Runner. | Yes | Yes | Yes | - |
| Python Wordcount Dataflow | Runs python WordCount example with DataFlow Runner. | - | Yes | Yes | Yes |

#### Java tests - [java_tests.yml](.github/workflows/java_tests.yml)

| Job | Description | Pull Request Run | Direct Push/Merge Run | Scheduled Run | Requires GCP Credentials |
|------------------------------|-----------------------------------------------------------------------------------------------|------------------|-----------------------|---------------|--------------------------|
| Check GCP variables | Checks that GCP variables are set. Jobs which required them depend on the output of this job. | Yes | Yes | Yes | Yes/No |
| Java Unit Tests | Runs Java unit tests. | Yes | Yes | Yes | - |
| Java Wordcount Direct Runner | Runs Java WordCount example with Direct Runner. | Yes | Yes | Yes | - |
| Java Wordcount Dataflow | Runs Java WordCount example with DataFlow Runner. | - | Yes | Yes | Yes |

### GitHub Action Tips

* If you introduce changes to the workflow it is possible that your changes will not be present in the check run triggered in Pull Request.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
[![Compat Check at master](https://python-compatibility-tools.appspot.com/one_badge_image?package=git%2Bgit%3A//github.com/apache/beam.git%23subdirectory%3Dsdks/python)](https://python-compatibility-tools.appspot.com/one_badge_target?package=git%2Bgit%3A//github.com/apache/beam.git%23subdirectory%3Dsdks/python)
![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg)
![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg)
![Java Tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg)

### Post-commit tests status (on master branch)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1378,9 +1378,15 @@ class BeamModulePlugin implements Plugin<Project> {
include "**/*IT.class"

def pipelineOptionsString = configuration.integrationTestPipelineOptions
def pipelineOptionsStringFormatted
def allOptionsList

if(pipelineOptionsString) {
allOptionsList = (new JsonSlurper()).parseText(pipelineOptionsString)
}

if(pipelineOptionsString && configuration.runner?.equalsIgnoreCase('dataflow')) {
project.evaluationDependsOn(":runners:google-cloud-dataflow-java:worker:legacy-worker")
def allOptionsList = (new JsonSlurper()).parseText(pipelineOptionsString)
def dataflowWorkerJar = project.findProperty('dataflowWorkerJar') ?:
project.project(":runners:google-cloud-dataflow-java:worker:legacy-worker").shadowJar.archivePath
def dataflowRegion = project.findProperty('dataflowRegion') ?: 'us-central1'
Expand All @@ -1389,11 +1395,17 @@ class BeamModulePlugin implements Plugin<Project> {
"--dataflowWorkerJar=${dataflowWorkerJar}",
"--region=${dataflowRegion}"
])
}

pipelineOptionsString = JsonOutput.toJson(allOptionsList)
// Windows handles quotation marks differently
if (pipelineOptionsString && System.properties['os.name'].toLowerCase().contains('windows')) {
def allOptionsListFormatted = allOptionsList.collect{ "\"$it\"" }
pipelineOptionsStringFormatted = JsonOutput.toJson(allOptionsListFormatted)
} else if (pipelineOptionsString) {
pipelineOptionsStringFormatted = JsonOutput.toJson(allOptionsList)
}

systemProperties.beamTestPipelineOptions = pipelineOptionsString
systemProperties.beamTestPipelineOptions = pipelineOptionsStringFormatted ?: pipelineOptionsString
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
package org.apache.beam.sdk.io;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;

import java.io.IOException;
import org.apache.beam.sdk.io.fs.ResourceId;
import org.apache.beam.sdk.util.CoderUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -30,6 +33,12 @@
@RunWith(JUnit4.class)
public class DefaultFilenamePolicyTest {

@Before
public void setup() {
// TODO: Java core test failing on windows, https://issues.apache.org/jira/browse/BEAM-10738
assumeFalse(SystemUtils.IS_OS_WINDOWS);
}

private static String constructName(
String baseFilename,
String shardTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand Down Expand Up @@ -63,6 +64,7 @@
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Sets;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -166,13 +168,17 @@ public void testRemoveWithTempFilename() throws Exception {
/** Finalize copies temporary files to output files and removes any temporary files. */
@Test
public void testFinalize() throws Exception {
// TODO: Java core test failing on windows, https://issues.apache.org/jira/browse/BEAM-10743
assumeFalse(SystemUtils.IS_OS_WINDOWS);
List<File> files = generateTemporaryFilesForFinalize(3);
runFinalize(buildWriteOperation(), files);
}

/** Finalize can be called repeatedly. */
@Test
public void testFinalizeMultipleCalls() throws Exception {
// TODO: Java core test failing on windows, https://issues.apache.org/jira/browse/BEAM-10744
assumeFalse(SystemUtils.IS_OS_WINDOWS);
List<File> files = generateTemporaryFilesForFinalize(3);
SimpleSink.SimpleWriteOperation writeOp = buildWriteOperation();
runFinalize(writeOp, files);
Expand All @@ -182,6 +188,8 @@ public void testFinalizeMultipleCalls() throws Exception {
/** Finalize can be called when some temporary files do not exist and output files exist. */
@Test
public void testFinalizeWithIntermediateState() throws Exception {
// TODO: Java core test failing on windows, https://issues.apache.org/jira/browse/BEAM-10745
assumeFalse(SystemUtils.IS_OS_WINDOWS);
SimpleSink.SimpleWriteOperation writeOp = buildWriteOperation();
List<File> files = generateTemporaryFilesForFinalize(3);
runFinalize(writeOp, files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import java.io.Writer;
import java.nio.channels.Channels;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class FileSystemsTest {

@Test
public void testGetLocalFileSystem() throws Exception {
// TODO: Java core test failing on windows, https://issues.apache.org/jira/browse/BEAM-10740
assumeFalse(SystemUtils.IS_OS_WINDOWS);
assertTrue(
FileSystems.getFileSystemInternal(toLocalResourceId("~/home/").getScheme())
instanceof LocalFileSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -407,6 +408,8 @@ public void testMatchWithDirectoryFiltersOutDirectory() throws Exception {

@Test
public void testMatchWithoutParentDirectory() throws Exception {
// TODO: Java core test failing on windows, https://issues.apache.org/jira/browse/BEAM-10741
assumeFalse(SystemUtils.IS_OS_WINDOWS);
Path pattern =
LocalResourceId.fromPath(temporaryFolder.getRoot().toPath(), true /* isDirectory */)
.resolve("non_existing_dir", StandardResolveOptions.RESOLVE_DIRECTORY)
Expand All @@ -417,6 +420,8 @@ public void testMatchWithoutParentDirectory() throws Exception {

@Test
public void testMatchNewResource() {
// TODO: Java core test failing on windows, https://issues.apache.org/jira/browse/BEAM-10742
assumeFalse(SystemUtils.IS_OS_WINDOWS);
LocalResourceId fileResource =
localFileSystem.matchNewResource("/some/test/resource/path", false /* isDirectory */);
LocalResourceId dirResource =
Expand Down
Loading

0 comments on commit 094d06c

Please sign in to comment.