Search in sources :

Example 6 with Chunker

use of org.syncany.chunk.Chunker 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 7 with Chunker

use of org.syncany.chunk.Chunker 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)

Example 8 with Chunker

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

the class TTTDChunkerTest method testStringSerialization.

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

Example 9 with Chunker

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

the class TTTDChunkerTest method testCreateChunksFrom5MBFileAndTestChunkSize.

@Test
public void testCreateChunksFrom5MBFileAndTestChunkSize() throws Exception {
    // Test Constants
    final int TOTAL_FILE_SIZE = 5 * 1024 * 1024;
    final int AVG_CHUNK_SIZE = 512 * 1024;
    // Setup				
    File inputRandom5MBFile = TestFileUtil.createRandomFileInDirectory(tempDir, TOTAL_FILE_SIZE);
    File outputCopyOfRandom5MBFile = TestFileUtil.getRandomFilenameInDirectory(tempDir);
    FileOutputStream outputCopyOfRandom5MBFileOutputStream = new FileOutputStream(outputCopyOfRandom5MBFile);
    Chunker chunker = new TttdChunker(AVG_CHUNK_SIZE);
    // Create chunks
    Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputRandom5MBFile);
    Chunk lastChunk = null;
    while (chunkEnumeration.hasMoreElements()) {
        lastChunk = chunkEnumeration.nextElement();
        // Checksum
        assertNotNull("Chunk checksum should not be null.", lastChunk.getChecksum());
        outputCopyOfRandom5MBFileOutputStream.write(lastChunk.getContent(), 0, lastChunk.getSize());
    }
    outputCopyOfRandom5MBFileOutputStream.close();
    // Number of chunks
    // TODO [low] How to test the number of chunks?
    // Checksums
    byte[] inputFileChecksum = FileUtil.createChecksum(inputRandom5MBFile, TttdChunker.DEFAULT_DIGEST_ALG);
    byte[] outputFileChecksum = FileUtil.createChecksum(outputCopyOfRandom5MBFile, TttdChunker.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 : FileOutputStream(java.io.FileOutputStream) TttdChunker(org.syncany.chunk.TttdChunker) Chunker(org.syncany.chunk.Chunker) Chunk(org.syncany.chunk.Chunk) File(java.io.File) TttdChunker(org.syncany.chunk.TttdChunker) Test(org.junit.Test)

Aggregations

Chunker (org.syncany.chunk.Chunker)9 Test (org.junit.Test)7 File (java.io.File)5 Chunk (org.syncany.chunk.Chunk)4 FixedChunker (org.syncany.chunk.FixedChunker)4 TttdChunker (org.syncany.chunk.TttdChunker)4 FileOutputStream (java.io.FileOutputStream)3 MultiChunker (org.syncany.chunk.MultiChunker)3 ZipMultiChunker (org.syncany.chunk.ZipMultiChunker)2 InputStream (java.io.InputStream)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 CipherTransformer (org.syncany.chunk.CipherTransformer)1 GzipTransformer (org.syncany.chunk.GzipTransformer)1 MultiChunk (org.syncany.chunk.MultiChunk)1 NoTransformer (org.syncany.chunk.NoTransformer)1 Transformer (org.syncany.chunk.Transformer)1 CipherSpec (org.syncany.crypto.CipherSpec)1 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)1