Search in sources :

Example 11 with Memoizer

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));
}
Also used : Memoizer(loci.formats.Memoizer) Test(org.testng.annotations.Test)

Example 12 with Memoizer

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);
}
Also used : Memoizer(loci.formats.Memoizer) File(java.io.File) Test(org.testng.annotations.Test)

Example 13 with Memoizer

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);
}
Also used : Memoizer(loci.formats.Memoizer) Test(org.testng.annotations.Test)

Example 14 with Memoizer

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;
}
Also used : IFormatReader(loci.formats.IFormatReader) Memoizer(loci.formats.Memoizer) ChannelMerger(loci.formats.ChannelMerger) ChannelFiller(loci.formats.ChannelFiller) IOException(java.io.IOException) ChannelSeparator(loci.formats.ChannelSeparator) FormatException(loci.formats.FormatException) FileStitcher(loci.formats.FileStitcher) MinMaxCalculator(loci.formats.MinMaxCalculator) DimensionSwapper(loci.formats.DimensionSwapper) ImageReader(loci.formats.ImageReader) DataProvider(org.testng.annotations.DataProvider)

Example 15 with Memoizer

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();
        }
    }
}
Also used : Memoizer(loci.formats.Memoizer) RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException) File(java.io.File) Location(loci.common.Location) Test(org.testng.annotations.Test)

Aggregations

Memoizer (loci.formats.Memoizer)15 Test (org.testng.annotations.Test)11 File (java.io.File)8 FileStitcher (loci.formats.FileStitcher)3 ImageReader (loci.formats.ImageReader)3 IOException (java.io.IOException)2 Location (loci.common.Location)2 ServiceException (loci.common.services.ServiceException)2 ChannelFiller (loci.formats.ChannelFiller)2 ChannelMerger (loci.formats.ChannelMerger)2 ChannelSeparator (loci.formats.ChannelSeparator)2 DimensionSwapper (loci.formats.DimensionSwapper)2 FormatException (loci.formats.FormatException)2 MinMaxCalculator (loci.formats.MinMaxCalculator)2 BufferedImageReader (loci.formats.gui.BufferedImageReader)2 RandomAccessInputStream (loci.common.RandomAccessInputStream)1 DependencyException (loci.common.services.DependencyException)1 ServiceFactory (loci.common.services.ServiceFactory)1 IFormatReader (loci.formats.IFormatReader)1 MissingLibraryException (loci.formats.MissingLibraryException)1