Search in sources :

Example 11 with MultiChunkSqlDao

use of org.syncany.database.dao.MultiChunkSqlDao 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)

Example 12 with MultiChunkSqlDao

use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.

the class MultiChunkDaoTest method testGetDirtyMultiChunks.

@Test
public void testGetDirtyMultiChunks() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    List<MultiChunkId> dirtyMultiChunkIds = multiChunkDao.getDirtyMultiChunkIds();
    // Test
    assertNotNull(dirtyMultiChunkIds);
    assertEquals(1, dirtyMultiChunkIds.size());
    assertEquals(MultiChunkId.parseMultiChunkId("1234567890987654321123456789098765433222"), dirtyMultiChunkIds.get(0));
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Test(org.junit.Test)

Example 13 with MultiChunkSqlDao

use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.

the class MultiChunkDaoTest method testGetMultiChunkIds.

@Test
public void testGetMultiChunkIds() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    List<ChunkChecksum> checksums = new ArrayList<ChunkChecksum>();
    checksums.add(ChunkChecksum.parseChunkChecksum("eba69a8e359ce3258520138a50ed9860127ab6e0"));
    checksums.add(ChunkChecksum.parseChunkChecksum("0fecbac8ac8a5f8b7aa12b2741a4ef5db88c5dea"));
    checksums.add(ChunkChecksum.parseChunkChecksum("38a18897e94a901b833e750e8604d9616a02ca84"));
    checksums.add(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"));
    //Ensure that uniqueness is not required
    checksums.add(ChunkChecksum.parseChunkChecksum("38a18897e94a901b833e750e8604d9616a02ca84"));
    Map<ChunkChecksum, MultiChunkId> multiChunkIds = multiChunkDao.getMultiChunkIdsByChecksums(checksums);
    // Test
    assertNotNull(multiChunkIds.get(checksums.get(0)));
    assertEquals("0d79eed3fd8ac866b5872ea3f3f079c46dd15ac9", multiChunkIds.get(checksums.get(0)).toString());
    assertNotNull(multiChunkIds.get(checksums.get(1)));
    assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkIds.get(checksums.get(1)).toString());
    assertNotNull(multiChunkIds.get(checksums.get(2)));
    assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkIds.get(checksums.get(2)).toString());
    assertEquals(multiChunkIds.get(checksums.get(1)), multiChunkIds.get(checksums.get(2)));
    assertNull(multiChunkIds.get(checksums.get(3)));
    Map<ChunkChecksum, MultiChunkId> multiChunkIdsEmpty = multiChunkDao.getMultiChunkIdsByChecksums(new ArrayList<ChunkChecksum>());
    assertTrue(multiChunkIdsEmpty.isEmpty());
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Test(org.junit.Test)

Example 14 with MultiChunkSqlDao

use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.

the class MultiChunkDaoTest method testGetMultiChunksByDatabaseVersion2.

@Test
public void testGetMultiChunksByDatabaseVersion2() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    Map<MultiChunkId, MultiChunkEntry> multiChunksA4 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A4"));
    Map<MultiChunkId, MultiChunkEntry> multiChunksA5 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A5"));
    // Test
    // - Database version "A4"		
    assertNotNull(multiChunksA4);
    assertEquals(0, multiChunksA4.size());
    // - Database version "A5"
    assertNotNull(multiChunksA5);
    assertEquals(1, multiChunksA5.size());
    MultiChunkEntry multiChunkInA5 = multiChunksA5.get(MultiChunkId.parseMultiChunkId("dddddddddddddddddddddddddddddddddddddddd"));
    assertNotNull(multiChunkInA5);
    assertEquals("dddddddddddddddddddddddddddddddddddddddd", multiChunkInA5.getId().toString());
    assertTrue(CollectionUtil.containsExactly(multiChunkInA5.getChunks(), ChunkChecksum.parseChunkChecksum("ffffffffffffffffffffffffffffffffffffffff")));
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) MultiChunkEntry(org.syncany.database.MultiChunkEntry) Test(org.junit.Test)

Example 15 with MultiChunkSqlDao

use of org.syncany.database.dao.MultiChunkSqlDao in project syncany by syncany.

the class DatabaseVersionDaoTest method testGetMaxDirtyVectorClock.

@Test
public void testGetMaxDirtyVectorClock() 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);
    Long maxDirtyVectorClockA = databaseVersionDao.getMaxDirtyVectorClock("A");
    Long maxDirtyVectorClockB = databaseVersionDao.getMaxDirtyVectorClock("B");
    // Test
    assertNull(maxDirtyVectorClockA);
    assertNotNull(maxDirtyVectorClockB);
    assertEquals(1, (long) maxDirtyVectorClockB);
    // 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) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Config (org.syncany.config.Config)16 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)16 Connection (java.sql.Connection)15 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)10 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)10 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)10 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)10 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)10 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)8 DatabaseVersion (org.syncany.database.DatabaseVersion)6 MultiChunkEntry (org.syncany.database.MultiChunkEntry)4 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)2 PartialFileHistory (org.syncany.database.PartialFileHistory)2 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ChunkEntry (org.syncany.database.ChunkEntry)1 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)1 FileContent (org.syncany.database.FileContent)1