use of org.syncany.config.Config in project syncany by syncany.
the class ChunkDaoTest method testGetChunksForDatabaseVersion.
@Test
public void testGetChunksForDatabaseVersion() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
Map<ChunkChecksum, ChunkEntry> chunksForA1 = chunkDao.getChunks(TestDatabaseUtil.createVectorClock("A1"));
Map<ChunkChecksum, ChunkEntry> chunksForA2 = chunkDao.getChunks(TestDatabaseUtil.createVectorClock("A2"));
Map<ChunkChecksum, ChunkEntry> chunksForA4 = chunkDao.getChunks(TestDatabaseUtil.createVectorClock("A4"));
Map<ChunkChecksum, ChunkEntry> chunksForB1 = chunkDao.getChunks(TestDatabaseUtil.createVectorClock("B1"));
Map<ChunkChecksum, ChunkEntry> chunksForNonExistent = chunkDao.getChunks(TestDatabaseUtil.createVectorClock("NonExistent1"));
// Test
assertNotNull(chunksForA1);
assertEquals(1, chunksForA1.size());
assertNotNull(chunksForA1.get(ChunkChecksum.parseChunkChecksum("fe83f217d464f6fdfa5b2b1f87fe3a1a47371196")));
assertNotNull(chunksForA2);
assertEquals(1, chunksForA2.size());
assertNotNull(chunksForA2.get(ChunkChecksum.parseChunkChecksum("bf8b4530d8d246dd74ac53a13471bba17941dff7")));
assertNotNull(chunksForA4);
// Especially: does NOT contain fe83f217d464f6fdfa5b2b1f87fe3a1a47371196
assertEquals(0, chunksForA4.size());
assertNotNull(chunksForB1);
assertEquals(1, chunksForB1.size());
assertNotNull(chunksForB1.get(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
assertNotNull(chunksForNonExistent);
assertEquals(0, chunksForNonExistent.size());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.config.Config 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.config.Config in project syncany by syncany.
the class FileContentDaoTest method testGetFileContentsByVectorClock.
@Test
public void testGetFileContentsByVectorClock() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
Map<FileChecksum, FileContent> fileContentsA1 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A1"));
Map<FileChecksum, FileContent> fileContentsA2 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A2"));
Map<FileChecksum, FileContent> fileContentsA3 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A3"));
Map<FileChecksum, FileContent> fileContentsA4 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A4"));
Map<FileChecksum, FileContent> fileContentsA5 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A5"));
Map<FileChecksum, FileContent> fileContentsA6 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A6"));
Map<FileChecksum, FileContent> fileContentsA6B1 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A6,B1"));
Map<FileChecksum, FileContent> fileContentsA7B1 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("A7,B1"));
Map<FileChecksum, FileContent> fileContentsInvalid1 = fileContentDao.getFileContents(TestDatabaseUtil.createVectorClock("Invalid1"));
// Test
assertNotNull(fileContentsA1);
assertEquals(0, fileContentsA1.size());
assertNotNull(fileContentsA2);
assertEquals(0, fileContentsA2.size());
assertNotNull(fileContentsA3);
assertEquals(0, fileContentsA3.size());
assertNotNull(fileContentsA4);
assertEquals(0, fileContentsA4.size());
assertNotNull(fileContentsA5);
assertEquals(1, fileContentsA5.size());
assertNotNull(fileContentsA5.get(FileChecksum.parseFileChecksum("0fefb345b62b6c0b0e5212158a9aa7c1eeec2ca6")));
assertEquals(12, fileContentsA5.get(FileChecksum.parseFileChecksum("0fefb345b62b6c0b0e5212158a9aa7c1eeec2ca6")).getSize());
assertNotNull(fileContentsA6);
assertEquals(1, fileContentsA6.size());
assertNotNull(fileContentsA6.get(FileChecksum.parseFileChecksum("24a39e00d6156804e27f7c0987d00903da8e6682")));
assertEquals(508, fileContentsA6.get(FileChecksum.parseFileChecksum("24a39e00d6156804e27f7c0987d00903da8e6682")).getSize());
assertNotNull(fileContentsA6B1);
assertEquals(1, fileContentsA6B1.size());
assertNotNull(fileContentsA6B1.get(FileChecksum.parseFileChecksum("7666fd3b860c9d7588d9ca1807eebdf8cfaa8be3")));
assertEquals(2029, fileContentsA6B1.get(FileChecksum.parseFileChecksum("7666fd3b860c9d7588d9ca1807eebdf8cfaa8be3")).getSize());
assertNotNull(fileContentsA7B1);
assertEquals(1, fileContentsA7B1.size());
assertNotNull(fileContentsA7B1.get(FileChecksum.parseFileChecksum("eba69a8e359ce3258520138a50ed9860127ab6e0")));
assertEquals(512, fileContentsA7B1.get(FileChecksum.parseFileChecksum("eba69a8e359ce3258520138a50ed9860127ab6e0")).getSize());
assertNotNull(fileContentsInvalid1);
assertEquals(0, fileContentsInvalid1.size());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.config.Config in project syncany by syncany.
the class DatabaseVersionDaoTest method testGetLocalDatabaseBranch2.
@Test
public void testGetLocalDatabaseBranch2() 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);
DatabaseBranch localDatabaseBranch = databaseVersionDao.getLocalDatabaseBranch();
// Test
assertNotNull(localDatabaseBranch);
assertEquals(5, localDatabaseBranch.size());
assertEquals(5, localDatabaseBranch.getAll().size());
assertEquals(TestDatabaseUtil.createBranch(new String[] { "A/(A1)/T=1388589969000", "A/(A2)/T=1388676369000", // Note: Does NOT contain B1 (because: DIRTY!)
"A/(A3)/T=1388762769000", "A/(A4)/T=1388849289000", "A/(A5)/T=1388935689000" }), localDatabaseBranch);
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.config.Config in project syncany by syncany.
the class DatabaseVersionDaoTest method testNonEmptyDatabaseVersionHeaders2.
@Test
public void testNonEmptyDatabaseVersionHeaders2() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
// Delete fileversions from first database version such that it has no content.
TestSqlUtil.runSql("DELETE FROM fileversion WHERE databaseversion_id = 0", databaseConnection);
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);
List<DatabaseVersionHeader> databaseVersionHeaders = databaseVersionDao.getNonEmptyDatabaseVersionHeaders();
Collection<String> databaseVersionHeaderStrings = databaseVersionHeaders.stream().map(dbv -> dbv.toString()).collect(Collectors.toCollection(ArrayList::new));
// Test
assertNotNull(databaseVersionHeaders);
assertEquals(5, databaseVersionHeaders.size());
assertTrue(CollectionUtil.containsExactly(Arrays.asList(new String[] { // (A1) is not present, because it is empty
"A/(A2)/T=1388676369000", "A/(A3)/T=1388762769000", "A/(A4)/T=1388849289000", "A/(A5)/T=1388935689000", "B/(B1)/T=1388849289000" }), databaseVersionHeaderStrings));
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Aggregations