Hi,

I'm able to run the unit test in org.h2.test.unit.TestFileSystem.java 
without any problems (in H2 version 1.3.174).

However, I'm unable to understand why the 2nd AssertThrows in the code 
below (around the call to truncate) is working at all 

    private void testSimple(final String fsBase) throws Exception {
    ...
        channel = FileUtils.open(fsBase + "/test", "r");
        final byte[] test = new byte[10000];
        FileUtils.readFully(channel, ByteBuffer.wrap(test, 0, 10000));
        assertEquals(buffer, test);
        final FileChannel fc = channel;
        new AssertThrows(IOException.class) {
            @Override
            public void test() throws Exception {
                fc.write(ByteBuffer.wrap(test, 0, 10));
            }
        };
        new AssertThrows(IOException.class) {
            @Override
            public void test() throws Exception {
                fc.truncate(10);
            }
        };
        ...
        
>From the JDK documentation, 
>FileChannel.truncate<http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#truncate(long)>
> on 
a readonly channel (or, a channel with a readonly underlying file) should 
result in a NonWritableChannelException, and not an IOException. In the 
following program that I wrote...

// size of /tmp/foo = 4 bytes
RandomAccessFile raf = new RandomAccessFile("/tmp/foo", "r");
try {
java.nio.channels.FileChannel c = raf.getChannel();
c.truncate(1);
} catch(Exception e) {
e.printStackTrace(); 
}
... I do indeed get a NonWritableChannelException.

So, how come the 2nd AssertThrows around truncate in the H2 unit test is 
working when it shouldn't?

Stumped,
/HS

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to