List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
// *** Part - 1 ***
// 1. load the data from massive-upload.dmp
// which includes deletes/upadtes (5000 operations)
TrieImpl trieSingle = new TrieImpl(mockDb_2);
for (int i = 0; i < strData.size() ; ++i){
String[] keyVal= strData.get(i).split("=");
if (keyVal[0].equals("*"))
trieSingle.delete(keyVal[1].trim());
else
trieSingle.update(keyVal[0].trim(), keyVal[1].trim());
}
System.out.println("root_1: => " + Hex.toHexString(trieSingle.getRootHash()));
// *** Part - 2 ***
// pre. we use the same data from massive-upload.dmp
// which includes deletes/upadtes (100000 operations)
// 1. part of the data loaded
// 2. the trie cache sync to the db
// 3. the rest of the data loaded with part of the trie not in the cache
TrieImpl trie = new TrieImpl(mockDb);
for (int i = 0; i < 2000; ++i){
String[] keyVal= strData.get(i).split("=");
if (keyVal[0].equals("*"))
trie.delete(keyVal[1].trim());
else
trie.update(keyVal[0].trim(), keyVal[1].trim());
}
trie.cleanCache();
trie.sync();
TrieImpl trie2 = new TrieImpl(mockDb, trie.getRootHash());
for (int i = 2000; i < strData.size(); ++i){
String[] keyVal= strData.get(i).split("=");
if (keyVal[0].equals("*"))
trie2.delete(keyVal[1].trim());
else
trie2.update(keyVal[0].trim(), keyVal[1].trim());
}
System.out.println("root_2: => " + Hex.toHexString( trie2.getRootHash()));
assertEquals(trieSingle.getRootHash(), trie2.getRootHash());
}