Package org.syncany.database

Examples of org.syncany.database.DatabaseVersion


    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);
  }
View Full Code Here


   
    // 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.persistDatabaseVersion(newDatabaseVersion);
   
    // d. Capture new last database version header
View Full Code Here

    assertNotNull(chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
    assertNotNull(multiChunkDao.getDirtyMultiChunkIds());
    assertEquals(1, multiChunkDao.getDirtyMultiChunkIds().size());
   
    // b. Add new database version with DIRTY multichunk; remove DIRTY version   
    DatabaseVersion newDatabaseVersion = new DatabaseVersion();
    newDatabaseVersion.setVectorClock(TestDatabaseUtil.createVectorClock("A5,B2"));
   
    long newDatabaseVersionId = databaseVersionDao.persistDatabaseVersion(newDatabaseVersion);   
    databaseVersionDao.removeDirtyDatabaseVersions(newDatabaseVersionId);
       
    // c. Test after   
View Full Code Here

    DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());

    MemoryDatabase remoteDatabase = new MemoryDatabase();
    dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseReadType.FULL, DatabaseVersionType.DEFAULT, null);

    DatabaseVersion remoteDatabaseVersion = remoteDatabase.getLastDatabaseVersion();

    // - Sql Database
    SqlDatabase localDatabase = new SqlDatabase(testConfig);
    Map<FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();

    // Compare!
    assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabaseVersion.getHeader());

    assertEquals(localFileHistories.size(), fileAmount);
    assertEquals(localDatabase.getFileHistoriesWithFileVersions().size(), remoteDatabaseVersion.getFileHistories().size());

    Collection<PartialFileHistory> remoteFileHistories = remoteDatabaseVersion.getFileHistories();

    List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
    List<FileVersion> localFileVersions = new ArrayList<FileVersion>();

    for (PartialFileHistory partialFileHistory : remoteFileHistories) {
View Full Code Here

  @Test
  public void testChunkCache() throws IOException {
    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add chunk to new database version, then add database version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    ChunkEntry chunkA1 = new ChunkEntry(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 }), 12);
    databaseVersion1.addChunk(chunkA1);

    database.addDatabaseVersion(databaseVersion1);
    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));

    // Round 2: Add chunk to new database version, then add database version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    ChunkEntry chunkA2 = new ChunkEntry(new ChunkChecksum(new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 }), 112);
    databaseVersion2.addChunk(chunkA2);

    database.addDatabaseVersion(databaseVersion2);
    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(chunkA2, database.getChunk(new ChunkChecksum(new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 })));

    // Round 3: Add chunk to new database version, then add database version
    DatabaseVersion databaseVersion3 = TestDatabaseUtil.createDatabaseVersion(databaseVersion2);

    ChunkEntry chunkA3 = new ChunkEntry(new ChunkChecksum(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }), 192);
    databaseVersion3.addChunk(chunkA3);

    database.addDatabaseVersion(databaseVersion3);
    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(chunkA2, database.getChunk(new ChunkChecksum(new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 })));
    assertEquals(chunkA3, database.getChunk(new ChunkChecksum(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 })));
View Full Code Here

  @Test
  public void testMultiChunkCache() throws IOException {
    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add chunk to multichunk
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    MultiChunkEntry multiChunkP1 = new MultiChunkEntry(new MultiChunkId(new byte[] { 8, 8, 8, 8, 8, 8, 8, 8 }), 10);
    ChunkEntry chunkA1 = new ChunkEntry(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 }), 12);

    multiChunkP1.addChunk(chunkA1.getChecksum());
    databaseVersion1.addChunk(chunkA1);
    databaseVersion1.addMultiChunk(multiChunkP1);

    database.addDatabaseVersion(databaseVersion1);

    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(multiChunkP1, database.getMultiChunk(new MultiChunkId(new byte[] { 8, 8, 8, 8, 8, 8, 8, 8 })));

    // Round 2: Add chunk to multichunk
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    MultiChunkEntry multiChunkP2 = new MultiChunkEntry(new MultiChunkId(new byte[] { 7, 7, 7, 7, 7, 7, 7, 7, 7 }), 11);
    MultiChunkEntry multiChunkP3 = new MultiChunkEntry(new MultiChunkId(new byte[] { 5, 5, 5, 5, 5, 5, 5, 5, 5 }), 12);

    ChunkEntry chunkA2 = new ChunkEntry(new ChunkChecksum(new byte[] { 9, 2, 3, 4, 5, 7, 8, 9, 0 }), 912);
    ChunkEntry chunkA3 = new ChunkEntry(new ChunkChecksum(new byte[] { 8, 2, 3, 4, 5, 7, 8, 9, 0 }), 812);
    ChunkEntry chunkA4 = new ChunkEntry(new ChunkChecksum(new byte[] { 7, 2, 3, 4, 5, 7, 8, 9, 0 }), 712);

    multiChunkP2.addChunk(chunkA2.getChecksum());
    multiChunkP2.addChunk(chunkA3.getChecksum());
    multiChunkP3.addChunk(chunkA4.getChecksum());

    databaseVersion2.addChunk(chunkA2);
    databaseVersion2.addChunk(chunkA3);
    databaseVersion2.addChunk(chunkA4);

    databaseVersion2.addMultiChunk(multiChunkP2);
    databaseVersion2.addMultiChunk(multiChunkP3);

    database.addDatabaseVersion(databaseVersion2);

    // fail("xx");
View Full Code Here

  @Test
  public void testFilenameCache() throws IOException {
    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("file1.jpg");
    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);

    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);

    database.addDatabaseVersion(databaseVersion1);

    assertEquals(fileHistory1, database.getFileHistory("file1.jpg"));

    // Round 2: Add new version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("file2.jpg", fileVersion1);
    FileHistoryId idFile2 = FileHistoryId.parseFileId("1111111111111111"); // same ID
    PartialFileHistory fileHistory2 = new PartialFileHistory(idFile2);

    fileHistory2.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory2);

    database.addDatabaseVersion(databaseVersion2);

    assertNotNull(database.getFileHistory("file2.jpg"));
    assertEquals(2, database.getFileHistory("file2.jpg").getFileVersions().size());
    assertNull(database.getFileHistory("file1.jpg"));

    // Round 3: Add deleted version
    DatabaseVersion databaseVersion3 = TestDatabaseUtil.createDatabaseVersion(databaseVersion2);

    FileVersion fileVersion3 = TestDatabaseUtil.createFileVersion("file2.jpg", fileVersion2);
    fileVersion3.setStatus(FileStatus.DELETED);

    FileHistoryId idFile3 = FileHistoryId.parseFileId("1111111111111111"); // same ID
    PartialFileHistory fileHistory3 = new PartialFileHistory(idFile3); // same ID

    fileHistory3.addFileVersion(fileVersion3);
    databaseVersion3.addFileHistory(fileHistory3);

    database.addDatabaseVersion(databaseVersion3);

    assertNull(database.getFileHistory("file2.jpg"));
  }
View Full Code Here

  @Test
  public void testFilenameCacheDeleteAndNewOfSameFileInOneDatabaseVersion() throws IOException {
    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("file1.jpg");
    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);

    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);

    database.addDatabaseVersion(databaseVersion1);

    assertEquals(fileHistory1, database.getFileHistory("file1.jpg"));

    // Round 2: Add new version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    // - delete file1.jpg
    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("file1.jpg", fileVersion1);
    fileVersion2.setStatus(FileStatus.DELETED);

    FileHistoryId idFile2 = FileHistoryId.parseFileId("1111111111111111"); // same ID
    PartialFileHistory fileHistory2 = new PartialFileHistory(idFile2);

    fileHistory2.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory2);

    // - add file1.jpg (as FOLDER!)
    FileVersion fileVersion3 = TestDatabaseUtil.createFileVersion("file1.jpg"); // new file!
    fileVersion3.setType(FileType.FOLDER);

    FileHistoryId idFile3 = FileHistoryId.parseFileId("1111111111111112"); // different ID
    PartialFileHistory fileHistory3 = new PartialFileHistory(idFile3); // same ID

    fileHistory3.addFileVersion(fileVersion3);
    databaseVersion2.addFileHistory(fileHistory3);

    // - add database version
    database.addDatabaseVersion(databaseVersion2);

    assertNotNull(database.getFileHistory("file1.jpg"));
View Full Code Here

  @Test
  public void testContentChecksumCache() throws IOException {
    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    // - history 1, version 1
    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("samechecksum1.jpg");
    fileVersion1.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));

    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);

    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);

    database.addDatabaseVersion(databaseVersion1);

    assertNotNull(database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })));
    assertEquals(1, database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })).size());

    // Round 2: Add two other versions with same checksum to new database version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    // - history 1, version 2
    FileVersion fileVersion11 = TestDatabaseUtil.createFileVersion("samechecksum2-renamed.jpg", fileVersion1);
    fileVersion11.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!
    fileVersion11.setStatus(FileStatus.RENAMED);

    FileHistoryId idFile11 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory11 = new PartialFileHistory(idFile11); // same ID as above

    fileHistory11.addFileVersion(fileVersion11);
    databaseVersion2.addFileHistory(fileHistory11);

    // - history 2, version 1
    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("samechecksum2.jpg");
    fileVersion2.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!

    FileHistoryId idFile2 = FileHistoryId.parseFileId("1111111122222222"); // different ID
    PartialFileHistory fileHistory2 = new PartialFileHistory(idFile2);

    fileHistory2.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory2);

    // - history 3, version 1
    FileVersion fileVersion3 = TestDatabaseUtil.createFileVersion("samechecksum3.jpg");
    fileVersion3.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!

    FileHistoryId idFile3 = FileHistoryId.parseFileId("aaaaaaaa22222222"); // different ID
    PartialFileHistory fileHistory3 = new PartialFileHistory(idFile3); // different ID

    fileHistory3.addFileVersion(fileVersion3);
    databaseVersion2.addFileHistory(fileHistory3);

    database.addDatabaseVersion(databaseVersion2);

    assertNotNull(database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })));
    assertEquals(3, database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })).size());
View Full Code Here

  @Test
  public void testGetFileHistory() throws IOException {
    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    // - history 1, version 1
    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("samechecksum1.jpg");
    fileVersion1.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));

    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);

    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);

    database.addDatabaseVersion(databaseVersion1);

    FileHistoryId idFile1Get = FileHistoryId.parseFileId("1111111111111111");
    assertNotNull(database.getFileHistory(idFile1Get));
    assertEquals(fileHistory1, database.getFileHistory(idFile1Get));

    // Round 2: Add two other versions with same checksum to new database version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    // - history 1, version 2
    FileVersion fileVersion11 = TestDatabaseUtil.createFileVersion("samechecksum2-renamed.jpg", fileVersion1);
    fileVersion11.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); // same checksum!
    fileVersion11.setStatus(FileStatus.RENAMED);

    FileHistoryId idFile11 = FileHistoryId.parseFileId("1111111111111111"); // same ID
    PartialFileHistory fileHistory11 = new PartialFileHistory(idFile11);

    fileHistory11.addFileVersion(fileVersion11);
    databaseVersion2.addFileHistory(fileHistory11);

    database.addDatabaseVersion(databaseVersion2);

    FileHistoryId idFile111 = FileHistoryId.parseFileId("1111111111111111"); // same ID
    assertNotNull(database.getFileHistory(idFile111));
View Full Code Here

TOP

Related Classes of org.syncany.database.DatabaseVersion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.