You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-dev@incubator.apache.org by Niklas Gustavsson <ni...@protocol7.com> on 2007/08/25 18:10:57 UTC

Re: RetrieveTest and RetrievePassiveTest failing on Linux due to line separators

Thanks for reporting! I've implemented a very similar solution as you 
describe below. Please test to see if it works better.

/niklas

Peter Kostouros wrote:
> Hi
> 
> Test cases
> 
> ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrieveTest 
> and
> ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrievePassiveTest 
> 
> 
> are failing under a Unix/Linux type of environment: the file sizes do 
> not match - looks like a \r\n issue.
> 
>  From the the org.apache.commons.net.ftp.FTPClient document page, 
> paraphrasing, retrieveFile(String, OutputStream) retrieves a named file 
> from the server and writes it to the given OutputStream. ... If the 
> current file type is ASCII, line separators in the file are converted to 
> the local representation.
> Here is how I got around it (not yet tested under Windows)
> 
> --- RetrieveTest.java~    2007-08-24 20:50:43.000000000 +1000
> +++ RetrieveTest.java    2007-08-24 20:45:43.000000000 +1000
> @@ -30,6 +30,8 @@
>     private static final File TEST_FILE = new File(ROOT_DIR, 
> TEST_FILENAME);
> 
>     private static byte[] testData = null;
> +
> +    private static final String EOL = 
> System.getProperty("line.separator");
>        /* (non-Javadoc)
>      * @see org.apache.ftpserver.clienttests.ClientTestTemplate#setUp()
> @@ -37,7 +39,12 @@
>     protected void setUp() throws Exception {
>         super.setUp();
> 
> -    testData = "TESTDATA\r\n".getBytes("UTF-8");
> +    if (EOL.equals("\n"))
> +            testData = "TESTDATA\n".getBytes("UTF-8");
> +    else if (EOL.equals("\r\n"))
> +        testData = "TESTDATA\r\n".getBytes("UTF-8");
> +    else
> +        testData = "TESTDATA\r\n".getBytes("UTF-8");
>                client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
>     }
> 
> The failed sure-fire report for RetrieveTest:
> 
> ------------------------------------------------------------------------------- 
> 
> Test set: org.apache.ftpserver.clienttests.RetrieveTest
> ------------------------------------------------------------------------------- 
> 
> Tests run: 7, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 9.962 
> sec <<< FAILURE!
> testRetrieve(org.apache.ftpserver.clienttests.RetrieveTest)  Time 
> elapsed: 1.276 sec  <<< FAILURE!
> junit.framework.AssertionFailedError: Arrays are of different length
>    at junit.framework.Assert.fail(Assert.java:47)
>    at 
> org.apache.ftpserver.test.TestUtil.assertArraysEqual(TestUtil.java:164)
>    at 
> org.apache.ftpserver.clienttests.RetrieveTest.testRetrieve(RetrieveTest.java:55) 
> 
>    at 
> org.apache.ftpserver.clienttests.RetrieveTest.testRetrieve(RetrieveTest.java:55) 
> 
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at junit.framework.TestCase.runTest(TestCase.java:154)
>    at junit.framework.TestCase.runBare(TestCase.java:127)
>    at junit.framework.TestResult$1.protect(TestResult.java:106)
>    at junit.framework.TestResult.runProtected(TestResult.java:124)
>    at junit.framework.TestResult.run(TestResult.java:109)
>    at junit.framework.TestCase.run(TestCase.java:118)
>    at junit.framework.TestSuite.runTest(TestSuite.java:208)
>    at junit.framework.TestSuite.run(TestSuite.java:203)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at 
> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
>    at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138) 
> 
>    at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125) 
> 
>    at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at 
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:299) 
> 
>    at 
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:837) 
> 
> 
> testRetrieveWithRestart(org.apache.ftpserver.clienttests.RetrieveTest)  
> Time elapsed: 2.124 sec  <<< FAILURE!
> junit.framework.AssertionFailedError: Arrays are of different length
>    at junit.framework.Assert.fail(Assert.java:47)
>    at 
> org.apache.ftpserver.test.TestUtil.assertArraysEqual(TestUtil.java:164)
>    at 
> org.apache.ftpserver.clienttests.RetrieveTest.testRetrieveWithRestart(RetrieveTest.java:88) 
> 
>    at 
> org.apache.ftpserver.clienttests.RetrieveTest.testRetrieveWithRestart(RetrieveTest.java:88) 
> 
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at junit.framework.TestCase.runTest(TestCase.java:154)
>    at junit.framework.TestCase.runBare(TestCase.java:127)
>    at junit.framework.TestResult$1.protect(TestResult.java:106)
>    at junit.framework.TestResult.runProtected(TestResult.java:124)
>    at junit.framework.TestResult.run(TestResult.java:109)
>    at junit.framework.TestCase.run(TestCase.java:118)
>    at junit.framework.TestSuite.runTest(TestSuite.java:208)
>    at junit.framework.TestSuite.run(TestSuite.java:203)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at 
> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
>    at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138) 
> 
>    at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125) 
> 
>    at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at 
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:299) 
> 
>    at 
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:837) 
> 
> 
> testRetrieveWithPath(org.apache.ftpserver.clienttests.RetrieveTest)  
> Time elapsed: 1.194 sec  <<< FAILURE!
> junit.framework.AssertionFailedError: Arrays are of different length
>    at junit.framework.Assert.fail(Assert.java:47)
>    at 
> org.apache.ftpserver.test.TestUtil.assertArraysEqual(TestUtil.java:164)
>    at 
> org.apache.ftpserver.clienttests.RetrieveTest.testRetrieveWithPath(RetrieveTest.java:105) 
> 
>    at 
> org.apache.ftpserver.clienttests.RetrieveTest.testRetrieveWithPath(RetrieveTest.java:105) 
> 
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at junit.framework.TestCase.runTest(TestCase.java:154)
>    at junit.framework.TestCase.runBare(TestCase.java:127)
>    at junit.framework.TestResult$1.protect(TestResult.java:106)
>    at junit.framework.TestResult.runProtected(TestResult.java:124)
>    at junit.framework.TestResult.run(TestResult.java:109)
>    at junit.framework.TestCase.run(TestCase.java:118)
>    at junit.framework.TestSuite.runTest(TestSuite.java:208)
>    at junit.framework.TestSuite.run(TestSuite.java:203)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at 
> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
>    at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138) 
> 
>    at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125) 
> 
>    at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>    at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>    at java.lang.reflect.Method.invoke(Method.java:597)
>    at 
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:299) 
> 
>    at 
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:837) 
> 
> 
> 


Re: RetrieveTest and RetrievePassiveTest failing on Linux due to line separators

Posted by Peter Kostouros <kp...@melbpc.org.au>.
Thanks. These tests now pass for me.

Niklas Gustavsson wrote:
> Thanks for reporting! I've implemented a very similar solution as you 
> describe below. Please test to see if it works better.
>
> /niklas
>
> Peter Kostouros wrote:
>> Hi
>>
>> Test cases
>>
>> ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrieveTest 
>> and
>> ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrievePassiveTest 
>>
>>
>> are failing under a Unix/Linux type of environment: the file sizes do 
>> not match - looks like a \r\n issue.


-- 

Regards

Peter

As always the organisation disavows knowledge of this email