use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class UpOperationTest method testUploadLocalDatabase.
@Test
public void testUploadLocalDatabase() throws Exception {
int fileSize = 1230 * 1024;
int fileAmount = 3;
List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
// Run!
AbstractTransferOperation op = new UpOperation(testConfig);
op.execute();
// Get databases (for comparison)
LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
File localDatabaseDir = testConfig.getDatabaseDir();
File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-0000000001");
assertNotNull(localDatabaseDir.listFiles());
assertTrue(localDatabaseDir.listFiles().length > 0);
assertTrue(remoteDatabaseFile.exists());
// - Memory database
DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
MemoryDatabase remoteDatabase = new MemoryDatabase();
dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseReadType.FULL);
DatabaseVersion remoteDatabaseVersion = remoteDatabase.getLastDatabaseVersion();
// - Sql Database
SqlDatabase localDatabase = new SqlDatabase(testConfig);
Map<FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
// Compare!
assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabaseVersion.getHeader());
assertEquals(localFileHistories.size(), fileAmount);
assertEquals(localDatabase.getFileHistoriesWithFileVersions().size(), remoteDatabaseVersion.getFileHistories().size());
Collection<PartialFileHistory> remoteFileHistories = remoteDatabaseVersion.getFileHistories();
List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
List<FileVersion> localFileVersions = new ArrayList<FileVersion>();
for (PartialFileHistory partialFileHistory : remoteFileHistories) {
remoteFileVersions.add(partialFileHistory.getLastVersion());
assertNotNull(localFileHistories.get(partialFileHistory.getFileHistoryId()));
}
for (PartialFileHistory partialFileHistory : localFileHistories.values()) {
localFileVersions.add(partialFileHistory.getLastVersion());
}
assertTrue(CollectionUtil.containsExactly(localFileVersions, remoteFileVersions));
compareFileVersionsAgainstOriginalFiles(originalFiles, localFileVersions);
compareFileVersionsAgainstOriginalFiles(originalFiles, remoteFileVersions);
}
use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class DirtyDatabaseScenarioTest method testDirtyDatabase.
@Test
public void testDirtyDatabase() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
upOptionsForceEnabled.setForceUploadEnabled(true);
clientA.createNewFile("A-file1.jpg", 50 * 1024);
clientA.up(upOptionsForceEnabled);
clientB.createNewFile("A-file1.jpg", 51 * 1024);
clientB.up(upOptionsForceEnabled);
// This creates a dirty database
clientB.down();
// Test (for dirty database existence)
Config configB = clientB.getConfig();
java.sql.Connection databaseConnectionB = configB.createDatabaseConnection();
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnectionB);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnectionB);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnectionB);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnectionB, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnectionB);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnectionB, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
Iterator<DatabaseVersion> databaseVersionsDirtyB = databaseVersionDao.getDirtyDatabaseVersions();
List<DatabaseVersion> databaseVersionsDirtyListB = TestCollectionUtil.toList(databaseVersionsDirtyB);
assertEquals(1, databaseVersionsDirtyListB.size());
DatabaseVersion dirtyDatabaseVersionB = databaseVersionsDirtyListB.get(0);
assertNotNull(dirtyDatabaseVersionB);
assertEquals(1, dirtyDatabaseVersionB.getFileHistories().size());
PartialFileHistory fileHistoryFile1B = dirtyDatabaseVersionB.getFileHistories().iterator().next();
assertNotNull(fileHistoryFile1B);
assertEquals(1, fileHistoryFile1B.getFileVersions().size());
assertEquals("A-file1.jpg", fileHistoryFile1B.getLastVersion().getPath());
assertFileEquals(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead());
// Run (part 2)
// This deletes the dirty database file
clientB.up();
Iterator<DatabaseVersion> databaseVersionsDirtyB2 = databaseVersionDao.getDirtyDatabaseVersions();
List<DatabaseVersion> databaseVersionsDirtyListB2 = TestCollectionUtil.toList(databaseVersionsDirtyB2);
assertEquals(0, databaseVersionsDirtyListB2.size());
// Run (part 3)
// This pulls down the conflicting file
clientA.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
assertConflictingFileExists("A-file1.jpg", clientA.getLocalFilesExcludeLockedAndNoRead());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class TestDatabaseUtil method createDatabaseVersion.
public static DatabaseVersion createDatabaseVersion(DatabaseVersionHeader basedOnDatabaseVersionHeader, Date date) {
VectorClock vectorClock = (basedOnDatabaseVersionHeader != null) ? basedOnDatabaseVersionHeader.getVectorClock().clone() : new VectorClock();
vectorClock.incrementClock("someclient");
DatabaseVersion databaseVersion = new DatabaseVersion();
databaseVersion.setClient("someclient");
databaseVersion.setTimestamp(date);
databaseVersion.setVectorClock(vectorClock);
return databaseVersion;
}
Aggregations