Author: gk Date: Wed Dec 18 15:31:27 2019 New Revision: 1871755 URL: http://svn.apache.org/viewvc?rev=1871755&view=rev Log: - check for mysql < 8 or mariadb < 10.3 to skip likeResults test in test DataTest.testLikeClauseEscaping, TORQUE-353 - add more inline docs in pom.xml and test (bulk fail) - fix log4j2-test.xml debug in torque.util package
Modified: db/torque/torque4/trunk/torque-test/pom.xml db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java db/torque/torque4/trunk/torque-test/src/test/resources/log4j2-test.xml Modified: db/torque/torque4/trunk/torque-test/pom.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/pom.xml?rev=1871755&r1=1871754&r2=1871755&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-test/pom.xml (original) +++ db/torque/torque4/trunk/torque-test/pom.xml Wed Dec 18 15:31:27 2019 @@ -522,7 +522,7 @@ <!--excludedGroups>docker</excludedGroups--> <forkCount>1</forkCount> <reuseForks>false</reuseForks> - <!-- forkMode>pertest</forkMode--><!-- normally pertest, if remote debugging with mvnDebug port 8000, setting in console -DforkMode=never or forkCount=0 seems to have no effect, set here --> + <!-- change forkCount = 1, if remote debugging with mvnDebug port 8000, set forkCount=0 --> <systemPropertyVariables combine.children="override"> <torque.configuration.file>src/test/profile/${torque.test.profileDirectory}/Torque.properties</torque.configuration.file> <torque.callback>host</torque.callback> @@ -1172,7 +1172,15 @@ </build> </profile> <!-- + todo: add docker profiles for postgresql, ... mvn -Pmysql,docker-testcontainer,managers,beans clean test + be careful to run test with @DockerCallback: + + mvnDebug -Pmysql,docker-testcontainer,managers,beans clean test -Dtest=DataContainerTest#testLikeClauseEscaping + + The following test call will fail, although database will be generated (prepare-mysql-databas) but docker is not initialized in the unit test as second step: + mvnDebug -Pmysql,docker-testcontainer,managers,beans clean test -Dtest=DataTest#testLikeClauseEscaping + --> <profile> <id>docker-testcontainer</id> Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1871755&r1=1871754&r2=1871755&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original) +++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Wed Dec 18 15:31:27 2019 @@ -83,6 +83,7 @@ import org.apache.torque.util.CountHelpe import org.apache.torque.util.Transaction; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.ArgumentsSource; +import org.opentest4j.AssertionFailedError; /** * Runtime tests. @@ -1260,8 +1261,10 @@ public class DataTest extends BaseDataba assertEquals(1, authors.size()); } + @Test - public void testLikeClauseEscaping() throws Exception + @ArgumentsSource(AdapterProvider.class) + public void testLikeClauseEscaping(Adapter adapter) throws Exception { String[] authorNames = {"abc", "bbc", "a_c", "a%c", "a\\c", @@ -1284,9 +1287,16 @@ public class DataTest extends BaseDataba // %\\\\c fails, see https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html, // MySQL uses C escape syntax in strings.. you must double any \ that you use in LIKE strings. // That is platform specific mysql: - // likeResults.put("%\\\\\\\\c", "a\\c"); // succeeds in mysql - // other platforms ? - //likeResults.put("%\\\\c", "a\\c"); // fails in mysql + + // succeeded only in mysql 5.x: + if (adapter instanceof MysqlAdapter && + ( getMysqlMajorVersion() < 8 || getMysqlVersion().matches("10\\.[12]\\..*\\-MariaDB") )) { + // likeResults.put("%\\\\\\\\c", "a\\c"); + log.warn("If using MySQL < 8 this test may fail, skipping special escape, " + + "see https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html and issue TORQUE-353"); + } else { + likeResults.put("%\\\\c", "a\\c"); + } likeResults.put("a\\*c", "a*c"); likeResults.put("a\\*%", "a*c"); @@ -1333,6 +1343,8 @@ public class DataTest extends BaseDataba "Name of author should be " + authorNames[i]); } + boolean bulkOk = true; + StringBuffer errors = new StringBuffer(); for (Map.Entry<String, String> likeResult : likeResults.entrySet()) { // System.out.println("Key: " + likeResult.getKey() + " - Value: " + likeResult.getValue()); @@ -1353,18 +1365,29 @@ public class DataTest extends BaseDataba + likeResult.getKey(), e); } - assertEquals( 1, - authorList.size(), - "AuthorList contained " + authorList.size() + ", but should contain one author" - + " when querying for " + likeResult.getKey()); - Author author = authorList.get(0); - assertEquals( - likeResult.getValue(), - author.getName(), - "Name of author should be " - + likeResult.getValue() - + " when querying for " - + likeResult.getKey()); + try { + assertEquals( 1, + authorList.size(), + "AuthorList contained " + authorList.size() + ", but should contain one author" + + " when querying for " + likeResult.getKey()); + Author author = authorList.get(0); + assertEquals( + likeResult.getValue(), + author.getName(), + "Name of author should be " + + likeResult.getValue() + + " when querying for " + + likeResult.getKey()); + } catch (AssertionFailedError e) { + log.error("assert failed, but proceeding", e); + bulkOk = false; + errors.append(e.getMessage()).append("expected:") + .append(e.getExpected().getValue()).append('|').append("actual:") + .append(e.getActual().getValue()).append("\r\n"); + } + } + if (!bulkOk) { + fail(errors.toString()); } // check that case insensitivity is maintained if Modified: db/torque/torque4/trunk/torque-test/src/test/resources/log4j2-test.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/resources/log4j2-test.xml?rev=1871755&r1=1871754&r2=1871755&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-test/src/test/resources/log4j2-test.xml (original) +++ db/torque/torque4/trunk/torque-test/src/test/resources/log4j2-test.xml Wed Dec 18 15:31:27 2019 @@ -32,8 +32,8 @@ <AppenderRef ref="console" level="INFO" /> </Logger> <!-- get queries: --> - <Logger name="org.apache.torque.util" additivity="false"> - <AppenderRef ref="torque" level="DEBUG"/> + <Logger name="org.apache.torque.util" additivity="false" level="DEBUG"> + <AppenderRef ref="torque"/> <AppenderRef ref="console" level="INFO"/> </Logger> <Logger name="org.apache.commons.beanutils" additivity="false" level="WARN"> --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org For additional commands, e-mail: torque-dev-h...@db.apache.org