cryptoe commented on code in PR #13374: URL: https://github.com/apache/druid/pull/13374#discussion_r1026263091
########## integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITSQLBasedBatchIngestion.java: ########## @@ -0,0 +1,63 @@ +/* + * 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.druid.testsEx.msq; + +import org.apache.curator.shaded.com.google.common.collect.ImmutableMap; +import org.apache.druid.testsEx.categories.MultiStageQuery; +import org.apache.druid.testsEx.config.DruidTestRunner; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.Arrays; + +@RunWith(DruidTestRunner.class) +@Category(MultiStageQuery.class) +public class ITSQLBasedBatchIngestion extends AbstractITSQLBasedBatchIngestion +{ + private static final String BATCH_INDEX_TASKS_DIR = "/multi-stage-query/batch-index/"; + + @Test + public void testSQLBasedBatchIngestion() throws Exception + { + // Get list of all directories in batch-index folder. Each folder is considered a test case. + File[] directories = (new File(getClass().getResource(BATCH_INDEX_TASKS_DIR).toURI())).listFiles(File::isDirectory); + int fail_count = 0; + LOG.info("Test will be run for sql in the following directories - \n %s", Arrays.toString(directories)); + for (File dir : directories) { + try { + runMSQTaskandTestQueries(BATCH_INDEX_TASKS_DIR + dir.getName(), "msqBatchIndex_" + dir.getName(), Review Comment: Can we create a parameterized test? That way we will know which test is exactly flaky ########## integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/AbstractITSQLBasedBatchIngestion.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.druid.testsEx.msq; + +import com.google.inject.Inject; +import org.apache.commons.io.IOUtils; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.testing.utils.DataLoaderHelper; +import org.apache.druid.testing.utils.MsqTestQueryHelper; +import org.apache.druid.testing.utils.TestQueryHelper; +import org.apache.druid.testsEx.indexer.AbstractITBatchIndexTest; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +public class AbstractITSQLBasedBatchIngestion +{ + public static final Logger LOG = new Logger(TestQueryHelper.class); + @Inject + private MsqTestQueryHelper msqHelper; + + @Inject + protected TestQueryHelper queryHelper; + + @Inject + private DataLoaderHelper dataLoaderHelper; + + protected String getFileWithFormatFromDir(String dir, String format) throws URISyntaxException + { + File[] file = (new File(getClass().getResource(dir).toURI())).listFiles(pathname -> { + String name = pathname.getName(); + return name.endsWith(format) && pathname.isFile(); + }); + return dir + '/' + file[0].getName(); + } + + protected String getSqlStringFromDir(String dir, String datasource) throws URISyntaxException + { + String filePath = getFileWithFormatFromDir(dir, ".sql"); + String sqlString; + try { + InputStream is = AbstractITBatchIndexTest.class.getResourceAsStream(filePath); + sqlString = IOUtils.toString(is, StandardCharsets.UTF_8); + } + catch (IOException e) { + throw new ISE(e, "could not read query file: %s", filePath); + } + + sqlString = StringUtils.replace( + sqlString, + "%%DATASOURCE%%", + datasource + ); + + return sqlString; + } + + protected void doTestQuery(String dir, String dataSource) throws URISyntaxException + { + String queryFilePath = getFileWithFormatFromDir(dir, ".json"); + try { + String queryResponseTemplate; + try { + InputStream is = AbstractITBatchIndexTest.class.getResourceAsStream(queryFilePath); + queryResponseTemplate = IOUtils.toString(is, StandardCharsets.UTF_8); + } + catch (IOException e) { + throw new ISE(e, "could not read query file: %s", queryFilePath); + } + + queryResponseTemplate = StringUtils.replace( + queryResponseTemplate, + "%%DATASOURCE%%", + dataSource + ); + queryHelper.testQueriesFromString(queryResponseTemplate); + + } + catch (Exception e) { + LOG.error(e, "Error while running test query"); + throw new RuntimeException(e); + } + } + + protected void runMSQTaskandTestQueries(String relativePath, String datasource, Map<String, Object> msqContext) throws Exception Review Comment: lets java doc this method. ########## integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/AbstractITSQLBasedBatchIngestion.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.druid.testsEx.msq; + +import com.google.inject.Inject; +import org.apache.commons.io.IOUtils; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.testing.utils.DataLoaderHelper; +import org.apache.druid.testing.utils.MsqTestQueryHelper; +import org.apache.druid.testing.utils.TestQueryHelper; +import org.apache.druid.testsEx.indexer.AbstractITBatchIndexTest; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +public class AbstractITSQLBasedBatchIngestion +{ + public static final Logger LOG = new Logger(TestQueryHelper.class); + @Inject + private MsqTestQueryHelper msqHelper; + + @Inject + protected TestQueryHelper queryHelper; + + @Inject + private DataLoaderHelper dataLoaderHelper; + + protected String getFileWithFormatFromDir(String dir, String format) throws URISyntaxException + { + File[] file = (new File(getClass().getResource(dir).toURI())).listFiles(pathname -> { + String name = pathname.getName(); + return name.endsWith(format) && pathname.isFile(); + }); + return dir + '/' + file[0].getName(); + } + + protected String getSqlStringFromDir(String dir, String datasource) throws URISyntaxException Review Comment: We are doing the replacement for the data source. So we should mention that in the signature. Lets javadoc this method. ########## integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/AbstractITSQLBasedBatchIngestion.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.druid.testsEx.msq; + +import com.google.inject.Inject; +import org.apache.commons.io.IOUtils; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.testing.utils.DataLoaderHelper; +import org.apache.druid.testing.utils.MsqTestQueryHelper; +import org.apache.druid.testing.utils.TestQueryHelper; +import org.apache.druid.testsEx.indexer.AbstractITBatchIndexTest; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +public class AbstractITSQLBasedBatchIngestion +{ + public static final Logger LOG = new Logger(TestQueryHelper.class); + @Inject + private MsqTestQueryHelper msqHelper; + + @Inject + protected TestQueryHelper queryHelper; + + @Inject + private DataLoaderHelper dataLoaderHelper; + + protected String getFileWithFormatFromDir(String dir, String format) throws URISyntaxException + { + File[] file = (new File(getClass().getResource(dir).toURI())).listFiles(pathname -> { + String name = pathname.getName(); + return name.endsWith(format) && pathname.isFile(); + }); + return dir + '/' + file[0].getName(); + } + + protected String getSqlStringFromDir(String dir, String datasource) throws URISyntaxException + { + String filePath = getFileWithFormatFromDir(dir, ".sql"); + String sqlString; + try { + InputStream is = AbstractITBatchIndexTest.class.getResourceAsStream(filePath); + sqlString = IOUtils.toString(is, StandardCharsets.UTF_8); + } + catch (IOException e) { + throw new ISE(e, "could not read query file: %s", filePath); + } + + sqlString = StringUtils.replace( + sqlString, + "%%DATASOURCE%%", + datasource + ); + + return sqlString; + } + + protected void doTestQuery(String dir, String dataSource) throws URISyntaxException Review Comment: this as well since it will be used in all tests. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
