slinkydeveloper commented on a change in pull request #18176: URL: https://github.com/apache/flink/pull/18176#discussion_r783963851
########## File path: flink-table/flink-table-planner/src/test/java/org/apache/flink/connector/file/table/FileSystemTableSinkStreamingTest.java ########## @@ -0,0 +1,94 @@ +/* + * 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.flink.connector.file.table; + +import org.apache.flink.table.api.DataTypes; +import org.apache.flink.table.api.Schema; +import org.apache.flink.table.api.TableDescriptor; +import org.apache.flink.table.planner.runtime.utils.StreamingTestBase; +import org.apache.flink.types.Row; +import org.apache.flink.util.CloseableIterator; + +import org.junit.Test; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Test of the filesystem source in streaming mode. */ +public class FileSystemTableSinkStreamingTest extends StreamingTestBase { + + @Test + public void testMonitorContinuously() throws Exception { + // Create temp dir + File testPath = TEMPORARY_FOLDER.newFolder(); + + // Write first csv file out + Files.write( + Paths.get(testPath.getPath(), "input_0.csv"), + Arrays.asList("1", "2", "3"), + StandardOpenOption.CREATE); + + Duration monitorInterval = Duration.ofSeconds(1); + + tEnv().createTable( + "my_streaming_table", + TableDescriptor.forConnector("filesystem") + .schema(Schema.newBuilder().column("data", DataTypes.INT()).build()) + .format("testcsv") + .option(FileSystemConnectorOptions.PATH, testPath.getPath()) + .option( + FileSystemConnectorOptions.SOURCE_WATCH_INTERVAL, + monitorInterval) + .build()); + + CloseableIterator<Row> resultsIterator = + tEnv().sqlQuery("SELECT * FROM my_streaming_table").execute().collect(); + + List<Integer> actual = new ArrayList<>(); + + // Iterate over the first 3 rows + for (int i = 0; i < 3; i++) { + actual.add(resultsIterator.next().<Integer>getFieldAs(0)); + } + + // Write second csv file out + Files.write( Review comment: No need for that, `TemporaryFolder` rule already take care of cleanup at the end of the test -- 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]
