Repository: incubator-drill Updated Branches: refs/heads/master f86639c31 -> 894037ab6
DRILL-1002: Fix TestSqlBracketlessSyntax.checkComplexExpressionParsing() on Windows Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/4d17aeab Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/4d17aeab Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/4d17aeab Branch: refs/heads/master Commit: 4d17aeab866a50bfe3a5d43b3fc874ae2ca84c8a Parents: f86639c Author: Aditya Kishore <[email protected]> Authored: Mon Jun 16 23:18:02 2014 -0700 Committer: Aditya Kishore <[email protected]> Committed: Mon Jun 16 23:25:02 2014 -0700 ---------------------------------------------------------------------- .../java/org/apache/drill/test/DrillAssert.java | 60 ++++++++++++++++++++ .../exec/sql/TestSqlBracketlessSyntax.java | 4 +- .../org/apache/drill/jdbc/test/TestViews.java | 10 ++-- 3 files changed, 67 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4d17aeab/common/src/test/java/org/apache/drill/test/DrillAssert.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/drill/test/DrillAssert.java b/common/src/test/java/org/apache/drill/test/DrillAssert.java new file mode 100644 index 0000000..ddd3b93 --- /dev/null +++ b/common/src/test/java/org/apache/drill/test/DrillAssert.java @@ -0,0 +1,60 @@ +/** + * 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.drill.test; + +import static org.junit.Assert.fail; + +public class DrillAssert { + + public static void assertMultiLineStringEquals(String expected, String actual) { + assertMultiLineStringEquals(null, expected, actual); + } + + public static void assertMultiLineStringEquals(String message, String expected, String actual) { + outside: + if (expected == actual) { + return; + } else if (expected != null && actual != null) { + int idx1 = 0, idx2 = 0; + char ch1, ch2; + while (idx1 < expected.length() && idx2 < actual.length()) { + ch1 = expected.charAt(idx1); + ch2 = actual.charAt(idx2); + if (isNewLineChar(ch1)) { + idx1++; continue; + } else if (isNewLineChar(ch2)) { + idx2++; continue; + } else if (ch1 != ch2) { + break outside; + } else { + idx1++; idx2++; + } + } + // skip newlines at the end + while(idx1 < expected.length() && isNewLineChar(expected.charAt(idx1))) idx1++; + while(idx2 < actual.length() && isNewLineChar(actual.charAt(idx2))) idx2++; + if (idx1 == expected.length() && idx2 == actual.length()) return; + } + + fail(message != null ? message : "Expected: " + expected + ", but was: " + actual); + } + + private static boolean isNewLineChar(char ch) { + return (ch == '\r' || ch == '\n'); + } +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4d17aeab/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSqlBracketlessSyntax.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSqlBracketlessSyntax.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSqlBracketlessSyntax.java index 1204e7c..ca1efab 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSqlBracketlessSyntax.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSqlBracketlessSyntax.java @@ -25,8 +25,8 @@ import net.hydromatic.optiq.tools.StdFrameworkConfig; import org.apache.drill.exec.planner.sql.DrillConvertletTable; import org.apache.drill.exec.planner.sql.parser.CompoundIdentifierConverter; import org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl; +import org.apache.drill.test.DrillAssert; import org.eigenbase.sql.SqlNode; -import org.junit.Assert; import org.junit.Test; public class TestSqlBracketlessSyntax { @@ -61,7 +61,7 @@ public class TestSqlBracketlessSyntax { SqlNode rewritten = node.accept(new CompoundIdentifierConverter()); String rewrittenQuery = rewritten.toString(); - Assert.assertEquals(expected, rewrittenQuery); + DrillAssert.assertMultiLineStringEquals(expected, rewrittenQuery); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4d17aeab/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java index 6f595af..8e7131c 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java @@ -18,8 +18,10 @@ package org.apache.drill.jdbc.test; import com.google.common.base.Function; + import org.apache.commons.io.FileUtils; import org.apache.drill.exec.store.hive.HiveTestDataGenerator; +import org.apache.drill.test.DrillAssert; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -34,8 +36,6 @@ import static org.junit.Assert.assertTrue; /** Contains tests for creating/droping and using views in Drill. */ public class TestViews extends JdbcTestQueryBase { - private final static String NEW_LINE = System.getProperty("line.separator"); - @BeforeClass public static void generateHive() throws Exception{ new HiveTestDataGenerator().generateTestData(); @@ -283,9 +283,9 @@ public class TestViews extends JdbcTestQueryBase { "WHERE TABLE_NAME = 'testview3'"); result = JdbcAssert.toString(resultSet).trim(); resultSet.close(); - expected = "TABLE_CATALOG=DRILL; TABLE_SCHEMA=dfs.tmp; TABLE_NAME=testview3; VIEW_DEFINITION=SELECT *"+NEW_LINE+"FROM `hive`.`kv`"; - assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), - expected.equals(result)); + expected = "TABLE_CATALOG=DRILL; TABLE_SCHEMA=dfs.tmp; TABLE_NAME=testview3; VIEW_DEFINITION=SELECT *\nFROM `hive`.`kv`"; + DrillAssert.assertMultiLineStringEquals(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), + expected, result); // test record in INFORMATION_SCHEMA.TABLES resultSet = statement.executeQuery("SELECT * FROM INFORMATION_SCHEMA.`TABLES` " +
