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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
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.util.*;
import static org.junit.Assert.*;
public class ObjectCollectionFactoryTest {
private void validate(ObjectCollection2 collection, List<String> subCollections, Map<String, String> subElements) {
assertEquals(subCollections.size(), collection.getSubCollectionMap().size());
assertEquals(subElements.size(), collection.getElementSet().size());
for (Map.Entry<String, ObjectCollection2> c : collection.getSubCollectionMap().entrySet()) {
assertEquals(c.getKey(), c.getValue().getName());
assertTrue(subCollections.contains(c.getKey()));
}
for (Map.Entry<String, ObjectElement> entry : collection.getElementMap().entrySet()) {
// assertTrue(subElements.contains(e.getIdentification()));
assertEquals(subElements.get(entry.getKey()).toUpperCase(), entry.getValue().getIdentifier().getIdentification().toUpperCase());
}
}
@Test
public void fromDirectory1() {
fromDirectory(1, 0);
}
@Test
public void fromDirectory2() {
fromDirectory(2, 0);
}
@Test
public void fromDirectory4() {
fromDirectory(4, 0);
}
@Test
public void fromDirectory8() {
fromDirectory(8, 0);
}
@Test
public void fromDirectory1A() {
fromDirectory(1, 1000);
}
@Test
public void fromDirectory2A() {
fromDirectory(2, 1000);
}
@Test
public void fromDirectory4A() {
fromDirectory(4, 1000);
}
@Test
public void fromDirectory8A() {
fromDirectory(8, 1000);
}
public void fromDirectory(int threads, int multiThreadThreshold) {
final String testRoot = "./testfile/ObjectCollectionFactoryTest";
File[] paths = new File[]{
new File(testRoot + "/1/12"),
new File(testRoot + "/2"),
new File(testRoot + "/3")
};
for (File f : paths) {
assertTrue("Failed to create directory: " + f.getAbsolutePath(),
f.isDirectory() || f.mkdirs());
}
try {
ObjectCollectionFactory<Sha256Identifier> factory =
new ObjectCollectionFactory<>(Sha256Identifier.getFactory(), threads, multiThreadThreshold);
ObjectCollection2 collection =
factory.fromDirectory(new File(testRoot));
assertEquals("ObjectCollectionFactoryTest", collection.getName());
assertEquals(3, collection.getSubCollectionMap().size());
assertEquals(2, collection.getElementSet().size());
final Map<String, String> elements = new HashMap<>();
// check root dir
elements.put("a", "S2-261CA0D59FEE8FD169802BB8030A07CF23E5C1593FA81A16C6D0A8CF27DAA2ED");
elements.put("b", "S2-B3FED75012C4969DC63A50EBC4E745FF77E4A06E0B04720EF71EF033032EBAF7");
validate(collection, Arrays.asList("1", "2", "3"), elements);
elements.clear();
// check `1`
elements.put("a", "S2-E8620F35A5DB33B1257CC51245DDACDA8AF3E0D431A8A38473575E468BCBD0BD");
elements.put("b", "S2-19EE41585A674274891DE5A4B365DBAB9C49C576AB6F86CD515B683724D2DBBD");
validate(collection.getSubCollectionMap().get("1"), Arrays.asList("11", "12"), elements);
elements.clear();
// check `2`
validate(collection.getSubCollectionMap().get("2"), Collections.emptyList(), Collections.emptyMap());
// check `3`
validate(collection.getSubCollectionMap().get("3"), Collections.emptyList(), Collections.emptyMap());
// check `11`
validate(collection.getSubCollectionMap().get("1").getSubCollectionMap().get("11"), Collections.singletonList("111"), Collections.emptyMap());
// check `111`
elements.put("a", "S2-1EDBE882A757E1FAFCA77A9D3BE3FF5D2BB3E2037B238C865F1F957C431F43B4");
elements.put("b", "S2-30BA7CD8B4AD93A8B3826CD8D1518790924EEBB930EC04DF7DFB03A50B17D7BC");
validate(
collection.getSubCollectionMap().get("1").getSubCollectionMap().get("11").getSubCollectionMap().get("111"),
Collections.emptyList(),
elements
);
elements.clear();
// check `12`
validate(collection.getSubCollectionMap().get("1").getSubCollectionMap().get("12"), Collections.emptyList(), Collections.emptyMap());
} catch (IOException e) {
e.printStackTrace();
fail();
}
}
}
|