use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class UpOperation method prepareResume.
private void prepareResume() throws Exception {
Collection<Long> versionsToResume = transferManager.loadPendingTransactionList();
boolean hasVersionsToResume = versionsToResume != null && versionsToResume.size() > 0;
if (hasVersionsToResume) {
logger.log(Level.INFO, "Found local transaction to resume.");
logger.log(Level.INFO, "Attempting to find transactionRemoteFile");
remoteTransactionsToResume = attemptResumeTransactions(versionsToResume);
Collection<DatabaseVersion> remoteDatabaseVersionsToResume = attemptResumeDatabaseVersions(versionsToResume);
resuming = remoteDatabaseVersionsToResume != null && remoteTransactionsToResume != null && remoteDatabaseVersionsToResume.size() == remoteTransactionsToResume.size();
if (resuming) {
databaseVersionQueue.addAll(remoteDatabaseVersionsToResume);
// Empty database version is the stopping marker
databaseVersionQueue.add(new DatabaseVersion());
transactionRemoteFileToResume = attemptResumeTransactionRemoteFile();
} else {
transferManager.clearResumableTransactions();
}
} else {
transferManager.clearResumableTransactions();
}
}
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 DatabaseVersionDaoTest method testGetDatabaseVersionsTo.
@Test
public void testGetDatabaseVersionsTo() 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);
Iterator<DatabaseVersion> databaseVersionsToA2 = databaseVersionDao.getDatabaseVersionsTo("A", 2);
Iterator<DatabaseVersion> databaseVersionsToA5 = databaseVersionDao.getDatabaseVersionsTo("A", 5);
// B1 is DIRTY !
Iterator<DatabaseVersion> databaseVersionsToB1 = databaseVersionDao.getDatabaseVersionsTo("B", 1);
List<DatabaseVersion> databaseVersionsToA2List = TestCollectionUtil.toList(databaseVersionsToA2);
List<DatabaseVersion> databaseVersionsToA5List = TestCollectionUtil.toList(databaseVersionsToA5);
List<DatabaseVersion> databaseVersionsToB1List = TestCollectionUtil.toList(databaseVersionsToB1);
// Test
assertNotNull(databaseVersionsToA2);
assertEquals(2, databaseVersionsToA2List.size());
assertEquals("(A1)", databaseVersionsToA2List.get(0).getHeader().getVectorClock().toString());
assertEquals("(A2)", databaseVersionsToA2List.get(1).getHeader().getVectorClock().toString());
assertNotNull(databaseVersionsToA5);
assertEquals(5, databaseVersionsToA5List.size());
assertEquals("(A1)", databaseVersionsToA5List.get(0).getHeader().getVectorClock().toString());
assertEquals("(A2)", databaseVersionsToA5List.get(1).getHeader().getVectorClock().toString());
assertEquals("(A3)", databaseVersionsToA5List.get(2).getHeader().getVectorClock().toString());
assertEquals("(A4)", databaseVersionsToA5List.get(3).getHeader().getVectorClock().toString());
assertEquals("(A5)", databaseVersionsToA5List.get(4).getHeader().getVectorClock().toString());
assertNotNull(databaseVersionsToB1);
assertEquals(0, databaseVersionsToB1List.size());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class DatabaseVersionDaoTest method testGetDatabaseVersionsMasterAndDirty.
@Test
public void testGetDatabaseVersionsMasterAndDirty() 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);
Iterator<DatabaseVersion> databaseVersionsDirty = databaseVersionDao.getDirtyDatabaseVersions();
// Test
assertNotNull(databaseVersionsDirty);
List<DatabaseVersion> databaseVersionsDirtyList = TestCollectionUtil.toList(databaseVersionsDirty);
assertEquals(1, databaseVersionsDirtyList.size());
DatabaseVersion databaseVersionB1 = databaseVersionsDirtyList.get(0);
assertEquals("(B1)", databaseVersionB1.getVectorClock().toString());
assertEquals(1, databaseVersionB1.getChunks().size());
assertEquals(1, databaseVersionB1.getMultiChunks().size());
assertEquals(1, databaseVersionB1.getFileContents().size());
assertEquals(2, databaseVersionB1.getFileHistories().size());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.DatabaseVersion in project syncany by syncany.
the class DatabaseVersionDaoTest method testPersistDatabaseVersion.
@Test
public void testPersistDatabaseVersion() 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. Capture database version header (now)
DatabaseVersionHeader lastDatabaseVersionHeaderBefore = databaseVersionDao.getLastDatabaseVersionHeader();
// b. Add new database header (with one file history)
DatabaseVersion newDatabaseVersion = new DatabaseVersion();
DatabaseVersionHeader newDatabaseVersionHeader = new DatabaseVersionHeader();
newDatabaseVersionHeader.setClient("C");
newDatabaseVersionHeader.setDate(new Date(1489977288000L));
newDatabaseVersionHeader.setVectorClock(TestDatabaseUtil.createVectorClock("A5,C1"));
newDatabaseVersion.setHeader(newDatabaseVersionHeader);
PartialFileHistory newFileHistory = new PartialFileHistory(FileHistoryId.secureRandomFileId());
FileVersion newFileVersion = new FileVersion();
newFileVersion.setVersion(1L);
newFileVersion.setPath("newfile");
newFileVersion.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
newFileVersion.setLinkTarget(null);
newFileVersion.setPosixPermissions("rwxrwxrwx");
newFileVersion.setDosAttributes(null);
newFileVersion.setStatus(FileStatus.NEW);
newFileVersion.setLastModified(new Date());
newFileVersion.setUpdated(new Date());
newFileVersion.setSize(1L);
newFileVersion.setType(FileType.FILE);
newFileHistory.addFileVersion(newFileVersion);
newDatabaseVersion.addFileHistory(newFileHistory);
ChunkEntry newChunkEntry = new ChunkEntry(ChunkChecksum.parseChunkChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"), 1);
newDatabaseVersion.addChunk(newChunkEntry);
MultiChunkEntry newMultiChunkEntry = new MultiChunkEntry(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"), 10);
newMultiChunkEntry.addChunk(newChunkEntry.getChecksum());
newDatabaseVersion.addMultiChunk(newMultiChunkEntry);
FileContent newFileContent = new FileContent();
newFileContent.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
newFileContent.setSize(1L);
newFileContent.addChunk(newChunkEntry.getChecksum());
newDatabaseVersion.addFileContent(newFileContent);
// c. Persist database version
databaseVersionDao.writeDatabaseVersion(newDatabaseVersion);
// d. Capture new last database version header
DatabaseVersionHeader lastDatabaseVersionHeaderAfter = databaseVersionDao.getLastDatabaseVersionHeader();
// Test
assertNotNull(lastDatabaseVersionHeaderBefore);
assertEquals("A/(A5)/T=1388935689000", lastDatabaseVersionHeaderBefore.toString());
assertNotNull(lastDatabaseVersionHeaderAfter);
assertEquals("C/(A5,C1)/T=1489977288000", lastDatabaseVersionHeaderAfter.toString());
assertEquals(newDatabaseVersionHeader.getVectorClock(), lastDatabaseVersionHeaderAfter.getVectorClock());
assertEquals(newChunkEntry, chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f")));
assertEquals(newFileContent, fileContentDao.getFileContent(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"), true));
Map<MultiChunkId, MultiChunkEntry> multiChunkIds = multiChunkDao.getMultiChunks(newDatabaseVersionHeader.getVectorClock());
assertNotNull(multiChunkIds);
assertEquals(1, multiChunkIds.size());
MultiChunkEntry actualNewMultiChunkEntry = multiChunkIds.get(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"));
assertNotNull(actualNewMultiChunkEntry);
assertEquals(newMultiChunkEntry.getId(), actualNewMultiChunkEntry.getId());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Aggregations