### Question:
TarContainerPacker implements ContainerPacker<KeyValueContainerData> { @Override public void pack(Container<KeyValueContainerData> container, OutputStream output) throws IOException { KeyValueContainerData containerData = container.getContainerData(); try (OutputStream compressed = compress(output); ArchiveOutputStream archiveOutput = tar(compressed)) { includePath(containerData.getDbFile().toPath(), DB_DIR_NAME, archiveOutput); includePath(Paths.get(containerData.getChunksPath()), CHUNKS_DIR_NAME, archiveOutput); includeFile(container.getContainerFile(), CONTAINER_FILE_NAME, archiveOutput); } catch (CompressorException e) { throw new IOException( "Can't compress the container: " + containerData.getContainerID(), e); } }  @Override byte[] unpackContainerData(Container<KeyValueContainerData> container,
      InputStream input); @Override void pack(Container<KeyValueContainerData> container,
      OutputStream output); @Override byte[] unpackContainerDescriptor(InputStream input);  }### Answer:
@Test public void pack() throws IOException, CompressorException { OzoneConfiguration conf = new OzoneConfiguration(); KeyValueContainerData sourceContainerData = createContainer(SOURCE_CONTAINER_ROOT); KeyValueContainer sourceContainer = new KeyValueContainer(sourceContainerData, conf); writeDbFile(sourceContainerData, TEST_DB_FILE_NAME); writeChunkFile(sourceContainerData, TEST_CHUNK_FILE_NAME); writeDescriptor(sourceContainer); Path targetFile = TEMP_DIR.resolve("container.tar.gz"); try (FileOutputStream output = new FileOutputStream(targetFile.toFile())) { packer.pack(sourceContainer, output); } try (FileInputStream input = new FileInputStream(targetFile.toFile())) { CompressorInputStream uncompressed = new CompressorStreamFactory() .createCompressorInputStream(GZIP, input); TarArchiveInputStream tarStream = new TarArchiveInputStream(uncompressed); TarArchiveEntry entry; Map<String, TarArchiveEntry> entries = new HashMap<>(); while ((entry = tarStream.getNextTarEntry()) != null) { entries.put(entry.getName(), entry); } Assert.assertTrue( entries.containsKey("container.yaml")); } try (FileInputStream input = new FileInputStream(targetFile.toFile())) { String containerYaml = new String(packer.unpackContainerDescriptor(input), Charset.forName(UTF_8.name())); Assert.assertEquals(TEST_DESCRIPTOR_FILE_CONTENT, containerYaml); } KeyValueContainerData destinationContainerData = createContainer(DEST_CONTAINER_ROOT); KeyValueContainer destinationContainer = new KeyValueContainer(destinationContainerData, conf); String descriptor; try (FileInputStream input = new FileInputStream(targetFile.toFile())) { descriptor = new String(packer.unpackContainerData(destinationContainer, input), Charset.forName(UTF_8.name())); } assertExampleMetadataDbIsGood( destinationContainerData.getDbFile().toPath(), TEST_DB_FILE_NAME); assertExampleChunkFileIsGood( Paths.get(destinationContainerData.getChunksPath()), TEST_CHUNK_FILE_NAME); Assert.assertFalse( "Descriptor file should not have been extracted by the " + "unpackContainerData Call", destinationContainer.getContainerFile().exists()); Assert.assertEquals(TEST_DESCRIPTOR_FILE_CONTENT, descriptor); }