diff --git a/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data.h5ar b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data.h5ar new file mode 100644 index 0000000000000000000000000000000000000000..1622fd8035539495835ea8dd00033e1d589f3acd Binary files /dev/null and b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data.h5ar differ diff --git a/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/hello.txt b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/hello.txt new file mode 100644 index 0000000000000000000000000000000000000000..95d09f2b10159347eece71399a7e2e907ea3df4f --- /dev/null +++ b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/hello.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/sub/hello.txt b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/sub/hello.txt new file mode 100644 index 0000000000000000000000000000000000000000..329c63806dd4cbc2a39d838d829d123bdc11d84c --- /dev/null +++ b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/sub/hello.txt @@ -0,0 +1 @@ +hello test \ No newline at end of file diff --git a/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/sub/some.txt b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/sub/some.txt new file mode 100644 index 0000000000000000000000000000000000000000..629ad124027d217ff7e76a20d61e6f66f0afefe2 --- /dev/null +++ b/datastore_server/resource/test-data/TarBasedPathInfoProviderTest/ds1/data/sub/some.txt @@ -0,0 +1 @@ +This is some text for testing purpose. \ No newline at end of file diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarBasedPathInfoProviderTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarBasedPathInfoProviderTest.java index ddbb5cfa93b3e07df34e9f313b36544a0cee182b..f6859576727e49d01c1004ac30a9d414a7b5ab1b 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarBasedPathInfoProviderTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarBasedPathInfoProviderTest.java @@ -26,11 +26,11 @@ import org.testng.annotations.Test; import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase; import ch.systemsx.cisd.common.collection.SimpleComparator; -import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.filesystem.tar.Tar; import ch.systemsx.cisd.common.logging.ISimpleLogger; import ch.systemsx.cisd.common.logging.MockLogger; import ch.systemsx.cisd.common.test.AssertionUtil; +import ch.systemsx.cisd.openbis.common.io.hierarchical_content.H5FolderFlags; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetPathInfo; /** @@ -38,6 +38,9 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetPathInfo; */ public class TarBasedPathInfoProviderTest extends AbstractFileSystemTestCase { + private static final File TEST_DATA_FOLDER = new File("../datastore_server/resource/test-data/" + + TarBasedPathInfoProviderTest.class.getSimpleName()); + private static final SimpleComparator<DataSetPathInfo, String> COMPARATOR = new SimpleComparator<DataSetPathInfo, String>() { @Override @@ -51,23 +54,19 @@ public class TarBasedPathInfoProviderTest extends AbstractFileSystemTestCase private TarBasedPathInfoProvider pathInfoProvider; + private File tarFile; + @BeforeMethod public void prepareExample() throws Exception { logger = new MockLogger(); - File dataSet = new File(workingDirectory, "ds1"); - File data = new File(dataSet, "data"); - File subFolder = new File(data, "sub"); - subFolder.mkdirs(); - FileUtilities.writeToFile(new File(subFolder, "hello.txt"), "hello test"); - FileUtilities.writeToFile(new File(subFolder, "some.txt"), "This is some text for testing purpose."); - FileUtilities.writeToFile(new File(data, "hello.txt"), "hello world"); - File tarFile = new File(workingDirectory, "data.tar"); + tarFile = new File(workingDirectory, "data.tar"); Tar tar = null; try { tar = new Tar(tarFile); - tar.add(data, dataSet.getPath().length()); + File file = new File(TEST_DATA_FOLDER, "ds1"); + tar.add(file, file.getPath().length()); } finally { if (tar != null) @@ -104,9 +103,9 @@ public class TarBasedPathInfoProviderTest extends AbstractFileSystemTestCase assertPathInfo("data/sub/hello.txt[hello.txt, 10, 3d4448e7]", children.get(0)); assertPathInfo("data/sub/some.txt[some.txt, 38, 2f7b8cfb]", children.get(1)); - AssertionUtil.assertContains("INFO: Reading statistics for input stream: 59 bytes in 7 chunks took < 1sec.", + AssertionUtil.assertContains("INFO: Reading statistics for input stream: 15.86 KB in 1626 chunks took < 1sec.", logger.toString()); - AssertionUtil.assertContains("INFO: Writing statistics for output stream: 59 bytes in 7 chunks took < 1sec.", + AssertionUtil.assertContains("INFO: Writing statistics for output stream: 15.86 KB in 1626 chunks took < 1sec.", logger.toString()); assertEquals(2, children.size()); } @@ -131,6 +130,30 @@ public class TarBasedPathInfoProviderTest extends AbstractFileSystemTestCase assertPathInfo("data/sub/hello.txt[hello.txt, 10, 3d4448e7]", pathInfos.get(0)); assertEquals(1, pathInfos.size()); } + + @Test + public void testHdf5FileAsFile() + { + DataSetPathInfo pathInfo = pathInfoProvider.tryGetPathInfoByRelativePath("data.h5ar"); + + assertEquals(false, pathInfo.isDirectory()); + assertPathInfo("data.h5ar[data.h5ar, 16184, 83bcffb0]", pathInfo); + } + + @Test + public void testHdf5FileAsFolder() + { + List<H5FolderFlags> flags = Arrays.asList(new H5FolderFlags("", false, true)); + TarBasedPathInfoProvider provider = new TarBasedPathInfoProvider(tarFile, flags, 10, logger); + + DataSetPathInfo parent = provider.tryGetPathInfoByRelativePath("data.h5ar/data"); + List<DataSetPathInfo> children = provider.listChildrenPathInfos(parent); + + Collections.sort(children, COMPARATOR); + assertPathInfo("data.h5ar/data/hello.txt[hello.txt, 11, d4a1185]", children.get(0)); + assertPathInfo("data.h5ar/data/sub[sub, 0, 0]", children.get(1)); + assertEquals(2, children.size()); + } private void assertPathInfo(String expectedPathInfo, DataSetPathInfo pathInfo) {