use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class FileSystemActionReconciliatorTest method testFileSystemActionReconDeleteNonExistingFolder.
@Test
public void testFileSystemActionReconDeleteNonExistingFolder() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
Config testConfigA = clientA.getConfig();
// - Create first database version
clientA.createNewFolder("new folder/some subfolder");
clientA.upWithForceChecksum();
// Delete this!
clientA.deleteFile("new folder/some subfolder");
// - Create new version (delete folder)
TestSqlDatabase sqlDatabaseA = new TestSqlDatabase(testConfigA);
PartialFileHistory folderFileHistoryWithLastVersion = sqlDatabaseA.getFileHistoryWithLastVersion("new folder/some subfolder");
FileVersion deletedFolderVersion = folderFileHistoryWithLastVersion.getLastVersion().clone();
deletedFolderVersion.setStatus(FileStatus.DELETED);
deletedFolderVersion.setVersion(deletedFolderVersion.getVersion() + 1);
PartialFileHistory deletedFolderVersionHistory = new PartialFileHistory(folderFileHistoryWithLastVersion.getFileHistoryId());
deletedFolderVersionHistory.addFileVersion(deletedFolderVersion);
DatabaseVersion winnersDatabaseVersion = TestDatabaseUtil.createDatabaseVersion(sqlDatabaseA.getLastDatabaseVersionHeader());
winnersDatabaseVersion.addFileHistory(deletedFolderVersionHistory);
// - Create memory database with this version
MemoryDatabase winnersDatabase = new MemoryDatabase();
winnersDatabase.addDatabaseVersion(winnersDatabaseVersion);
// Run! Finally!
DownOperationResult outDownOperationResult = new DownOperationResult();
FileSystemActionReconciliator fileSystemActionReconciliator = new FileSystemActionReconciliator(testConfigA, outDownOperationResult.getChangeSet());
List<FileSystemAction> fileSystemActions = fileSystemActionReconciliator.determineFileSystemActions(winnersDatabase);
assertNotNull(fileSystemActions);
assertEquals(0, fileSystemActions.size());
// Tear down
clientA.deleteTestData();
}
use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class MemoryDatabaseCacheTest method testRemoveDatabaseVersion.
@Test
public void testRemoveDatabaseVersion() {
MemoryDatabase database = new MemoryDatabase();
// Round 1: Add file history & version
DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();
// - history 1, version 1
FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("file.jpg");
FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);
fileHistory1.addFileVersion(fileVersion1);
databaseVersion1.addFileHistory(fileHistory1);
database.addDatabaseVersion(databaseVersion1);
// - history 1, version 2
DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);
FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("file.jpg", fileVersion1);
FileHistoryId idFile1b = FileHistoryId.parseFileId("1111111111111111");
PartialFileHistory fileHistory1b = new PartialFileHistory(idFile1b);
fileHistory1b.addFileVersion(fileVersion2);
databaseVersion2.addFileHistory(fileHistory1b);
database.addDatabaseVersion(databaseVersion2);
// Tests: Database should have 2 versions of file
assertEquals(2, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(2, database.getFileHistory(idFile1b).getFileVersions().size());
// Round 2: Remove second database version
database.removeDatabaseVersion(databaseVersion2);
// Tests: Second version removed, 1 version left
assertEquals(1, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(1, database.getFileHistory(idFile1b).getFileVersions().size());
assertEquals(fileVersion1, database.getFileHistory(idFile1).getLastVersion());
// Round 3: Add database version again
database.addDatabaseVersion(databaseVersion2);
// Tests: Second version added, 2 versions of file
assertEquals(2, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(2, database.getFileHistory(idFile1b).getFileVersions().size());
// Round 4: Remove FIRST database version
database.removeDatabaseVersion(databaseVersion1);
// Tests: First version removed, 1 version left
assertEquals(1, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(1, database.getFileHistory(idFile1b).getFileVersions().size());
assertEquals(fileVersion2, database.getFileHistory(idFile1).getLastVersion());
// Round 5: Remove second database version
database.removeDatabaseVersion(databaseVersion2);
// Tests: Second version removed, none left
assertNull(database.getFileHistory(idFile1));
}
use of org.syncany.database.DatabaseVersion 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.DatabaseVersion 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.DatabaseVersion in project syncany by syncany.
the class XmlDatabaseDaoTest method testWriteAndReadFileHistoryAndFileVersion.
@Test
public void testWriteAndReadFileHistoryAndFileVersion() throws IOException {
// Prepare
MemoryDatabase newDatabase = new MemoryDatabase();
DatabaseVersion newDatabaseVersion = createDatabaseVersion();
// Create directories (no content!)
// File A
PartialFileHistory fileHistoryA = new PartialFileHistory(FileHistoryId.secureRandomFileId());
newDatabaseVersion.addFileHistory(fileHistoryA);
FileVersion versionA1 = new FileVersion();
versionA1.setVersion(1L);
versionA1.setType(FileType.FOLDER);
versionA1.setPath("Pictures/2013/New York Folder");
versionA1.setStatus(FileStatus.NEW);
versionA1.setSize(0L);
versionA1.setLastModified(new Date());
fileHistoryA.addFileVersion(versionA1);
FileVersion versionA2 = new FileVersion();
versionA2.setVersion(2L);
versionA2.setType(FileType.FOLDER);
versionA2.setPath("Pictures/2013/New York");
versionA2.setStatus(FileStatus.RENAMED);
versionA2.setSize(0L);
versionA2.setLastModified(new Date());
fileHistoryA.addFileVersion(versionA2);
// File B
PartialFileHistory fileHistoryB = new PartialFileHistory(FileHistoryId.secureRandomFileId());
newDatabaseVersion.addFileHistory(fileHistoryB);
FileVersion versionB1 = new FileVersion();
versionB1.setVersion(1L);
versionB1.setType(FileType.FOLDER);
versionB1.setPath("Pictures/2013/Egypt Folder");
versionB1.setStatus(FileStatus.NEW);
versionB1.setSize(0L);
versionB1.setLastModified(new Date());
fileHistoryB.addFileVersion(versionB1);
FileVersion versionB2 = new FileVersion();
versionB2.setVersion(2L);
versionB2.setType(FileType.FOLDER);
versionB2.setPath("Pictures/2013/Egypt");
versionB2.setStatus(FileStatus.RENAMED);
versionB2.setSize(0L);
versionB2.setLastModified(new Date());
fileHistoryB.addFileVersion(versionB2);
// Add database version
newDatabase.addDatabaseVersion(newDatabaseVersion);
// Write database to disk, read it again, and compare them
MemoryDatabase loadedDatabase = writeReadAndCompareDatabase(newDatabase);
// File histories
PartialFileHistory loadedFileHistoryA = loadedDatabase.getFileHistory(fileHistoryA.getFileHistoryId());
PartialFileHistory loadedFileHistoryB = loadedDatabase.getFileHistory(fileHistoryB.getFileHistoryId());
assertEquals("File history not found in database loaded.", fileHistoryA, loadedFileHistoryA);
assertEquals("File history not found in database loaded.", fileHistoryB, loadedFileHistoryB);
assertArrayEquals("File versions differ in loaded database.", fileHistoryA.getFileVersions().values().toArray(), loadedFileHistoryA.getFileVersions().values().toArray());
assertArrayEquals("File versions differ in loaded database.", fileHistoryB.getFileVersions().values().toArray(), loadedFileHistoryB.getFileVersions().values().toArray());
}
Aggregations