You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2014/04/28 13:10:01 UTC

svn commit: r1590602 - /sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java

Author: desruisseaux
Date: Mon Apr 28 11:10:00 2014
New Revision: 1590602

URL: http://svn.apache.org/r1590602
Log:
Test a code path for non-seekable channel.

Modified:
    sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java

Modified: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java?rev=1590602&r1=1590601&r2=1590602&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java [UTF-8] Mon Apr 28 11:10:00 2014
@@ -24,6 +24,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.InvalidMarkException;
+import java.nio.channels.ByteChannel;
 import javax.imageio.stream.ImageOutputStream;
 import org.apache.sis.test.DependsOnMethod;
 import org.junit.Test;
@@ -85,6 +86,20 @@ public strictfp class ChannelDataOutputT
     }
 
     /**
+     * May be invoked after {@link #initialize(String, int, int)} for replacing the seekable byte channel
+     * by a non-seekable one. Used for testing different code paths in {@link ChannelDataOutput}.
+     */
+    private void nonSeekableChannel() throws IOException {
+        final ByteChannel channel = (ByteChannel) testedStream.channel;
+        testedStream = new ChannelDataOutput(testedStream.filename, new ByteChannel() {
+            @Override public boolean isOpen()                                 {return channel.isOpen();}
+            @Override public int     read(ByteBuffer dst)  throws IOException {return channel.read(dst);}
+            @Override public int     write(ByteBuffer src) throws IOException {return channel.write(src);}
+            @Override public void    close()               throws IOException {channel.close();}
+        }, testedStream.buffer);
+    }
+
+    /**
      * Fills a stream with random data and compares the result with a reference output stream.
      * We allocate a small buffer for the {@code ChannelDataOutput} in order to force frequent
      * interactions between the buffer and the channel.
@@ -136,14 +151,26 @@ public strictfp class ChannelDataOutputT
     }
 
     /**
-     * Tests seek ahead of buffer capacity.
+     * Tests seeking ahead of buffer capacity.
      *
      * @throws IOException Should never happen.
      */
     @Test
     @DependsOnMethod("testWriteAndSeek")
     public void testSeekAhead() throws IOException {
+        testSeekAhead(true);
+        testSeekAhead(false);
+    }
+
+    /**
+     * Implementation of {@link #testSeekAhead()} method, testing two different code paths depending
+     * on the {@code seekable} argument value. Note: the two code paths are actually identical on JDK 6.
+     */
+    private void testSeekAhead(final boolean seekable) throws IOException {
         initialize("testArgumentChecks", 48, 10);
+        if (!seekable) {
+            nonSeekableChannel();
+        }
         for (int i=0; i<3; i++) {
             final long v = random.nextLong();
             referenceStream.writeLong(v);