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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations