[ https://issues.apache.org/jira/browse/BEAM-2546?focusedWorklogId=391147&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-391147 ]
ASF GitHub Bot logged work on BEAM-2546: ---------------------------------------- Author: ASF GitHub Bot Created on: 22/Feb/20 15:07 Start Date: 22/Feb/20 15:07 Worklog Time Spent: 10m Work Description: iemejia commented on pull request #10604: BEAM-2546 Beam IO for InfluxDB URL: https://github.com/apache/beam/pull/10604#discussion_r382916818 ########## File path: sdks/java/io/influxdb/src/test/java/org/apache/beam/sdk/io/influxdb/InfluxDBIOIT.java ########## @@ -0,0 +1,190 @@ +package org.apache.beam.sdk.io.influxdb; + +import org.apache.beam.sdk.PipelineResult; + +import org.apache.beam.sdk.io.common.IOTestPipelineOptions; +import org.apache.beam.sdk.options.Default; +import org.apache.beam.sdk.options.Description; +import org.apache.beam.sdk.options.PipelineOptionsFactory; +import org.apache.beam.sdk.testing.PAssert; +import org.apache.beam.sdk.testing.TestPipeline; +import org.apache.beam.sdk.transforms.*; +import org.apache.beam.sdk.values.PCollection; +import org.influxdb.InfluxDB; +import org.influxdb.InfluxDBFactory; +import org.influxdb.dto.Query; +import org.junit.*; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Arrays; + + +/** + * A test of {@link org.apache.beam.sdk.io.influxdb.InfluxDBIO} on an independent InfluxDB instance. + * + * <p>This test requires a running instance of InfluxDB. Pass in connection information using + * PipelineOptions: + * + * <pre> + * ./gradlew integrationTest -p sdks/java/io/influxdb -DintegrationTestPipelineOptions='[ + * "--influxdburl=http://localhost:8086", + * "--infuxDBDatabase=mypass", + * "--username=username" + * "--password=password"]' + * --tests org.apache.beam.sdk.io.influxdb.InfluxDBIOIT + * -DintegrationTestRunner=direct + * </pre> + * + */ + + +@RunWith(JUnit4.class) +public class InfluxDBIOIT { + + private static InfluxDBPipelineOptions options; + + @Rule + public final TestPipeline writePipeline = TestPipeline.create(); + @Rule + public final TestPipeline readPipeline = TestPipeline.create(); + + /** + * InfluxDBIO options. + */ + public interface InfluxDBPipelineOptions extends IOTestPipelineOptions { + @Description("InfluxDB host (host name/ip address)") + @Default.String("http://localhost:8086") + String getInfluxDBURL(); + void setInfluxDBURL(String value); + + @Description("Username for InfluxDB") + @Default.String("superadmin") + String getInfluxDBUserName(); + void setInfluxDBUserName(String value); + + @Description("Password for InfluxDB") + @Default.String("supersecretpassword") + String getInfluxDBPassword(); + void setInfluxDBPassword(String value); + + @Description("InfluxDB database name") + @Default.String("db0") + String getDatabaseName(); + void setDatabaseName(String value); + + } + @BeforeClass + public static void setUp() { + PipelineOptionsFactory.register(InfluxDBPipelineOptions.class); + options = TestPipeline.testingPipelineOptions().as(InfluxDBPipelineOptions.class); + } + + @After + public void clear(){ + try (InfluxDB connection = InfluxDBFactory.connect(options.getInfluxDBURL(), + options.getInfluxDBUserName(), options.getInfluxDBPassword())){ + connection.query(new Query("DROP DATABASE \"" + options.getDatabaseName() + "\"")); + } + } + @Before + public void initTest(){ + try (InfluxDB connection = InfluxDBFactory.connect(options.getInfluxDBURL(), + options.getInfluxDBUserName(), options.getInfluxDBPassword())){ + connection.query(new Query("CREATE DATABASE \"" + options.getDatabaseName() + "\"")); + } + } + @Test + public void testWriteAndRead() { + final int noofElementsToReadAndWrite = 1000; + writePipeline + .apply("Generate data", Create.of(GenerateData.getMetric(noofElementsToReadAndWrite))) + .apply( + "Write data to InfluxDB", + InfluxDBIO.write() + .withConfiguration(InfluxDBIO.DataSourceConfiguration.create(options.getInfluxDBURL(), + options.getInfluxDBUserName(), options.getInfluxDBPassword())) + .withDatabase(options.getDatabaseName()) + .withSslInvalidHostNameAllowed(false) + .withSslEnabled(false)); + writePipeline.run().waitUntilFinish(); + PCollection<String> readVals = + readPipeline + .apply( + "Read all points in Influxdb", + InfluxDBIO.read() + .withDataSourceConfiguration(InfluxDBIO.DataSourceConfiguration.create(options.getInfluxDBURL(), + options.getInfluxDBUserName(), options.getInfluxDBPassword())) + .withDatabase(options.getDatabaseName()).withQuery("SELECT * FROM \"test_m\"") + .withSslInvalidHostNameAllowed(false) + .withSslEnabled(false)); + + PAssert.thatSingleton(readVals.apply("Count All", Count.globally())) + .isEqualTo((long) noofElementsToReadAndWrite); + PipelineResult readResult = readPipeline.run(); + readResult.waitUntilFinish(); + } + + @Test + public void testWriteAndReadWithSingleMetric() { Review comment: Since MultipleMetric is a more general case of this one, maybe we can remove this case as well as the auxiliar getMetric method in GenerateData. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 391147) Time Spent: 5h (was: 4h 50m) > Create InfluxDbIO > ----------------- > > Key: BEAM-2546 > URL: https://issues.apache.org/jira/browse/BEAM-2546 > Project: Beam > Issue Type: New Feature > Components: io-ideas > Reporter: Jean-Baptiste Onofré > Assignee: Jean-Baptiste Onofré > Priority: Major > Time Spent: 5h > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)