diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-09-26 12:30:44 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2018-09-26 12:30:44 +0200 |
commit | 9af0fd0f7f0941a6524d6b03a0891c13d6ebfe06 (patch) | |
tree | 3e55f917c1ad800e0efdfa82375abe1c167578ae /vespajlib | |
parent | 115a99c2af52187838223286a44a14b21d3439ba (diff) |
Do not expose error.
Drop from cache after rotation.
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/io/NativeIO.java | 16 | ||||
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java | 21 |
2 files changed, 21 insertions, 16 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java index 5adb509ac3b..18779022d99 100644 --- a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java +++ b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java @@ -34,16 +34,20 @@ public class NativeIO { public NativeIO() { if (!initialized) { - logger.warning("native IO not possible due to " + initError); - if (initError != null) { - throw new RuntimeException(initError); - } else { - throw new RuntimeException("Platform is unsúpported. Only supported on linux."); - } + logger.warning("native IO not possible due to " + getError().getMessage()); } fieldFD = getField(FileDescriptor.class, "fd"); } + public boolean valid() { return initialized; } + public Throwable getError() { + if (initError != null) { + return initError; + } else { + return new RuntimeException("Platform is unsúpported. Only supported on linux."); + } + } + public void dropFileFromCache(FileDescriptor fd) { if (initialized) { posix_fadvise(getfh(fd), 0, 0, POSIX_FADV_DONTNEED); diff --git a/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java b/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java index 91144d5999f..8616427b78b 100644 --- a/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java @@ -9,6 +9,8 @@ import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + public class NativeIOTestCase { @@ -20,16 +22,15 @@ public class NativeIOTestCase { output.write('t'); output.flush(); output.close(); - try { - NativeIO nativeIO = new NativeIO(); - nativeIO.dropFileFromCache(output.getFD()); - nativeIO.dropFileFromCache(testFile); - } catch (Throwable e) { - if (Platform.isLinux()) { - assertTrue(false); - } else { - assertEquals("Platform is unsúpported. Only supported on linux.", e.getMessage()); - } + NativeIO nativeIO = new NativeIO(); + if (Platform.isLinux()) { + assertTrue(nativeIO.valid()); + } else { + assertFalse(nativeIO.valid()); + assertEquals("Platform is unsúpported. Only supported on linux.", nativeIO.getError().getMessage()); } + nativeIO.dropFileFromCache(output.getFD()); + nativeIO.dropFileFromCache(testFile); + testFile.delete(); } } |