mattcasters commented on a change in pull request #15916: URL: https://github.com/apache/beam/pull/15916#discussion_r749199313
########## File path: sdks/java/io/neo4j/src/test/java/org/apache/beam/sdk/io/neo4j/Neo4jIOIT.java ########## @@ -0,0 +1,268 @@ +/* + * 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.neo4j; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.apache.beam.sdk.PipelineResult; +import org.apache.beam.sdk.coders.SerializableCoder; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.testing.PAssert; +import org.apache.beam.sdk.testing.TestPipeline; +import org.apache.beam.sdk.transforms.Create; +import org.apache.beam.sdk.transforms.ParDo; +import org.apache.beam.sdk.transforms.SerializableFunction; +import org.apache.beam.sdk.values.PBegin; +import org.apache.beam.sdk.values.PCollection; +import org.apache.beam.sdk.values.Row; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.neo4j.driver.Driver; +import org.neo4j.driver.Record; +import org.neo4j.driver.Result; +import org.neo4j.driver.Session; +import org.testcontainers.containers.Neo4jContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.utility.DockerImageName; + +@RunWith(JUnit4.class) +public class Neo4jIOIT { + + private static Network network; + private static Neo4jContainer<?> neo4jContainer; + + @Rule public transient TestPipeline parameterizedReadPipeline = TestPipeline.create(); + @Rule public transient TestPipeline writeUnwindPipeline = TestPipeline.create(); + @Rule public transient TestPipeline largeWriteUnwindPipeline = TestPipeline.create(); + + @BeforeClass + public static void setup() throws Exception { + // network sharing doesn't work with ClassRule + network = Network.newNetwork(); + + neo4jContainer = + new Neo4jContainer<>(DockerImageName.parse("neo4j").withTag(Neo4jTestUtil.NEO4J_VERSION)) + .withStartupAttempts(1) + .withExposedPorts(7687, 7474) + .withNetwork(network) + .withEnv( + "NEO4J_AUTH", Neo4jTestUtil.NEO4J_USERNAME + "/" + Neo4jTestUtil.NEO4J_PASSWORD) + .withEnv("NEO4J_dbms_default_listen_address", "0.0.0.0") + .withNetworkAliases(Neo4jTestUtil.NEO4J_HOSTNAME) + .withSharedMemorySize(256 * 1024 * 1024L); // 256MB + + // Start Neo4j + neo4jContainer.start(); + + // Start with an empty database to use for testing. + // This prevents any possibility of some old data messing up the test results. + // We add a unique constraint to see we're not trying to create nodes twice in the larger test + // below + // + Neo4jTestUtil.executeOnNeo4j( + "CREATE OR REPLACE DATABASE " + Neo4jTestUtil.NEO4J_DATABASE, false); + Neo4jTestUtil.executeOnNeo4j( + "CREATE CONSTRAINT something_id_unique ON (n:Something) ASSERT n.id IS UNIQUE", true); + } + + @AfterClass + public static void tearDown() { + neo4jContainer.stop(); + neo4jContainer.close(); + + try { + network.close(); + } catch (Exception e) { + // ignore + } + } + + @Test + public void testParameterizedRead() throws Exception { + PBegin begin = parameterizedReadPipeline.begin(); + PCollection<String> stringsCollections = + begin.apply(Create.of(Arrays.asList("one", "two", "three"))); Review comment: The goal was not code brevity but clarity in this case. But sure :-) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
