TarWriter implements Closeable { TarWriter createNextGeneration() throws IOException { checkState(writeIndex >= 0); synchronized (this) { if (!archive.isCreated()) { return this; } } close(); int newIndex = writeIndex + 1; return new TarWriter(archiveManager, newIndex, segmentCount); } TarWriter(SegmentArchiveManager archiveManager, String archiveName);   TarWriter(SegmentArchiveManager archiveManager, int writeIndex, CounterStats segmentCountStats); @Override void close(); @Override String toString();  }
@Test public void createNextGenerationTest() throws IOException { int counter = 2222; TarWriter t0 = new TarWriter(archiveManager, counter, NoopStats.INSTANCE); TarWriter t1 = t0.createNextGeneration(); assertEquals(t0, t1); assertTrue(t1.getFileName().contains("" + counter)); UUID id = UUID.randomUUID(); long msb = id.getMostSignificantBits(); long lsb = id.getLeastSignificantBits() & (-1 >>> 4); byte[] data = "Hello, World!".getBytes(UTF_8); t1.writeEntry(msb, lsb, data, 0, data.length, newGCGeneration(0, 0, false)); TarWriter t2 = t1.createNextGeneration(); assertNotEquals(t1, t2); assertTrue(t1.isClosed()); assertTrue(t2.getFileName().contains("" + (counter + 1))); }