Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sdks/java/io/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.
*/
package org.apache.beam.sdk.io.common;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.sql.DataSource;
import org.postgresql.ds.PGSimpleDataSource;

/**
* This class contains helper methods to ease database usage in tests.
*/
public class DatabaseTestHelper {

public static PGSimpleDataSource getPostgresDataSource(IOTestPipelineOptions options) {
PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setDatabaseName(options.getPostgresDatabaseName());
dataSource.setServerName(options.getPostgresServerName());
dataSource.setPortNumber(options.getPostgresPort());
dataSource.setUser(options.getPostgresUsername());
dataSource.setPassword(options.getPostgresPassword());
dataSource.setSsl(options.getPostgresSsl());
return dataSource;
}

public static void createTable(DataSource dataSource, String tableName)
throws SQLException {
try (Connection connection = dataSource.getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute(
String.format("create table %s (id INT, name VARCHAR(500))", tableName));
}
}
}

public static void deleteTable(DataSource dataSource, String tableName)
throws SQLException {
if (tableName != null) {
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate(String.format("drop table %s", tableName));
}
}
}

public static String getTestTableName(String testIdentifier) {
SimpleDateFormat formatter = new SimpleDateFormat();
formatter.applyPattern("yyyy_MM_dd_HH_mm_ss_S");
return String.format("BEAMTEST_%s_%s", testIdentifier, formatter.format(new Date()));
}

public static String getPostgresDBUrl(IOTestPipelineOptions options) {
return String.format(
"jdbc:postgresql://%s:%s/%s",
options.getPostgresServerName(),
options.getPostgresPort(),
options.getPostgresDatabaseName()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void processElement(ProcessContext c) {
private static final Map<Integer, String> EXPECTED_HASHES = ImmutableMap.of(
1000, "7d94d63a41164be058a9680002914358",
100_000, "c7cbddb319209e200f1c5eebef8fe960",
600_000, "e2add2f680de9024e9bc46cd3912545e",
5_000_000, "c44f8a5648cd9207c9c6f77395a998dc"
);

Expand Down
212 changes: 212 additions & 0 deletions sdks/java/io/hadoop/input-format/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,197 @@
<name>Apache Beam :: SDKs :: Java :: IO :: Hadoop :: input-format</name>
<description>IO to read data from data sources which implement Hadoop Input Format.</description>

<profiles>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I simply duplicated the code from jdbc io, applying necessary changes. I think it can be improved later, see: https://issues.apache.org/jira/browse/BEAM-3440

<!-- Include the Google Cloud Dataflow runner activated by -DintegrationTestRunner=dataflow -->
<profile>
<id>dataflow-runner</id>
<activation>
<property>
<name>integrationTestRunner</name>
<value>dataflow</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>

<!--
This profile invokes PerfKitBenchmarker, which does benchmarking of
the IO ITs. The arguments passed to it allow it to invoke mvn again
with the desired benchmark.

To invoke this, run:

mvn verify -Dio-it-suite -pl sdks/java/io/hadoop/input-format
-DpkbLocation="path-to-pkb.py" \
-DintegrationTestPipelineOptions='["-tempRoot=gs://bucket/staging"]'
-->
<profile>
<id>io-it-suite</id>
<activation>
<property><name>io-it-suite</name></property>
</activation>
<properties>
<!-- This is based on the location of the current pom relative to the root
See discussion in BEAM-2460 -->
<beamRootProjectDir>${project.parent.parent.parent.parent.parent.basedir}</beamRootProjectDir>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>${groovy-maven-plugin.version}</version>
<executions>
<execution>
<id>find-supported-python-for-compile</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${beamRootProjectDir}/sdks/python/findSupportedPython.groovy</source>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven-exec-plugin.version}</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${python.interpreter.bin}</executable>
<arguments>
<argument>${pkbLocation}</argument>
<argument>-benchmarks=beam_integration_benchmark</argument>
<argument>-beam_it_profile=io-it</argument>
<argument>-beam_location=${beamRootProjectDir}</argument>
<argument>-beam_prebuilt=true</argument>
<argument>-beam_sdk=java</argument>
<argument>-kubeconfig=${kubeconfig}</argument>
<argument>-kubectl=${kubectl}</argument>
<!-- runner overrides, controlled via forceDirectRunner -->
<argument>${pkbBeamRunnerProfile}</argument>
<argument>${pkbBeamRunnerOption}</argument>
<!-- specific to this IO -->
<argument>-beam_it_module=sdks/java/io/hadoop/input-format</argument>
<argument>-beam_it_class=org.apache.beam.sdk.io.hadoop.inputformat.HadoopInputFormatIOIT</argument>
<argument>-beam_options_config_file=${beamRootProjectDir}/.test-infra/kubernetes/postgres/pkb-config.yml</argument>
<argument>-beam_kubernetes_scripts=${beamRootProjectDir}/.test-infra/kubernetes/postgres/postgres.yml</argument>
<!-- arguments typically defined by user -->
<argument>-beam_it_options=${integrationTestPipelineOptions}</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<!--
io-it-suite-local overrides part of io-it-suite, allowing users to run tests
when they are on a separate network from the kubernetes cluster by
creating a LoadBalancer service.
-->
<profile>
<id>io-it-suite-local</id>
<activation><property><name>io-it-suite-local</name></property></activation>
<properties>
<!-- This is based on the location of the current pom relative to the root
See discussion in BEAM-2460 -->
<beamRootProjectDir>${project.parent.parent.parent.parent.parent.basedir}</beamRootProjectDir>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>${groovy-maven-plugin.version}</version>
<executions>
<execution>
<id>find-supported-python-for-compile</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${beamRootProjectDir}/sdks/python/findSupportedPython.groovy</source>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven-exec-plugin.version}</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${python.interpreter.bin}</executable>
<arguments>
<argument>${pkbLocation}</argument>
<argument>-benchmarks=beam_integration_benchmark</argument>
<argument>-beam_it_profile=io-it</argument>
<argument>-beam_location=${beamRootProjectDir}</argument>
<argument>-beam_prebuilt=true</argument>
<argument>-beam_sdk=java</argument>
<argument>-kubeconfig=${kubeconfig}</argument>
<argument>-kubectl=${kubectl}</argument>
<!-- runner overrides, controlled via forceDirectRunner -->
<argument>${pkbBeamRunnerProfile}</argument>
<argument>${pkbBeamRunnerOption}</argument>
<!-- specific to this IO -->
<argument>-beam_it_module=sdks/java/io/hadoop/input-format</argument>
<argument>-beam_it_class=org.apache.beam.sdk.io.hadoop.inputformat.HadoopInputFormatIOIT</argument>
<argument>-beam_options_config_file=${beamRootProjectDir}/.test-infra/kubernetes/postgres/pkb-config-local.yml</argument>
<argument>-beam_kubernetes_scripts=${beamRootProjectDir}/.test-infra/kubernetes/postgres/postgres.yml,${beamRootProjectDir}/.test-infra/kubernetes/postgres/postgres-service-for-local-dev.yml</argument>
<!-- arguments typically defined by user -->
<argument>-beam_it_options=${integrationTestPipelineOptions}</argument>
</arguments>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -69,10 +260,31 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-common</artifactId>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading