|
1 | 1 | package org.janelia.saalfeldlab.n5.universe.storage.zarr; |
2 | 2 |
|
3 | 3 | import com.google.cloud.storage.Storage; |
| 4 | +import org.janelia.saalfeldlab.n5.DataType; |
| 5 | +import org.janelia.saalfeldlab.n5.DatasetAttributes; |
| 6 | +import org.janelia.saalfeldlab.n5.N5Exception; |
| 7 | +import org.janelia.saalfeldlab.n5.N5Reader; |
4 | 8 | import org.janelia.saalfeldlab.n5.N5Writer; |
| 9 | +import org.janelia.saalfeldlab.n5.RawCompression; |
5 | 10 | import org.janelia.saalfeldlab.n5.googlecloud.GoogleCloudStorageKeyValueAccess; |
6 | 11 | import org.janelia.saalfeldlab.n5.googlecloud.N5GoogleCloudStorageTests; |
7 | 12 | import org.janelia.saalfeldlab.n5.googlecloud.backend.BackendGoogleCloudStorageFactory; |
|
10 | 15 | import org.junit.AfterClass; |
11 | 16 | import org.junit.BeforeClass; |
12 | 17 |
|
| 18 | +import java.io.IOException; |
13 | 19 | import java.net.URI; |
14 | 20 | import java.net.URISyntaxException; |
15 | 21 |
|
16 | 22 | import static org.janelia.saalfeldlab.n5.s3.N5AmazonS3Tests.tempContainerPath; |
| 23 | +import static org.junit.Assert.assertArrayEquals; |
| 24 | +import static org.junit.Assert.assertEquals; |
| 25 | +import static org.junit.Assert.assertThrows; |
17 | 26 | import static org.junit.Assert.assertTrue; |
18 | 27 |
|
19 | 28 | public abstract class ZarrGoogleCloudFactoryTest extends ZarrStorageTests.ZarrFactoryTest { |
@@ -62,6 +71,41 @@ public ZarrGoogleCloudMockTest() { |
62 | 71 |
|
63 | 72 | ZarrGoogleCloudFactoryTest.storage = MockGoogleCloudStorageFactory.getOrCreateStorage(); |
64 | 73 | } |
| 74 | + |
| 75 | + @Override public void testPathsWithIllegalUriCharacters() { |
| 76 | + |
| 77 | + // NOTE: This is currently identical to the AbstractN5Test version, except we remove "%" from the array of illegalChars to test. |
| 78 | + // Specifically we ONLY remove it in this Mock version of the test. The actual backend has no problem, and the test passes |
| 79 | + // just fine, but the mock version seems to have some incorrect handling of % in keys. Likely because % is a valid UTF-8 character |
| 80 | + // but requires special encoding for URL over HTTP, and it seems the mock channels don't handle that case correctly |
| 81 | + try (N5Writer writer = createTempN5Writer()) { |
| 82 | + try (N5Reader reader = createN5Reader(writer.getURI().toString())) { |
| 83 | + |
| 84 | + final String[] illegalChars = {" ", "#"}; |
| 85 | + for (final String illegalChar : illegalChars) { |
| 86 | + final String groupWithIllegalChar = "test" + illegalChar + "group"; |
| 87 | + assertThrows("list over group should throw prior to create", N5Exception.N5IOException.class, () -> writer.list(groupWithIllegalChar)); |
| 88 | + writer.createGroup(groupWithIllegalChar); |
| 89 | + assertTrue("Newly created group should exist", writer.exists(groupWithIllegalChar)); |
| 90 | + assertArrayEquals("list over empty group should be empty list", new String[0], writer.list(groupWithIllegalChar)); |
| 91 | + writer.setAttribute(groupWithIllegalChar, "/a/b/key1", "value1"); |
| 92 | + final String attrFromWriter = writer.getAttribute(groupWithIllegalChar, "/a/b/key1", String.class); |
| 93 | + final String attrFromReader = reader.getAttribute(groupWithIllegalChar, "/a/b/key1", String.class); |
| 94 | + assertEquals("value1", attrFromWriter); |
| 95 | + assertEquals("value1", attrFromReader); |
| 96 | + |
| 97 | + |
| 98 | + final String datasetWithIllegalChar = "test" + illegalChar + "dataset"; |
| 99 | + final DatasetAttributes datasetAttributes = new DatasetAttributes(dimensions, blockSize, DataType.UINT64, new RawCompression()); |
| 100 | + writer.createDataset(datasetWithIllegalChar, datasetAttributes); |
| 101 | + final DatasetAttributes datasetFromWriter = writer.getDatasetAttributes(datasetWithIllegalChar); |
| 102 | + final DatasetAttributes datasetFromReader = reader.getDatasetAttributes(datasetWithIllegalChar); |
| 103 | + assertDatasetAttributesEquals(datasetAttributes, datasetFromWriter); |
| 104 | + assertDatasetAttributesEquals(datasetAttributes, datasetFromReader); |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
65 | 109 | } |
66 | 110 |
|
67 | 111 | public static class ZarrGoogleCloudBackendTest extends ZarrGoogleCloudFactoryTest { |
|
0 commit comments