summaryrefslogtreecommitdiff
path: root/src/test/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializerTest.java
blob: d21e5b30ca1a88ce9b9856706a07c2e07f671a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.keuin.kbackupfabric.backup.incremental;

import com.keuin.kbackupfabric.backup.incremental.identifier.Sha256Identifier;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import static org.junit.Assert.assertEquals;

public class ObjectCollectionSerializerTest {

    @Test
    public void testSerializationConsistency1() throws IOException {
        testSerializationConsistency(1, 0);
    }

    @Test
    public void testSerializationConsistency2() throws IOException {
        testSerializationConsistency(2, 0);
    }

    @Test
    public void testSerializationConsistency4() throws IOException {
        testSerializationConsistency(4, 0);
    }

    @Test
    public void testSerializationConsistency8() throws IOException {
        testSerializationConsistency(8, 0);
    }

    @Test
    public void testSerializationConsistency1A() throws IOException {
        testSerializationConsistency(1, 1000);
    }

    @Test
    public void testSerializationConsistency2A() throws IOException {
        testSerializationConsistency(2, 1000);
    }

    @Test
    public void testSerializationConsistency4A() throws IOException {
        testSerializationConsistency(4, 1000);
    }

    @Test
    public void testSerializationConsistency8A() throws IOException {
        testSerializationConsistency(8, 1000);
    }

    public void testSerializationConsistency(int threads, int multiThreadThreshold) throws IOException {
        ObjectCollectionFactory<Sha256Identifier> factory =
                new ObjectCollectionFactory<>(Sha256Identifier.getFactory(), threads, multiThreadThreshold);
        ObjectCollection collection =
                factory.fromDirectory(new File("./testfile/ObjectCollectionFactoryTest"));
        File file = new File("./testfile/serialized");
        if (file.exists()) {
            Files.delete(file.toPath());
        }
        ObjectCollectionSerializer.toFile(collection, file);
        ObjectCollection collection2 = ObjectCollectionSerializer.fromFile(file);
        Files.delete(file.toPath());
        assertEquals(collection, collection2);
    }

}