mreutegg commented on code in PR #1800:
URL: https://github.com/apache/jackrabbit-oak/pull/1800#discussion_r1802478510


##########
oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java:
##########
@@ -445,4 +451,54 @@ public boolean shouldFollow(UUID from, UUID to) {
 
         assertThrows(IllegalRepositoryStateException.class, () -> 
tarFiles.createFileReaper());
     }
+
+    @Test
+    public void testWriterRolloverOnExcessiveEntryCount() throws IOException {
+        // TOTAL_ENTRIES > WRITER_ENTRY_LIMIT;
+        final int WRITER_ENTRY_LIMIT = 8;
+        final int TOTAL_ENTRIES = 42;
+
+        IOMonitorAdapter ioMonitor = new IOMonitorAdapter();
+        FileStoreMonitor fsMonitor = new FileStoreMonitorAdapter();
+        RemoteStoreMonitor remoteStoreMonitor = new 
RemoteStoreMonitorAdapter();
+        File rootDirectory = folder.getRoot();
+        File segmentStoreDir = folder.newFolder();
+
+        // create persistence
+        SegmentNodeStorePersistence persistence = new 
TarPersistence(rootDirectory) {
+            @Override
+            public SegmentArchiveManager createArchiveManager(
+                    boolean memoryMapping, boolean offHeapAccess, IOMonitor 
ioMonitor,
+                    FileStoreMonitor fileStoreMonitor, RemoteStoreMonitor 
remoteStoreMonitor
+            ) {
+                return new SegmentTarManager(
+                        segmentStoreDir, fsMonitor, ioMonitor, false, false
+                ) {
+                    @Override
+                    public @NotNull SegmentArchiveWriter create(String 
archiveName) {
+                        return new SegmentTarWriter(new File(segmentStoreDir, 
archiveName), fsMonitor, ioMonitor) {
+                            @Override
+                            public int getMaxEntryCount() {
+                                return WRITER_ENTRY_LIMIT;
+                            }
+                        };
+                    }
+                };
+            }
+        };
+        tarFiles = TarFiles.builder()
+                .withDirectory(rootDirectory)
+                .withTarRecovery((id, data, recovery) -> {})
+                .withIOMonitor(ioMonitor)
+                .withFileStoreMonitor(fsMonitor)
+                .withMaxFileSize(MAX_FILE_SIZE)
+                .withRemoteStoreMonitor(remoteStoreMonitor)
+                .withPersistence(persistence)
+                .build();
+
+        // write more entries than fit into a single tar file
+        for (int i = 0; i < TOTAL_ENTRIES; i++) {
+            writeSegment(randomUUID());
+        }

Review Comment:
   Would be good to assert that the number of created archives is as expected. 
I think `tarFiles.readerCount()` should be `5` at this point, right?



-- 
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]

Reply via email to