AdalbertMemSQL commented on code in PR #23535: URL: https://github.com/apache/beam/pull/23535#discussion_r1023394717
########## sdks/java/io/singlestore/src/test/java/org/apache/beam/sdk/io/singlestore/SingleStoreIOIT.java: ########## @@ -0,0 +1,267 @@ +/* + * 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.singlestore; + +import static org.apache.beam.sdk.io.common.IOITHelper.readIOTestPipelineOptions; + +import com.google.cloud.Timestamp; +import com.singlestore.jdbc.SingleStoreDataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.function.Function; +import javax.sql.DataSource; +import org.apache.beam.sdk.PipelineResult; +import org.apache.beam.sdk.io.GenerateSequence; +import org.apache.beam.sdk.io.common.DatabaseTestHelper; +import org.apache.beam.sdk.io.common.HashingFn; +import org.apache.beam.sdk.io.common.TestRow; +import org.apache.beam.sdk.testing.NeedsRunner; +import org.apache.beam.sdk.testing.PAssert; +import org.apache.beam.sdk.testing.TestPipeline; +import org.apache.beam.sdk.testutils.NamedTestResult; +import org.apache.beam.sdk.testutils.metrics.IOITMetrics; +import org.apache.beam.sdk.testutils.metrics.MetricsReader; +import org.apache.beam.sdk.testutils.metrics.TimeMonitor; +import org.apache.beam.sdk.testutils.publishing.InfluxDBSettings; +import org.apache.beam.sdk.transforms.Combine; +import org.apache.beam.sdk.transforms.Count; +import org.apache.beam.sdk.transforms.ParDo; +import org.apache.beam.sdk.transforms.Sum; +import org.apache.beam.sdk.transforms.Top; +import org.apache.beam.sdk.values.PCollection; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class SingleStoreIOIT { + + private static final String NAMESPACE = SingleStoreIOIT.class.getName(); + + private static final String DATABASE_NAME = "SingleStoreIOIT"; + + private static int numberOfRows; + + private static String tableName; + + private static String serverName; + + private static String username; + + private static String password; + + private static Integer port; + + private static SingleStoreIO.DataSourceConfiguration dataSourceConfiguration; + + private static InfluxDBSettings settings; + + @BeforeClass + public static void setup() { + SingleStoreIOTestPipelineOptions options; + try { + options = readIOTestPipelineOptions(SingleStoreIOTestPipelineOptions.class); + } catch (IllegalArgumentException e) { + options = null; + } + org.junit.Assume.assumeNotNull(options); + + numberOfRows = options.getNumberOfRecords(); + serverName = options.getSingleStoreServerName(); + username = options.getSingleStoreUsername(); + password = options.getSingleStorePassword(); + port = options.getSingleStorePort(); + tableName = DatabaseTestHelper.getTestTableName("IT"); + dataSourceConfiguration = + SingleStoreIO.DataSourceConfiguration.create(serverName + ":" + port) + .withDatabase(DATABASE_NAME) + .withPassword(password) + .withUsername(username); + settings = + InfluxDBSettings.builder() + .withHost(options.getInfluxHost()) + .withDatabase(options.getInfluxDatabase()) + .withMeasurement(options.getInfluxMeasurement()) + .get(); + } + + void createDatabaseIfNotExists() throws SQLException { + DataSource dataSource = + new SingleStoreDataSource( + String.format( + "jdbc:singlestore://%s:%d/?user=%s&password=%s&allowLocalInfile=TRUE", + serverName, port, username, password)); + try (Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement()) { + stmt.executeQuery(String.format("CREATE DATABASE IF NOT EXISTS %s", DATABASE_NAME)); + } + } + + @Test + @Category(NeedsRunner.class) + public void testWriteThenRead() throws Exception { + createDatabaseIfNotExists(); + DataSource dataSource = + new SingleStoreDataSource( + String.format( + "jdbc:singlestore://%s:%d/%s?user=%s&password=%s&allowLocalInfile=TRUE", + serverName, port, DATABASE_NAME, username, password)); + DatabaseTestHelper.createTable(dataSource, tableName); + try { + PipelineResult writeResult = runWrite(); + writeResult.waitUntilFinish(); + PipelineResult readResult = runRead(); + readResult.waitUntilFinish(); Review Comment: number of records is checked here ``` private void testReadResult(PCollection<TestRow> namesAndIds) { PAssert.thatSingleton(namesAndIds.apply("Count All", Count.globally())) .isEqualTo((long) numberOfRows); ``` (lines 248-250) Will add asserts for pipeline status. Thanks! -- 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]
