Skip to content

Commit

Permalink
WIP: Move test to sdks/io directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgajowy committed Nov 2, 2017
1 parent fa2f43f commit dee9753
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 91 deletions.
53 changes: 53 additions & 0 deletions sdks/java/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>

<profiles>
<profile>
<id>io-it</id>
<activation>
<property><name>io-it</name></property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<useManifestOnlyJar>false</useManifestOnlyJar>
<skip>${skipDefaultIT}</skip>
<parallel>all</parallel>
<threadCount>4</threadCount>
<systemPropertyVariables>
<beamTestPipelineOptions>${integrationTestPipelineOptions}</beamTestPipelineOptions>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</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>
<properties>
<skipITs>false</skipITs>
</properties>
</profile>
</profiles>

<build>
<resources>
<resource>
Expand Down Expand Up @@ -359,5 +404,13 @@
<version>2.21</version>
<scope>test</scope>
</dependency>


<!--&lt;!&ndash;CYCLES - directRunner uses the core module&ndash;&gt;-->
<!--<dependency>-->
<!--<groupId>org.apache.beam</groupId>-->
<!--<artifactId>beam-runners-direct-java</artifactId>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
</dependencies>
</project>

This file was deleted.

1 change: 1 addition & 0 deletions sdks/java/io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<module>mqtt</module>
<module>redis</module>
<module>solr</module>
<module>text</module>
<module>tika</module>
<module>xml</module>
</modules>
Expand Down
84 changes: 84 additions & 0 deletions sdks/java/io/text/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<parent>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-parent</artifactId>
<version>2.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>beam-sdks-java-io-text</artifactId>
<name>Apache Beam :: SDKs :: Java :: IO :: Text</name>
<description>IO to read and write on Text datasource.</description>

<dependencies>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-direct-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</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-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>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.apache.beam.sdk.io.text;

import com.google.common.hash.Hashing;
import java.nio.charset.StandardCharsets;
import org.apache.beam.sdk.io.GenerateSequence;
import org.apache.beam.sdk.io.TextIO;
import org.apache.beam.sdk.io.common.HashingFn;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.testing.TestPipeline;
import org.apache.beam.sdk.transforms.Combine;
import org.apache.beam.sdk.transforms.MapElements;
import org.apache.beam.sdk.transforms.SerializableFunction;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.TypeDescriptors;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** A test of {@link org.apache.beam.sdk.io.TextIO}. */
@RunWith(JUnit4.class)
public class TextIOIT {

private static final String FILE_BASENAME = "textioit";
private static final long LINES_OF_TEXT_COUNT = 10000L;

@Rule public TestPipeline pipelineWrite = TestPipeline.create();
@Rule public TestPipeline pipelineRead = TestPipeline.create();


@Test
public void testWriteThenRead() {
runWrite();
runRead();
}

private void runWrite() {
pipelineWrite
.apply(GenerateSequence.from(0).to(LINES_OF_TEXT_COUNT))
.apply(MapElements.into(TypeDescriptors.strings()).via(produceTextLine()))
.apply(TextIO.write().to(FILE_BASENAME));

pipelineWrite.run().waitUntilFinish();
}

private SerializableFunction<Long, String> produceTextLine() {
return (SerializableFunction<Long, String>)
seed ->
Hashing.murmur3_128().hashString(seed.toString(), StandardCharsets.UTF_8).toString();
}

private void runRead() {
PCollection<String> files =
pipelineRead.apply(TextIO.read().from(String.format("%s*", FILE_BASENAME)));

PCollection<String> consolidatedHashcode =
files.apply(Combine.globally(new HashingFn()).withoutDefaults());

PAssert.that(consolidatedHashcode).containsInAnyOrder("ccae48ff685c1822e9f4d510363bf018");

pipelineRead.run().waitUntilFinish();
}
}

/*
Next steps:
- use one pipeline instead of the two (investigation)
- Should we pre calculate them or calculate them during test runs?
- test setup & cleanup
- Better files destination (filesystem? path?)
- parametrize this test (data amount, filesystem, path)
*/

0 comments on commit dee9753

Please sign in to comment.