Search in sources :

Example 6 with FileHistorySqlDao

use of org.syncany.database.dao.FileHistorySqlDao 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();
}
Also used : Config(org.syncany.config.Config) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) PartialFileHistory(org.syncany.database.PartialFileHistory) ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) TestClient(org.syncany.tests.util.TestClient) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 7 with FileHistorySqlDao

use of org.syncany.database.dao.FileHistorySqlDao 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);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Config(org.syncany.config.Config) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Example 8 with FileHistorySqlDao

use of org.syncany.database.dao.FileHistorySqlDao 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);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) Arrays(java.util.Arrays) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Connection(java.sql.Connection) Date(java.util.Date) TestDatabaseUtil(org.syncany.tests.util.TestDatabaseUtil) MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) ChunkEntry(org.syncany.database.ChunkEntry) ArrayList(java.util.ArrayList) FileType(org.syncany.database.FileVersion.FileType) TestConfigUtil(org.syncany.tests.util.TestConfigUtil) FileChecksum(org.syncany.database.FileContent.FileChecksum) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) CollectionUtil(org.syncany.util.CollectionUtil) Map(java.util.Map) FileVersion(org.syncany.database.FileVersion) FileStatus(org.syncany.database.FileVersion.FileStatus) TestSqlUtil(org.syncany.tests.util.TestSqlUtil) DatabaseVersion(org.syncany.database.DatabaseVersion) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) MultiChunkEntry(org.syncany.database.MultiChunkEntry) Iterator(java.util.Iterator) TestCollectionUtil(org.syncany.tests.util.TestCollectionUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) List(java.util.List) Config(org.syncany.config.Config) Assert.assertNull(org.junit.Assert.assertNull) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) PartialFileHistory(org.syncany.database.PartialFileHistory) FileContent(org.syncany.database.FileContent) Assert.assertEquals(org.junit.Assert.assertEquals) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) Config(org.syncany.config.Config) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Example 9 with FileHistorySqlDao

use of org.syncany.database.dao.FileHistorySqlDao 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);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Config(org.syncany.config.Config) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 10 with FileHistorySqlDao

use of org.syncany.database.dao.FileHistorySqlDao 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);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Config(org.syncany.config.Config) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 Config (org.syncany.config.Config)12 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)12 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)12 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)12 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)12 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)12 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)12 Connection (java.sql.Connection)11 DatabaseVersion (org.syncany.database.DatabaseVersion)8 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)4 MultiChunkEntry (org.syncany.database.MultiChunkEntry)4 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)4 PartialFileHistory (org.syncany.database.PartialFileHistory)4 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)4 Date (java.util.Date)3 ChunkEntry (org.syncany.database.ChunkEntry)3 FileContent (org.syncany.database.FileContent)3 FileVersion (org.syncany.database.FileVersion)3 ArrayList (java.util.ArrayList)2