Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java
 Tue Feb 13 11:17:42 2018
@@ -19,7 +19,6 @@
 
 package org.apache.jackrabbit.oak.segment.file.tar;
 
-import static com.google.common.base.Charsets.UTF_8;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkPositionIndexes;
 import static com.google.common.base.Preconditions.checkState;
@@ -33,20 +32,15 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter.newBinaryReferencesIndexWriter;
 
 import java.io.Closeable;
-import java.io.File;
-import java.io.FileDescriptor;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
-import java.util.concurrent.TimeUnit;
 import java.util.zip.CRC32;
 
-import com.google.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
 import 
org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter;
 import org.apache.jackrabbit.oak.segment.file.tar.index.IndexWriter;
 import org.slf4j.Logger;
@@ -61,40 +55,9 @@ class TarWriter implements Closeable {
     /** Logger instance */
     private static final Logger log = LoggerFactory.getLogger(TarWriter.class);
 
-    private static final byte[] ZERO_BYTES = new byte[BLOCK_SIZE];
-
-    static int getPaddingSize(int size) {
-        int remainder = size % BLOCK_SIZE;
-        if (remainder > 0) {
-            return BLOCK_SIZE - remainder;
-        } else {
-            return 0;
-        }
-    }
-
     private final int writeIndex;
 
     /**
-     * The file being written. This instance is also used as an additional
-     * synchronization point by {@link #flush()} and {@link #close()} to
-     * allow {@link #flush()} to work concurrently with normal reads and
-     * writes, but not with a concurrent {@link #close()}.
-     */
-    private final File file;
-
-    private final FileStoreMonitor monitor;
-
-    /**
-     * File handle. Initialized lazily in {@link #writeEntry(UUID, byte[],
-     * byte[], int, int, GCGeneration)} to avoid creating an extra empty file
-     * when just reading from the repository. Should only be accessed from
-     * synchronized code.
-     */
-    private RandomAccessFile access = null;
-
-    private FileChannel channel = null;
-
-    /**
      * Flag to indicate a closed writer. Accessing a closed writer is illegal.
      * Should only be accessed from synchronized code.
      */
@@ -121,24 +84,30 @@ class TarWriter implements Closeable {
      */
     private final Map<UUID, Set<UUID>> graph = newHashMap();
 
-    private final IOMonitor ioMonitor;
+    private final SegmentArchiveManager archiveManager;
+
+    private final SegmentArchiveManager.SegmentArchiveWriter archive;
+
+    /** This object is used as an additional
+     *  synchronization point by {@link #flush()} and {@link #close()} to
+     *  allow {@link #flush()} to work concurrently with normal reads and
+     *  writes, but not with a concurrent {@link #close()}. */
+    private final Object closeMonitor = new Object();
 
     /**
      * Used for maintenance operations (GC or recovery) via the TarReader and
      * tests
      */
-    TarWriter(File file, IOMonitor ioMonitor) {
-        this.file = file;
-        this.monitor = new FileStoreMonitorAdapter();
+    TarWriter(SegmentArchiveManager archiveManager, String archiveName) throws 
IOException {
+        this.archiveManager = archiveManager;
+        this.archive = archiveManager.create(archiveName);
         this.writeIndex = -1;
-        this.ioMonitor = ioMonitor;
     }
 
-    TarWriter(File directory, FileStoreMonitor monitor, int writeIndex, 
IOMonitor ioMonitor) {
-        this.file = new File(directory, format(FILE_NAME_FORMAT, writeIndex, 
"a"));
-        this.monitor = monitor;
+    TarWriter(SegmentArchiveManager archiveManager, int writeIndex) throws 
IOException {
+        this.archiveManager = archiveManager;
+        this.archive = archiveManager.create(format(FILE_NAME_FORMAT, 
writeIndex, "a"));
         this.writeIndex = writeIndex;
-        this.ioMonitor = ioMonitor;
     }
 
     synchronized boolean containsEntry(long msb, long lsb) {
@@ -155,18 +124,13 @@ class TarWriter implements Closeable {
      * @return the byte buffer, or null if not in this file
      */
     ByteBuffer readEntry(long msb, long lsb) throws IOException {
-        checkState(!closed);
-        
         TarEntry entry;
         synchronized (this) {
+            checkState(!closed);
             entry = index.get(new UUID(msb, lsb));
         }
         if (entry != null) {
-            checkState(channel != null); // implied by entry != null
-            ByteBuffer data = ByteBuffer.allocate(entry.size());
-            channel.read(data, entry.offset());
-            data.rewind();
-            return data;
+            return archive.readSegment(entry);
         } else {
             return null;
         }
@@ -176,50 +140,17 @@ class TarWriter implements Closeable {
         checkNotNull(data);
         checkPositionIndexes(offset, offset + size, data.length);
 
-        UUID uuid = new UUID(msb, lsb);
-        CRC32 checksum = new CRC32();
-        checksum.update(data, offset, size);
-        String entryName = String.format("%s.%08x", uuid, checksum.getValue());
-        byte[] header = newEntryHeader(entryName, size);
-
-        log.debug("Writing segment {} to {}", uuid, file);
-        return writeEntry(uuid, header, data, offset, size, generation);
-    }
-
-    private synchronized long writeEntry(UUID uuid, byte[] header, byte[] 
data, int offset, int size, GCGeneration generation) throws IOException {
-        checkState(!closed);
-
-        if (access == null) {
-            access = new RandomAccessFile(file, "rw");
-            channel = access.getChannel();
-        }
-
-        long msb = uuid.getMostSignificantBits();
-        long lsb = uuid.getLeastSignificantBits();
-
-        int padding = getPaddingSize(size);
-
-        long initialLength = access.getFilePointer();
+        synchronized (this) {
+            checkState(!closed);
 
-        access.write(header);
+            TarEntry entry = archive.writeSegment(msb, lsb, data, offset, 
size, generation);
+            long currentLength = archive.getLength();
 
-        ioMonitor.beforeSegmentWrite(file, msb, lsb, size);
-        Stopwatch stopwatch = Stopwatch.createStarted();
-        access.write(data, offset, size);
-        ioMonitor.afterSegmentWrite(file, msb, lsb, size, 
stopwatch.elapsed(TimeUnit.NANOSECONDS));
+            checkState(currentLength <= Integer.MAX_VALUE);
+            index.put(new UUID(msb, lsb), entry);
 
-        if (padding > 0) {
-            access.write(ZERO_BYTES, 0, padding);
+            return currentLength;
         }
-
-        long currentLength = access.getFilePointer();
-        monitor.written(currentLength - initialLength);
-
-        checkState(currentLength <= Integer.MAX_VALUE);
-        TarEntry entry = new TarEntry(msb, lsb, (int) (currentLength - size - 
padding), size, generation);
-        index.put(uuid, entry);
-
-        return currentLength;
     }
 
     void addBinaryReference(GCGeneration generation, UUID segmentId, String 
reference) {
@@ -246,17 +177,15 @@ class TarWriter implements Closeable {
      * @throws IOException if the tar file could not be flushed
      */
     void flush() throws IOException {
-        synchronized (file) {
-            FileDescriptor descriptor = null;
+        synchronized (closeMonitor) {
+            boolean doFlush;
 
             synchronized (this) {
-                if (access != null && !closed) {
-                    descriptor = access.getFD();
-                }
+                doFlush = archive.isCreated() && !closed;
             }
 
-            if (descriptor != null) {
-                descriptor.sync();
+            if (doFlush) {
+                archive.flush();
             }
         }
     }
@@ -277,28 +206,21 @@ class TarWriter implements Closeable {
         }
 
         // If nothing was written to this file, then we're already done.
-        if (access == null) {
+        if (!archive.isCreated()) {
             return;
         }
 
         // Complete the tar file by adding the graph, the index and the
-        // trailing two zero blocks. This code is synchronized on the file
-        // instance to  ensure that no concurrent thread is still flushing
+        // trailing two zero blocks. This code is synchronized on the 
closeMonitor
+        // to ensure that no concurrent thread is still flushing
         // the file when we close the file handle.
-        long initialPosition, currentPosition;
-        synchronized (file) {
-            initialPosition = access.getFilePointer();
+        synchronized (closeMonitor) {
             writeBinaryReferences();
             writeGraph();
             writeIndex();
-            access.write(ZERO_BYTES);
-            access.write(ZERO_BYTES);
 
-            currentPosition = access.getFilePointer();
-            access.close();
+            archive.close();
         }
-
-        monitor.written(currentPosition - initialPosition);
     }
 
     /**
@@ -311,24 +233,17 @@ class TarWriter implements Closeable {
         checkState(writeIndex >= 0);
         // If nothing was written to this file, then we're already done.
         synchronized (this) {
-            if (access == null) {
+            if (!archive.isCreated()) {
                 return this;
             }
         }
         close();
         int newIndex = writeIndex + 1;
-        return new TarWriter(file.getParentFile(), monitor, newIndex, 
ioMonitor);
+        return new TarWriter(archiveManager, newIndex);
     }
 
     private void writeBinaryReferences() throws IOException {
-        byte[] data = binaryReferences.write();
-        int paddingSize = getPaddingSize(data.length);
-        byte[] header = newEntryHeader(file.getName() + ".brf", data.length + 
paddingSize);
-        access.write(header);
-        if (paddingSize > 0) {
-            access.write(ZERO_BYTES, 0, paddingSize);
-        }
-        access.write(data);
+        archive.writeBinaryReferences(binaryReferences.write());
     }
 
     private void writeGraph() throws IOException {
@@ -391,15 +306,7 @@ class TarWriter implements Closeable {
         buffer.putInt(graphSize);
         buffer.putInt(GRAPH_MAGIC);
 
-        int padding = getPaddingSize(graphSize);
-
-        access.write(newEntryHeader(file.getName() + ".gph", graphSize + 
padding));
-
-        if (padding > 0) {
-            access.write(ZERO_BYTES, 0, padding);
-        }
-
-        access.write(buffer.array());
+        archive.writeGraph(buffer.array());
     }
 
     private void writeIndex() throws IOException {
@@ -418,70 +325,15 @@ class TarWriter implements Closeable {
         }
 
         byte[] index = writer.write();
-        access.write(newEntryHeader(file.getName() + ".idx", index.length));
-        access.write(index);
-    }
-
-    private static byte[] newEntryHeader(String name, int size) {
-        byte[] header = new byte[BLOCK_SIZE];
-
-        // File name
-        byte[] nameBytes = name.getBytes(UTF_8);
-        System.arraycopy(
-                nameBytes, 0, header, 0, Math.min(nameBytes.length, 100));
-
-        // File mode
-        System.arraycopy(
-                String.format("%07o", 0400).getBytes(UTF_8), 0,
-                header, 100, 7);
-
-        // User's numeric user ID
-        System.arraycopy(
-                String.format("%07o", 0).getBytes(UTF_8), 0,
-                header, 108, 7);
-
-        // Group's numeric user ID
-        System.arraycopy(
-                String.format("%07o", 0).getBytes(UTF_8), 0,
-                header, 116, 7);
-
-        // File size in bytes (octal basis)
-        System.arraycopy(
-                String.format("%011o", size).getBytes(UTF_8), 0,
-                header, 124, 11);
-
-        // Last modification time in numeric Unix time format (octal)
-        long time = System.currentTimeMillis() / 1000;
-        System.arraycopy(
-                String.format("%011o", time).getBytes(UTF_8), 0,
-                header, 136, 11);
-
-        // Checksum for header record
-        System.arraycopy(
-                new byte[] {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0,
-                header, 148, 8);
-
-        // Type flag
-        header[156] = '0';
-
-        // Compute checksum
-        int checksum = 0;
-        for (byte aHeader : header) {
-            checksum += aHeader & 0xff;
-        }
-        System.arraycopy(
-                String.format("%06o\0 ", checksum).getBytes(UTF_8), 0,
-                header, 148, 8);
-
-        return header;
+        archive.writeIndex(index);
     }
 
     synchronized long fileLength() {
-        return file.length();
+        return archive.getLength();
     }
 
-    synchronized File getFile() {
-        return file;
+    synchronized String getFileName() {
+        return archive.getName();
     }
 
     synchronized boolean isClosed() {
@@ -492,7 +344,7 @@ class TarWriter implements Closeable {
 
     @Override
     public String toString() {
-        return file.toString();
+        return getFileName();
     }
 
 }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java
 Tue Feb 13 11:17:42 2018
@@ -60,6 +60,7 @@ import org.apache.jackrabbit.oak.segment
 import org.apache.jackrabbit.oak.segment.file.JournalReader;
 import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore;
 import org.apache.jackrabbit.oak.segment.file.tar.IOMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -138,7 +139,7 @@ public class ConsistencyChecker implemen
             PrintWriter errWriter
     ) throws IOException, InvalidFileStoreVersionException {
         try (
-                JournalReader journal = new JournalReader(new File(directory, 
journalFileName));
+                JournalReader journal = new JournalReader(new 
LocalJournalFile(directory, journalFileName));
                 ConsistencyChecker checker = new ConsistencyChecker(directory, 
debugInterval, ioStatistics, outWriter, errWriter)
         ) {
             Set<String> checkpointsSet = Sets.newLinkedHashSet();

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java
 Tue Feb 13 11:17:42 2018
@@ -36,6 +36,7 @@ import com.google.common.collect.Iterato
 import org.apache.jackrabbit.oak.json.BlobSerializer;
 import org.apache.jackrabbit.oak.json.JsonSerializer;
 import org.apache.jackrabbit.oak.segment.SegmentNodeState;
+import 
org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
 import org.apache.jackrabbit.oak.segment.file.JournalEntry;
 import org.apache.jackrabbit.oak.segment.file.JournalReader;
@@ -75,7 +76,7 @@ public class RevisionHistory {
      * @return
      * @throws IOException
      */
-    public Iterator<HistoryElement> getHistory(@Nonnull File journal, @Nonnull 
final String path)
+    public Iterator<HistoryElement> getHistory(@Nonnull JournalFile journal, 
@Nonnull final String path)
             throws IOException {
         checkNotNull(path);
         

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java
 Tue Feb 13 11:17:42 2018
@@ -35,15 +35,17 @@ import java.io.RandomAccessFile;
 import java.util.Date;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
-
 import javax.annotation.Nullable;
 
 import com.google.common.base.Stopwatch;
 import org.apache.jackrabbit.oak.segment.SegmentCache;
+import 
org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
+import 
org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFileWriter;
 import org.apache.jackrabbit.oak.segment.file.FileStore;
 import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
 import org.apache.jackrabbit.oak.segment.file.JournalReader;
+import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
 
 /**
  * Perform an offline compaction of an existing segment store.
@@ -273,15 +275,16 @@ public class Compact {
             store.compactFull();
             System.out.printf("    -> cleaning up\n");
             store.cleanup();
+            JournalFile journal = new LocalJournalFile(path, "journal.log");
             String head;
             try (JournalReader journalReader = new JournalReader(journal)) {
                 head = String.format("%s root %s\n", 
journalReader.next().getRevision(), System.currentTimeMillis());
             }
-            try (RandomAccessFile journalFile = new RandomAccessFile(journal, 
"rw")) {
+
+            try (JournalFileWriter journalWriter = 
journal.openJournalWriter()) {
                 System.out.printf("    -> writing new %s: %s\n", 
journal.getName(), head);
-                journalFile.setLength(0);
-                journalFile.writeBytes(head);
-                journalFile.getChannel().force(false);
+                journalWriter.truncate();
+                journalWriter.writeLine(head);
             }
         } catch (Exception e) {
             watch.stop();

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java
 Tue Feb 13 11:17:42 2018
@@ -23,6 +23,8 @@ import static com.google.common.base.Pre
 import java.io.File;
 import java.util.Iterator;
 
+import 
org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
+import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
 import org.apache.jackrabbit.oak.segment.file.tooling.RevisionHistory;
 import 
org.apache.jackrabbit.oak.segment.file.tooling.RevisionHistory.HistoryElement;
 
@@ -123,7 +125,7 @@ public class History {
 
     private final File path;
 
-    private final File journal;
+    private final JournalFile journal;
 
     private final String node;
 
@@ -131,7 +133,7 @@ public class History {
 
     private History(Builder builder) {
         this.path = builder.path;
-        this.journal = builder.journal;
+        this.journal = new LocalJournalFile(builder.journal);
         this.node = builder.node;
         this.depth = builder.depth;
     }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java
 Tue Feb 13 11:17:42 2018
@@ -30,10 +30,12 @@ import javax.annotation.Nonnull;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Iterators;
+import 
org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
 import org.apache.jackrabbit.oak.segment.file.JournalEntry;
 import org.apache.jackrabbit.oak.segment.file.JournalReader;
 import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore;
+import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
 import org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 
@@ -65,7 +67,7 @@ final class Utils {
     }
 
     static List<String> readRevisions(File store) {
-        File journal = new File(store, "journal.log");
+        JournalFile journal = new LocalJournalFile(store, "journal.log");
 
         if (journal.exists()) {
             try (JournalReader journalReader = new JournalReader(journal)) {

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java
 Tue Feb 13 11:17:42 2018
@@ -19,24 +19,23 @@
 
 package org.apache.jackrabbit.oak.segment.file;
 
-import static com.google.common.base.Charsets.UTF_8;
 import static com.google.common.collect.Lists.newArrayList;
 import static 
org.apache.jackrabbit.oak.segment.file.tar.GCGeneration.newGCGeneration;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
 import org.apache.jackrabbit.oak.commons.IOUtils;
 import org.apache.jackrabbit.oak.segment.RecordId;
+import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
 import org.apache.jackrabbit.oak.segment.file.GCJournal.GCJournalEntry;
+import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -46,10 +45,13 @@ public class GcJournalTest {
     @Rule
     public final TemporaryFolder segmentFolder = new TemporaryFolder(new 
File("target"));
 
+    protected SegmentNodeStorePersistence getPersistence() throws Exception {
+        return new TarPersistence(segmentFolder.getRoot());
+    }
+
     @Test
     public void tarGcJournal() throws Exception {
-        File directory = segmentFolder.newFolder();
-        GCJournal gc = new GCJournal(directory);
+        GCJournal gc = new GCJournal(getPersistence().getGCJournalFile());
 
         gc.persist(0, 100, newGCGeneration(1, 0, false), 50, 
RecordId.NULL.toString10());
         GCJournalEntry e0 = gc.read();
@@ -83,32 +85,31 @@ public class GcJournalTest {
         Collection<GCJournalEntry> all = gc.readAll();
         assertEquals(all.size(), 3);
 
-        File file = new File(directory, GCJournal.GC_JOURNAL);
-        assertTrue(file.exists());
-        List<String> allLines = Files.readAllLines(file.toPath(), UTF_8);
+        SegmentNodeStorePersistence.GCJournalFile gcFile = 
getPersistence().getGCJournalFile();
+        List<String> allLines = gcFile.readLines();
         assertEquals(allLines.size(), 3);
     }
 
     @Test
     public void testGCGeneration() throws Exception {
-        GCJournal out = new GCJournal(segmentFolder.getRoot());
+        GCJournal out = new GCJournal(getPersistence().getGCJournalFile());
         out.persist(1, 100, newGCGeneration(1, 2, false), 50, 
RecordId.NULL.toString());
-        GCJournal in = new GCJournal(segmentFolder.getRoot());
+        GCJournal in = new GCJournal(getPersistence().getGCJournalFile());
         assertEquals(newGCGeneration(1, 2, false), 
in.read().getGcGeneration());
     }
 
     @Test
     public void testGCGenerationCompactedFlagCleared() throws Exception {
-        GCJournal out = new GCJournal(segmentFolder.getRoot());
+        GCJournal out = new GCJournal(getPersistence().getGCJournalFile());
         out.persist(1, 100, newGCGeneration(1, 2, true), 50, 
RecordId.NULL.toString());
-        GCJournal in = new GCJournal(segmentFolder.getRoot());
+        GCJournal in = new GCJournal(getPersistence().getGCJournalFile());
         assertEquals(newGCGeneration(1, 2, false), 
in.read().getGcGeneration());
     }
 
     @Test
-    public void testReadOak16GCLog() throws IOException {
+    public void testReadOak16GCLog() throws Exception {
         createOak16GCLog();
-        GCJournal gcJournal = new GCJournal(segmentFolder.getRoot());
+        GCJournal gcJournal = new 
GCJournal(getPersistence().getGCJournalFile());
         GCJournalEntry entry = gcJournal.read();
         assertEquals(45919825920L, entry.getRepoSize());
         assertEquals(41394306048L, entry.getReclaimedSize());
@@ -119,9 +120,9 @@ public class GcJournalTest {
     }
 
     @Test
-    public void testUpdateOak16GCLog() throws IOException {
+    public void testUpdateOak16GCLog() throws Exception {
         createOak16GCLog();
-        GCJournal gcJournal = new GCJournal(segmentFolder.getRoot());
+        GCJournal gcJournal = new 
GCJournal(getPersistence().getGCJournalFile());
         gcJournal.persist(75, 300, newGCGeneration(3, 0, false), 125, "bar");
 
         ArrayList<GCJournalEntry> entries = newArrayList(gcJournal.readAll());

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalEntryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalEntryTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalEntryTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalEntryTest.java
 Tue Feb 13 11:17:42 2018
@@ -32,6 +32,7 @@ import com.google.common.base.Splitter;
 import com.google.common.io.Files;
 import org.apache.jackrabbit.oak.segment.SegmentNodeStore;
 import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
+import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -79,7 +80,7 @@ public class JournalEntryTest {
         long entryTime = Long.valueOf(parts.get(2));
         assertTrue(entryTime >= startTime);
 
-        JournalReader jr = new JournalReader(journal);
+        JournalReader jr = new JournalReader(new LocalJournalFile(journal));
         JournalEntry journalEntry = jr.next();
         assertEquals(journalParts(lines.get(lines.size() - 1)).get(0), 
journalEntry.getRevision());
         assertEquals(journalParts(lines.get(lines.size() - 1)).get(2), 
String.valueOf(journalEntry.getTimestamp()));

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalReaderTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalReaderTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalReaderTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/JournalReaderTest.java
 Tue Feb 13 11:17:42 2018
@@ -28,6 +28,7 @@ import java.io.File;
 import java.io.IOException;
 
 import com.google.common.collect.Iterators;
+import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -141,10 +142,10 @@ public class JournalReaderTest {
         }
     }
 
-    private JournalReader createJournalReader(String s) throws IOException {
+    protected JournalReader createJournalReader(String s) throws IOException {
         File journalFile = folder.newFile("jrt");
         write(journalFile, s);
-        return new JournalReader(journalFile);
+        return new JournalReader(new LocalJournalFile(journalFile));
     }
 
 }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java
 Tue Feb 13 11:17:42 2018
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEqu
 import java.io.File;
 import java.nio.file.Files;
 
+import 
org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.ManifestFile;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -33,16 +34,19 @@ public class ManifestCheckerTest {
     @Rule
     public TemporaryFolder root = new TemporaryFolder(new File("target"));
 
-    private File manifest;
+    private File file;
+
+    private ManifestFile manifest;
 
     @Before
     public void setUp() throws Exception {
-        manifest = root.newFile();
+        file = root.newFile();
+        manifest = new LocalManifestFile(file);
     }
 
     @Test(expected = InvalidFileStoreVersionException.class)
     public void testManifestShouldExist() throws Exception {
-        Files.delete(manifest.toPath());
+        Files.delete(file.toPath());
         newManifestChecker(manifest, true, 1, 2).checkManifest();
     }
 
@@ -81,7 +85,7 @@ public class ManifestCheckerTest {
 
     @Test
     public void testUpdateNonExistingManifest() throws Exception {
-        Files.delete(manifest.toPath());
+        Files.delete(file.toPath());
         newManifestChecker(manifest, false, 2, 3).checkAndUpdateManifest();
         assertEquals(3, Manifest.load(manifest).getStoreVersion(0));
     }

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestTest.java
 Tue Feb 13 11:17:42 2018
@@ -32,12 +32,12 @@ public class ManifestTest {
 
     @Test
     public void defaultStoreVersionShouldBeReturned() throws Exception {
-        assertEquals(42, Manifest.load(folder.newFile()).getStoreVersion(42));
+        assertEquals(42, Manifest.load(new 
LocalManifestFile(folder.newFile())).getStoreVersion(42));
     }
 
     @Test
     public void storeVersionShouldBeReturned() throws Exception {
-        File file = folder.newFile();
+        LocalManifestFile file = new LocalManifestFile(folder.newFile());
 
         Manifest write = Manifest.empty();
         write.setStoreVersion(42);

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java
 Tue Feb 13 11:17:42 2018
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertTru
 
 import java.io.File;
 
+import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
+import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -37,7 +39,8 @@ public class SizeDeltaGCEstimationTest {
 
     @Before
     public void setUpJournal() throws Exception {
-        journal = new GCJournal(folder.getRoot());
+        SegmentNodeStorePersistence persistence = new 
TarPersistence(folder.getRoot());
+        journal = new GCJournal(persistence.getGCJournalFile());
     }
 
     @Test

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java
 Tue Feb 13 11:17:42 2018
@@ -45,7 +45,9 @@ import com.google.common.util.concurrent
 import org.apache.jackrabbit.oak.segment.RecordId;
 import org.apache.jackrabbit.oak.segment.SegmentNodeBuilder;
 import org.apache.jackrabbit.oak.segment.SegmentNodeState;
+import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
 import org.apache.jackrabbit.oak.segment.SegmentReader;
+import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -64,29 +66,36 @@ public class TarRevisionsTest {
         return folder.getRoot();
     }
 
+    protected SegmentNodeStorePersistence getPersistence() throws IOException {
+        return new TarPersistence(getFileStoreFolder());
+    }
+
     @Before
     public void setup() throws Exception {
-        store = 
FileStoreBuilder.fileStoreBuilder(getFileStoreFolder()).build();
+        store = 
FileStoreBuilder.fileStoreBuilder(getFileStoreFolder()).withCustomPersistence(getPersistence()).build();
         revisions = store.getRevisions();
         reader = store.getReader();
         store.flush();
     }
 
     @After
-    public void tearDown() throws IOException {
-        store.close();
+    public void tearDown() {
+        if (store != null) {
+            store.close();
+            store = null;
+        }
     }
 
     @Test(expected = IllegalStateException.class)
     public void unboundRevisions() throws IOException {
-        try (TarRevisions tarRevisions = new TarRevisions(folder.getRoot())) {
+        try (TarRevisions tarRevisions = new TarRevisions(getPersistence())) {
             tarRevisions.getHead();
         }
     }
 
     @Nonnull
     private JournalReader createJournalReader() throws IOException {
-        return new JournalReader(new File(getFileStoreFolder(), 
TarRevisions.JOURNAL_FILE_NAME));
+        return new JournalReader(getPersistence().getJournalFile());
     }
 
     @Test
@@ -150,7 +159,7 @@ public class TarRevisionsTest {
 
     @Test
     public void concurrentSetHeadFromFunction()
-    throws IOException, InterruptedException, ExecutionException, 
TimeoutException {
+    throws InterruptedException, ExecutionException, TimeoutException {
         ListeningExecutorService executor = 
listeningDecorator(newFixedThreadPool(2));
         try {
             ListenableFuture<Boolean> t1 = executor.submit(new 
Callable<Boolean>() {

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java
 Tue Feb 13 11:17:42 2018
@@ -36,6 +36,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -43,18 +44,22 @@ import org.junit.rules.TemporaryFolder;
 
 public class TarFileTest {
 
-    private static GCGeneration generation(int full) {
+    protected static GCGeneration generation(int full) {
         return newGCGeneration(full, 0, false);
     }
 
-    private File file;
-
     @Rule
     public TemporaryFolder folder = new TemporaryFolder(new File("target"));
 
+    protected SegmentArchiveManager archiveManager;
+
     @Before
     public void setUp() throws IOException {
-        file = folder.newFile();
+        archiveManager = new SegmentTarManager(folder.newFolder(), new 
FileStoreMonitorAdapter(), new IOMonitorAdapter(), false);
+    }
+
+    protected long getWriteAndReadExpectedSize() {
+        return 5120;
     }
 
     @Test
@@ -64,14 +69,13 @@ public class TarFileTest {
         long lsb = id.getLeastSignificantBits() & (-1 >>> 4); // OAK-1672
         byte[] data = "Hello, World!".getBytes(UTF_8);
 
-        try (TarWriter writer = new TarWriter(file, new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 
"data00000a.tar")) {
             writer.writeEntry(msb, lsb, data, 0, data.length, generation(0));
             assertEquals(ByteBuffer.wrap(data), writer.readEntry(msb, lsb));
         }
 
-        assertEquals(5120, file.length());
-
-        try (TarReader reader = TarReader.open(file, false, new 
IOMonitorAdapter())) {
+        try (TarReader reader = TarReader.open("data00000a.tar", 
archiveManager)) {
+            assertEquals(getWriteAndReadExpectedSize(), reader.size());
             assertEquals(ByteBuffer.wrap(data), reader.readEntry(msb, lsb));
         }
     }
@@ -84,11 +88,11 @@ public class TarFileTest {
         String data = "test";
         byte[] buffer = data.getBytes(UTF_8);
 
-        try (TarWriter writer = new TarWriter(file, new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 
"data00000a.tar")) {
             writer.writeEntry(msb, lsb, buffer, 0, buffer.length, 
newGCGeneration(1, 2, false));
         }
 
-        try (TarReader reader = TarReader.open(file, false, new 
IOMonitorAdapter())) {
+        try (TarReader reader = TarReader.open("data00000a.tar", 
archiveManager)) {
             TarEntry[] entries = reader.getEntries();
             assertEquals(newGCGeneration(1, 2, false), 
entries[0].generation());
         }
@@ -102,11 +106,11 @@ public class TarFileTest {
         String data = "test";
         byte[] buffer = data.getBytes(UTF_8);
 
-        try (TarWriter writer = new TarWriter(file, new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 
"data00000a.tar")) {
             writer.writeEntry(msb, lsb, buffer, 0, buffer.length, 
newGCGeneration(1, 2, true));
         }
 
-        try (TarReader reader = TarReader.open(file, false, new 
IOMonitorAdapter())) {
+        try (TarReader reader = TarReader.open("data00000a.tar", 
archiveManager)) {
             TarEntry[] entries = reader.getEntries();
             assertEquals(newGCGeneration(1, 2, true), entries[0].generation());
         }
@@ -114,7 +118,7 @@ public class TarFileTest {
 
     @Test
     public void testWriteAndReadBinaryReferences() throws Exception {
-        try (TarWriter writer = new TarWriter(file, new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 
"data00000a.tar")) {
             writer.writeEntry(0x00, 0x00, new byte[] {0x01, 0x02, 0x3}, 0, 3, 
generation(0));
 
             writer.addBinaryReference(generation(1), new UUID(1, 0), "r0");
@@ -154,7 +158,7 @@ public class TarFileTest {
         expected.put(generation(2), two);
         expected.put(generation(3), three);
 
-        try (TarReader reader = TarReader.open(file, false, new 
IOMonitorAdapter())) {
+        try (TarReader reader = TarReader.open("data00000a.tar", 
archiveManager)) {
             Map<GCGeneration, Map<UUID, Set<String>>> actual = new HashMap<>();
 
             reader.getBinaryReferences().forEach((generation, full, compacted, 
id, reference) -> {
@@ -170,7 +174,7 @@ public class TarFileTest {
 
     @Test
     public void binaryReferencesIndexShouldBeTrimmedDownOnSweep() throws 
Exception {
-        try (TarWriter writer = new TarWriter(file, new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 
"data00000a.tar")) {
             writer.writeEntry(1, 1, new byte[] {1}, 0, 1, generation(1));
             writer.writeEntry(1, 2, new byte[] {1}, 0, 1, generation(1));
             writer.writeEntry(2, 1, new byte[] {1}, 0, 1, generation(2));
@@ -185,7 +189,7 @@ public class TarFileTest {
 
         Set<UUID> sweep = newSet(new UUID(1, 1), new UUID(2, 2));
 
-        try (TarReader reader = TarReader.open(file, false, new 
IOMonitorAdapter())) {
+        try (TarReader reader = TarReader.open("data00000a.tar", 
archiveManager)) {
             try (TarReader swept = reader.sweep(sweep, new HashSet<>())) {
                 assertNotNull(swept);
 
@@ -214,12 +218,12 @@ public class TarFileTest {
 
     @Test
     public void binaryReferencesIndexShouldContainCompleteGCGeneration() 
throws Exception {
-        try (TarWriter writer = new TarWriter(file, new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 
"data00000a.tar")) {
             writer.writeEntry(0x00, 0x00, new byte[] {0x01, 0x02, 0x3}, 0, 3, 
generation(0));
             writer.addBinaryReference(newGCGeneration(1, 2, false), new 
UUID(1, 2), "r1");
             writer.addBinaryReference(newGCGeneration(3, 4, true), new UUID(3, 
4), "r2");
         }
-        try (TarReader reader = TarReader.open(file, false, new 
IOMonitorAdapter())) {
+        try (TarReader reader = TarReader.open("data00000a.tar", 
archiveManager)) {
             Set<GCGeneration> expected = new HashSet<>();
             expected.add(newGCGeneration(1, 2, false));
             expected.add(newGCGeneration(3, 4, true));
@@ -233,7 +237,7 @@ public class TarFileTest {
 
     @Test
     public void graphShouldBeTrimmedDownOnSweep() throws Exception {
-        try (TarWriter writer = new TarWriter(file, new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 
"data00000a.tar")) {
             writer.writeEntry(1, 1, new byte[] {1}, 0, 1, generation(1));
             writer.writeEntry(1, 2, new byte[] {1}, 0, 1, generation(1));
             writer.writeEntry(1, 3, new byte[] {1}, 0, 1, generation(1));
@@ -249,7 +253,7 @@ public class TarFileTest {
 
         Set<UUID> sweep = newSet(new UUID(1, 2), new UUID(2, 3));
 
-        try (TarReader reader = TarReader.open(file, false, new 
IOMonitorAdapter())) {
+        try (TarReader reader = TarReader.open("data00000a.tar", 
archiveManager)) {
             try (TarReader swept = reader.sweep(sweep, new HashSet<UUID>())) {
                 assertNotNull(swept);
 

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java
 Tue Feb 13 11:17:42 2018
@@ -50,7 +50,7 @@ import org.junit.rules.TemporaryFolder;
 
 public class TarFilesTest {
 
-    private static final int MAX_FILE_SIZE = 512 * 1024;
+    public static final int MAX_FILE_SIZE = 512 * 1024;
 
     private static final Random random = new Random();
 
@@ -63,7 +63,7 @@ public class TarFilesTest {
     @Rule
     public TemporaryFolder folder = new TemporaryFolder(new File("target"));
 
-    private TarFiles tarFiles;
+    protected TarFiles tarFiles;
 
     @Before
     public void setUp() throws Exception {
@@ -80,7 +80,10 @@ public class TarFilesTest {
 
     @After
     public void tearDown() throws Exception {
-        tarFiles.close();
+        if (tarFiles != null) {
+            tarFiles.close();
+            tarFiles = null;
+        }
     }
 
     private void writeSegment(UUID id) throws IOException {

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java
 Tue Feb 13 11:17:42 2018
@@ -29,6 +29,8 @@ import java.io.File;
 import java.io.IOException;
 import java.util.UUID;
 
+import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -38,15 +40,25 @@ public class TarWriterTest {
     @Rule
     public TemporaryFolder folder = new TemporaryFolder(new File("target"));
 
+    protected SegmentArchiveManager archiveManager;
+
+    protected TestFileStoreMonitor monitor;
+
+    @Before
+    public void setUp() throws IOException {
+        monitor = new TestFileStoreMonitor();
+        archiveManager = new SegmentTarManager(folder.newFolder(), monitor, 
new IOMonitorAdapter(), false);
+    }
+
     @Test
     public void createNextGenerationTest() throws IOException {
         int counter = 2222;
-        TarWriter t0 = new TarWriter(folder.newFolder(), new 
FileStoreMonitorAdapter(), counter, new IOMonitorAdapter());
+        TarWriter t0 = new TarWriter(archiveManager, counter);
 
         // not dirty, will not create a new writer
         TarWriter t1 = t0.createNextGeneration();
         assertEquals(t0, t1);
-        assertTrue(t1.getFile().getName().contains("" + counter));
+        assertTrue(t1.getFileName().contains("" + counter));
 
         // dirty, will create a new writer
         UUID id = UUID.randomUUID();
@@ -58,10 +70,10 @@ public class TarWriterTest {
         TarWriter t2 = t1.createNextGeneration();
         assertNotEquals(t1, t2);
         assertTrue(t1.isClosed());
-        assertTrue(t2.getFile().getName().contains("" + (counter + 1)));
+        assertTrue(t2.getFileName().contains("" + (counter + 1)));
     }
 
-    private static class TestFileStoreMonitor extends FileStoreMonitorAdapter {
+    public static class TestFileStoreMonitor extends FileStoreMonitorAdapter {
 
         long written;
 
@@ -74,8 +86,7 @@ public class TarWriterTest {
 
     @Test
     public void testFileStoreMonitor() throws Exception {
-        TestFileStoreMonitor monitor = new TestFileStoreMonitor();
-        try (TarWriter writer = new TarWriter(folder.getRoot(), monitor, 0, 
new IOMonitorAdapter())) {
+        try (TarWriter writer = new TarWriter(archiveManager, 0)) {
             long sizeBefore = writer.fileLength();
             long writtenBefore = monitor.written;
             writer.writeEntry(0, 0, new byte[42], 0, 42, newGCGeneration(0, 0, 
false));

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java?rev=1824115&r1=1824114&r2=1824115&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
 Tue Feb 13 11:17:42 2018
@@ -39,6 +39,7 @@ import javax.annotation.Nonnull;
 import org.apache.jackrabbit.oak.segment.SegmentVersion;
 import org.apache.jackrabbit.oak.segment.data.SegmentData;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.segment.file.LocalManifestFile;
 import org.apache.jackrabbit.oak.segment.file.tar.IOMonitorAdapter;
 import org.apache.jackrabbit.oak.segment.file.tar.TarFiles;
 import org.apache.jackrabbit.oak.segment.tool.Compact;
@@ -124,7 +125,7 @@ public class UpgradeIT {
     }
 
     private void checkStoreVersion(int version) throws IOException, 
InvalidFileStoreVersionException {
-        newManifestChecker(new File(fileStoreHome.getRoot(), "manifest"),
+        newManifestChecker(new LocalManifestFile(fileStoreHome.getRoot(), 
"manifest"),
                 true, version, version).checkManifest();
     }
 


Reply via email to