Skip to content

Commit

Permalink
we will not add the Cleaner API calls for now but just
Browse files Browse the repository at this point in the history
reference to issue #17 in comments
  • Loading branch information
msrocka committed Dec 11, 2019
1 parent 33b1fdf commit 68a3cec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ DenseMatrix run() {
}
}
}
buf.force();

// there is no way to close the buffer here
// see: https://github.com/GreenDelta/olca-modules/issues/17
// System.gc();

return matrix;
} catch (IOException e) {
throw new RuntimeException("failed to read from " + file, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
import org.junit.Assert;
import org.junit.Test;
import org.openlca.core.matrix.format.DenseMatrix;
import sun.misc.Cleaner;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;

public class HeaderTest {
Expand All @@ -35,26 +31,10 @@ public void testFromReadFile() throws Exception {
Assert.assertEquals("<f8", h.dtype);
Assert.assertTrue(h.fortranOrder);
Assert.assertArrayEquals(new int[]{2, 3}, h.shape);
Assert.assertTrue(file.delete());
}

@Test
public void testDeleteTempFile() throws Exception {
File file = Files.createTempFile("_file_del_test", ".txt").toFile();
try (RandomAccessFile f = new RandomAccessFile(file, "rw");
FileChannel chan = f.getChannel()) {
MappedByteBuffer buf = chan.map(
FileChannel.MapMode.READ_WRITE, 0, 42);
for (int i = 0; i < 42; i++) {
buf.put((byte) 42);
}
buf.force();
Cleaner cleaner = ((sun.nio.ch.DirectBuffer) buf).cleaner();
if (cleaner != null) {
cleaner.clean();
}
if (!file.delete()) {
// deleting the file will probably fail on Windows
// see https://github.com/GreenDelta/olca-modules/issues/17
file.deleteOnExit();
}
Assert.assertTrue(file.delete());
}

}

0 comments on commit 68a3cec

Please sign in to comment.