use of loci.formats.Memoizer in project bioformats by openmicroscopy.
the class MemoizerTest method testConstructorReader.
@Test
public void testConstructorReader() throws Exception {
Memoizer memoizer = new Memoizer(reader);
checkMemoFile(memoizer.getMemoFile(id));
}
use of loci.formats.Memoizer in project bioformats by openmicroscopy.
the class MemoizerTest method testRelocate.
@Test
public void testRelocate() throws Exception {
// Create an in-place memo file
Memoizer memoizer = new Memoizer(reader, 0);
memoizer.setId(id);
memoizer.close();
assertFalse(memoizer.isLoadedFromMemo());
assertTrue(memoizer.isSavedToMemo());
// Rename the directory (including the file and the memo file)
File newidDir = new File(idDir.getAbsolutePath() + ".new");
idDir.renameTo(newidDir);
File newtempFile = new File(newidDir, TEST_FILE);
String newid = newtempFile.getAbsolutePath();
// Try to reopen the file with the Memoizer
memoizer.setId(newid);
memoizer.close();
assertTrue(memoizer.isLoadedFromMemo());
assertFalse(memoizer.isSavedToMemo());
recursiveDeleteOnExit(newidDir);
}
use of loci.formats.Memoizer in project bioformats by openmicroscopy.
the class MemoizerTest method testConstructorTimeElapsed.
@Test
public void testConstructorTimeElapsed() throws Exception {
Memoizer memoizer = new Memoizer(0);
checkMemoFile(memoizer.getMemoFile(id));
checkMemo(memoizer, id);
}
use of loci.formats.Memoizer in project bioformats by openmicroscopy.
the class WrapperTest method createWrappers.
@DataProvider(name = "wrappers")
public Object[][] createWrappers() {
Location.mapId(TEST_FILE, TEST_FILE);
Object[][] wrappers = new Object[][] { { new ChannelFiller() }, { new ChannelMerger() }, { new ChannelSeparator() }, { new DimensionSwapper() }, { new FileStitcher() }, { new ImageReader() }, { new MinMaxCalculator() }, { new Memoizer() } };
for (int i = 0; i < wrappers.length; i++) {
IFormatReader reader = (IFormatReader) wrappers[i][0];
try {
reader.setId(TEST_FILE);
} catch (FormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return wrappers;
}
use of loci.formats.Memoizer in project bioformats by openmicroscopy.
the class FormatReaderTest method testMemoFileUsage.
@Test(groups = { "all", "automated" })
public void testMemoFileUsage() {
String testName = "testMemoFileUsage";
if (!initFile())
result(testName, false, "initFile");
File memoFile = null;
File memoDir = null;
try {
// this should prevent conflicts when running multiple tests
// on the same system and/or in multiple threads
String tmpdir = System.getProperty("java.io.tmpdir");
memoDir = new File(tmpdir, UUID.randomUUID().toString() + ".memo");
memoDir.mkdir();
Memoizer memo = new Memoizer(0, memoDir);
memo.setId(reader.getCurrentFile());
memo.close();
memoFile = memo.getMemoFile(reader.getCurrentFile());
if (!memo.isSavedToMemo()) {
result(testName, false, "Memo file not saved");
}
memo.setId(reader.getCurrentFile());
if (!memo.isLoadedFromMemo()) {
result(testName, false, "Memo file could not be loaded");
}
memo.openBytes(0, 0, 0, 1, 1);
memo.close();
result(testName, true);
} catch (Throwable t) {
if (TestTools.isOutOfMemory(t)) {
result(testName, true, "Image too large");
return;
}
LOGGER.warn("", t);
result(testName, false, t.getMessage());
} finally {
if (memoFile != null) {
// log the memo file's size
try {
RandomAccessInputStream s = new RandomAccessInputStream(memoFile.getAbsolutePath());
LOGGER.debug("memo file size for {} = {} bytes", new Location(reader.getCurrentFile()).getAbsolutePath(), s.length());
s.close();
} catch (IOException e) {
LOGGER.warn("memo file size not available");
}
memoFile.delete();
// within the memo directory
while (!memoFile.getParentFile().equals(memoDir)) {
memoFile = memoFile.getParentFile();
memoFile.delete();
}
}
if (memoDir != null) {
memoDir.delete();
}
}
}
Aggregations