Search in sources :

Example 1 with FixedChunker

use of org.syncany.chunk.FixedChunker in project syncany by syncany.

the class FixedOffsetChunkerTest method testExceptionInvalidDigestAlgorithm.

@Test
public void testExceptionInvalidDigestAlgorithm() {
    boolean exceptionThrown = false;
    try {
        new FixedChunker(1337, "does-not-exist").createChunks(new File("/some/file"));
    } catch (Exception e) {
        exceptionThrown = true;
    }
    assertTrue("Exception expected.", exceptionThrown);
}
Also used : FixedChunker(org.syncany.chunk.FixedChunker) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with FixedChunker

use of org.syncany.chunk.FixedChunker in project syncany by syncany.

the class FixedOffsetChunkerTest method testCreateChunksFrom5MBFileAndTestChunkSize.

@Test
public void testCreateChunksFrom5MBFileAndTestChunkSize() throws Exception {
    // Test Constants
    final int TOTAL_FILE_SIZE = 5 * 1024 * 1024;
    final int EXACT_CHUNK_SIZE = 512 * 1024;
    final int EXPECTED_NUMBER_OF_CHUNKS = TOTAL_FILE_SIZE / EXACT_CHUNK_SIZE;
    final int EXPECTED_CHUNK_SIZE = EXACT_CHUNK_SIZE;
    // Setup
    File inputRandom5MBFile = TestFileUtil.createRandomFileInDirectory(tempDir, TOTAL_FILE_SIZE);
    File outputCopyOfRandom5MBFile = TestFileUtil.getRandomFilenameInDirectory(tempDir);
    FileOutputStream outputCopyOfRandom5MBFileOutputStream = new FileOutputStream(outputCopyOfRandom5MBFile);
    Chunker chunker = new FixedChunker(EXACT_CHUNK_SIZE, FixedChunker.DEFAULT_DIGEST_ALG);
    // Create chunks
    int actualChunkCount = 0;
    Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputRandom5MBFile);
    Chunk lastChunk = null;
    while (chunkEnumeration.hasMoreElements()) {
        actualChunkCount++;
        lastChunk = chunkEnumeration.nextElement();
        // Chunk size & checksum
        assertEquals("Chunk does not have the expected size.", EXPECTED_CHUNK_SIZE, lastChunk.getSize());
        assertNotNull("Chunk checksum should not be null.", lastChunk.getChecksum());
        outputCopyOfRandom5MBFileOutputStream.write(lastChunk.getContent());
    }
    outputCopyOfRandom5MBFileOutputStream.close();
    // Number of chunks
    assertEquals("Unexpected number of chunks when chunking", EXPECTED_NUMBER_OF_CHUNKS, actualChunkCount);
    // Checksums
    byte[] inputFileChecksum = FileUtil.createChecksum(inputRandom5MBFile, FixedChunker.DEFAULT_DIGEST_ALG);
    byte[] outputFileChecksum = FileUtil.createChecksum(outputCopyOfRandom5MBFile, FixedChunker.DEFAULT_DIGEST_ALG);
    assertArrayEquals("Checksums of input and output file do not match.", inputFileChecksum, outputFileChecksum);
    assertArrayEquals("Last chunk's getFileChecksum() should be the file checksum.", inputFileChecksum, lastChunk.getFileChecksum());
}
Also used : FixedChunker(org.syncany.chunk.FixedChunker) FileOutputStream(java.io.FileOutputStream) FixedChunker(org.syncany.chunk.FixedChunker) Chunker(org.syncany.chunk.Chunker) Chunk(org.syncany.chunk.Chunk) File(java.io.File) Test(org.junit.Test)

Example 3 with FixedChunker

use of org.syncany.chunk.FixedChunker in project syncany by syncany.

the class FixedOffsetChunkerTest method testNextChunkEvenIfThereAreNone.

@Test
public void testNextChunkEvenIfThereAreNone() throws IOException {
    // Test Constants
    final int TOTAL_FILE_SIZE = 5 * 1024;
    final int EXACT_CHUNK_SIZE = 512 * 1024;
    // Setup
    File inputFile = TestFileUtil.createRandomFileInDirectory(tempDir, TOTAL_FILE_SIZE);
    Chunker chunker = new FixedChunker(EXACT_CHUNK_SIZE);
    // Create chunks
    Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputFile);
    while (chunkEnumeration.hasMoreElements()) {
        chunkEnumeration.nextElement();
    }
    // This should lead to an IOException
    assertNull("No chunk expected, but data received.", chunkEnumeration.nextElement());
    assertFalse("hasElements() should return 'false' if no chunk available.", chunkEnumeration.hasMoreElements());
}
Also used : FixedChunker(org.syncany.chunk.FixedChunker) FixedChunker(org.syncany.chunk.FixedChunker) Chunker(org.syncany.chunk.Chunker) Chunk(org.syncany.chunk.Chunk) File(java.io.File) Test(org.junit.Test)

Example 4 with FixedChunker

use of org.syncany.chunk.FixedChunker in project syncany by syncany.

the class FixedOffsetChunkerTest method testStringSerialization.

@Test
public void testStringSerialization() {
    final int CHUNK_SIZE = 512 * 1024;
    Chunker chunker = new FixedChunker(CHUNK_SIZE);
    assertEquals("Other toString() result expected.", "Fixed-" + CHUNK_SIZE + "-" + FixedChunker.DEFAULT_DIGEST_ALG, chunker.toString());
}
Also used : FixedChunker(org.syncany.chunk.FixedChunker) FixedChunker(org.syncany.chunk.FixedChunker) Chunker(org.syncany.chunk.Chunker) Test(org.junit.Test)

Example 5 with FixedChunker

use of org.syncany.chunk.FixedChunker in project syncany by syncany.

the class MultiChunkerTest method testChunkFileIntoMultiChunks.

@Test
public void testChunkFileIntoMultiChunks() throws Exception {
    int minMultiChunkSize = 512;
    int chunkSizeB = 16000;
    Chunker[] chunkers = new Chunker[] { new FixedChunker(chunkSizeB) };
    MultiChunker[] multiChunkers = new MultiChunker[] { //new CustomMultiChunker(minMultiChunkSize),
    new ZipMultiChunker(minMultiChunkSize) };
    for (Chunker chunker : chunkers) {
        for (MultiChunker multiChunker : multiChunkers) {
            logger.log(Level.INFO, "Running with " + chunker.getClass() + " and " + multiChunker.getClass());
            chunkFileIntoMultiChunks(chunker, multiChunker, minMultiChunkSize);
        }
    }
}
Also used : FixedChunker(org.syncany.chunk.FixedChunker) ZipMultiChunker(org.syncany.chunk.ZipMultiChunker) FixedChunker(org.syncany.chunk.FixedChunker) Chunker(org.syncany.chunk.Chunker) MultiChunker(org.syncany.chunk.MultiChunker) ZipMultiChunker(org.syncany.chunk.ZipMultiChunker) MultiChunker(org.syncany.chunk.MultiChunker) ZipMultiChunker(org.syncany.chunk.ZipMultiChunker) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 FixedChunker (org.syncany.chunk.FixedChunker)5 Chunker (org.syncany.chunk.Chunker)4 File (java.io.File)3 Chunk (org.syncany.chunk.Chunk)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 MultiChunker (org.syncany.chunk.MultiChunker)1 ZipMultiChunker (org.syncany.chunk.ZipMultiChunker)1