use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.
the class DatabaseVersionDaoTest method testGetLastDatabaseVersionHeader1.
@Test
public void testGetLastDatabaseVersionHeader1() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
DatabaseVersionHeader lastDatabaseVersionHeader = databaseVersionDao.getLastDatabaseVersionHeader();
// Test
assertNotNull(lastDatabaseVersionHeader);
assertEquals("(A8,B3)", lastDatabaseVersionHeader.getVectorClock().toString());
assertEquals("A/(A8,B3)/T=1389977288000", lastDatabaseVersionHeader.toString());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.
the class DatabaseVersionDaoTest method testGetLocalDatabaseBranch1.
@Test
public void testGetLocalDatabaseBranch1() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
DatabaseBranch localDatabaseBranch = databaseVersionDao.getLocalDatabaseBranch();
// Test
assertNotNull(localDatabaseBranch);
assertEquals(11, localDatabaseBranch.size());
assertEquals(11, localDatabaseBranch.getAll().size());
assertEquals(TestDatabaseUtil.createBranch(new String[] { "A/(A1)/T=1389977166000", "A/(A2)/T=1389977199000", "A/(A3)/T=1389977203000", "A/(A4)/T=1389977207000", "A/(A5)/T=1389977214000", "A/(A6)/T=1389977222000", "B/(A6,B1)/T=1389977233000", "A/(A7,B1)/T=1389977234000", "B/(A7,B2)/T=1389977258000", "B/(A7,B3)/T=1389977264000", "A/(A8,B3)/T=1389977288000" }), localDatabaseBranch);
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.
the class DatabaseVersionDaoTest method testRemoveDirtyDatabaseVersions.
@Test
public void testRemoveDirtyDatabaseVersions() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
// a. Test before
List<DatabaseVersion> dirtyDatabaseVersionsBefore = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
assertNotNull(dirtyDatabaseVersionsBefore);
assertNotNull(chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
assertNotNull(multiChunkDao.getDirtyMultiChunkIds());
assertEquals(1, multiChunkDao.getDirtyMultiChunkIds().size());
// b. Add new database version with DIRTY multichunk; remove DIRTY version
DatabaseVersion newDatabaseVersion = new DatabaseVersion();
newDatabaseVersion.setVectorClock(TestDatabaseUtil.createVectorClock("A5,B2"));
long newDatabaseVersionId = databaseVersionDao.writeDatabaseVersion(newDatabaseVersion);
databaseVersionDao.removeDirtyDatabaseVersions(newDatabaseVersionId);
// c. Test after
// Database version
List<DatabaseVersion> dirtyDatabaseVersionsAfter = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
assertNotNull(dirtyDatabaseVersionsAfter);
assertEquals(0, dirtyDatabaseVersionsAfter.size());
// Multichunk from dirty version "moved" to new version
Map<MultiChunkId, MultiChunkEntry> multiChunksA5B2 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A5,B2"));
assertNotNull(multiChunksA5B2);
assertEquals(1, multiChunksA5B2.size());
assertNotNull(multiChunksA5B2.get(MultiChunkId.parseMultiChunkId("1234567890987654321123456789098765433222")));
// File version/history/content ARE removed
assertNull(fileContentDao.getFileContent(FileChecksum.parseFileChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"), true));
// TODO [low] Test file version and file history removal
// Chunks and multichunks are NOT removed!
assertNotNull(chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
assertNotNull(multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("B1")));
assertEquals(0, multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("B1")).size());
assertNotNull(multiChunkDao.getDirtyMultiChunkIds());
assertEquals(0, multiChunkDao.getDirtyMultiChunkIds().size());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.
the class DatabaseVersionDaoTest method testMarkDatabaseVersionDirty.
@Test
public void testMarkDatabaseVersionDirty() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set2.sql");
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
databaseVersionDao.markDatabaseVersionDirty(TestDatabaseUtil.createVectorClock("A48"));
databaseVersionDao.markDatabaseVersionDirty(TestDatabaseUtil.createVectorClock("A49"));
databaseVersionDao.markDatabaseVersionDirty(TestDatabaseUtil.createVectorClock("A50"));
List<DatabaseVersion> dirtyDatabaseVersions = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
// Test
assertNotNull(dirtyDatabaseVersions);
assertEquals(3, dirtyDatabaseVersions.size());
assertEquals("(A48)", dirtyDatabaseVersions.get(0).getVectorClock().toString());
assertEquals("(A49)", dirtyDatabaseVersions.get(1).getVectorClock().toString());
assertEquals("(A50)", dirtyDatabaseVersions.get(2).getVectorClock().toString());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.
the class MultiChunkDaoTest method testGetMultiChunkIdsByFileChecksum.
@Test
public void testGetMultiChunkIdsByFileChecksum() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
List<MultiChunkId> multiChunkIds1 = multiChunkDao.getMultiChunkIds(FileChecksum.parseFileChecksum("254416e71ae50431fc6ced6751075b3366db7cc8"));
List<MultiChunkId> multiChunkIds2 = multiChunkDao.getMultiChunkIds(FileChecksum.parseFileChecksum("7666fd3b860c9d7588d9ca1807eebdf8cfaa8be3"));
List<MultiChunkId> multiChunkIdsDoesNotExist = multiChunkDao.getMultiChunkIds(FileChecksum.parseFileChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"));
// Test
// - Multi chunk for file 254416e71ae50431fc6ced6751075b3366db7cc8
assertNotNull(multiChunkIds1);
assertEquals(1, multiChunkIds1.size());
MultiChunkId multiChunkId1 = multiChunkIds1.get(0);
assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkId1.toString());
// - Multi chunk for file a7405a0bada0035ed52a1a44a4d381b78dc59d19
assertNotNull(multiChunkIds2);
assertEquals(1, multiChunkIds2.size());
MultiChunkId multiChunkId2 = multiChunkIds2.get(0);
assertEquals("53dbeafe18eb2cd6dc519f8b861cf974fda8f26a", multiChunkId2.toString());
// - Multi chunk for non existent file
assertNotNull(multiChunkIdsDoesNotExist);
assertEquals(0, multiChunkIdsDoesNotExist.size());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Aggregations