jelmini commented on code in PR #800:
URL: https://github.com/apache/jackrabbit-oak/pull/800#discussion_r1054428182
##########
oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureArchiveManagerTest.java:
##########
@@ -400,6 +400,40 @@ public void testCachingPersistenceTarRecovery() throws
URISyntaxException, Inval
assertFalse(container.getDirectoryReference("oak/data00000a.tar.ro.bak").listBlobs().iterator().hasNext());
}
+ @Test
+ public void testCollectBlobReferencesForReadOnlyFileStore() throws
URISyntaxException, InvalidFileStoreVersionException, IOException,
CommitFailedException, StorageException {
+ AzurePersistence rwPersistence = new
AzurePersistence(container.getDirectoryReference("oak"));
+ FileStore rwFileStore = FileStoreBuilder.fileStoreBuilder(new
File("target")).withCustomPersistence(rwPersistence).build();
+ SegmentNodeStore segmentNodeStore =
SegmentNodeStoreBuilders.builder(rwFileStore).build();
+ NodeBuilder builder = segmentNodeStore.getRoot().builder();
+ builder.setProperty("foo", "bar");
+ segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+ rwFileStore.flush();
+
+
assertTrue(container.getDirectoryReference("oak/data00000a.tar").listBlobs().iterator().hasNext());
+ // create read-only FS
+ AzurePersistence roPersistence = new
AzurePersistence(container.getDirectoryReference("oak"));
+ ReadOnlyFileStore roFileStore = FileStoreBuilder.fileStoreBuilder(new
File("target")).withCustomPersistence(roPersistence).buildReadOnly();
+
+ PropertyState fooProperty =
SegmentNodeStoreBuilders.builder(roFileStore).build()
+ .getRoot()
+ .getProperty("foo");
+
+ assertThat(fooProperty, not(nullValue()));
+ assertThat(fooProperty.getValue(Type.STRING), equalTo("bar"));
+
+ //exception should not be thrown
+ try {
+ roFileStore.collectBlobReferences(s -> {});
+ } catch (Exception e){
+ fail();
+ }
+
+ roFileStore.close();
Review Comment:
If any assertion fails in this test, then these 2 file stores will not be
closed properly. In my own PR (coming soon!), I had to add some tests to this
same class and they were sometimes failing because stores were not properly
closed by other tests. I had to fix all tests in order to make mines work
reliably...
I suggest to use `try-with-resource` which will close the store even when
there are exceptions:
```java
try (FileStore rwFileStore = FileStoreBuilder.fileStoreBuilder(new
File("target")).withCustomPersistence(rwPersistence).build()) {
...
try (ReadOnlyFileStore roFileStore =
FileStoreBuilder.fileStoreBuilder(new
File("target")).withCustomPersistence(roPersistence).buildReadOnly()) {
...
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]