@Test public void testRenameAndCheckIfMultiChunksAreDownloaded() throws Exception { // Setup Connection testConnection = TestConfigUtil.createTestLocalConnection(); TestClient clientA = new TestClient("A", testConnection); TestClient clientB = new TestClient("B", testConnection); // Run // Prepare, create file at A, sync it to B clientA.createNewFile("A-file1"); clientA.sync(); clientB.sync(); // Now move file, and sync clientA.moveFile("A-file1", "A-file-moved1"); clientA.up(); DownOperationResult downOperationResult = clientB.down(); assertEquals( "No multichunks should have been downloaded.", 0, downOperationResult.getDownloadedMultiChunks().size()); assertTrue("Moved files should exist.", clientB.getLocalFile("A-file-moved1").exists()); assertFileListEquals(clientA.getLocalFiles(), clientB.getLocalFiles()); assertDatabaseFileEquals( clientA.getLocalDatabaseFile(), clientB.getLocalDatabaseFile(), clientA.getConfig().getTransformer()); // Tear down clientA.cleanup(); clientB.cleanup(); }
@Test public void testManySyncUpsAndDatabaseFileCleanup() throws Exception { // Setup LocalConnection testConnection = (LocalConnection) TestConfigUtil.createTestLocalConnection(); TestClient clientA = new TestClient("A", testConnection); // ROUND 1: many sync up (no cleanup expected here) for (int i = 1; i <= 15; i++) { clientA.createNewFile("file" + i, 1); clientA.up(); } for (int i = 1; i <= 15; i++) { File expectedDatabaseFile = new File(testConnection.getRepositoryPath() + "/db-A-" + i); assertTrue( "Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists()); } // ROUND 2: 1x sync up (cleanup expected!) clientA.createNewFile("file16", 1); clientA.up(); for (int i = 1; i <= 10; i++) { File expectedDatabaseFile = new File(testConnection.getRepositoryPath() + "/db-A-" + i); assertTrue( "Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists()); } for (int i = 11; i <= 16; i++) { File expectedDatabaseFile = new File(testConnection.getRepositoryPath() + "/db-A-" + i); assertTrue( "Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists()); } // ROUND 3: many sync up (no cleanup expected here) for (int i = 17; i <= 25; i++) { clientA.createNewFile("file" + i, 1); clientA.up(); } for (int i = 1; i <= 10; i++) { File expectedDatabaseFile = new File(testConnection.getRepositoryPath() + "/db-A-" + i); assertTrue( "Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists()); } for (int i = 11; i <= 25; i++) { File expectedDatabaseFile = new File(testConnection.getRepositoryPath() + "/db-A-" + i); assertTrue( "Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists()); } // ROUND 4: 1x sync up (cleanup expected!) clientA.createNewFile("file26", 1); clientA.up(); for (int i = 1; i <= 20; i++) { File expectedDatabaseFile = new File(testConnection.getRepositoryPath() + "/db-A-" + i); assertTrue( "Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists()); } for (int i = 21; i <= 25; i++) { File expectedDatabaseFile = new File(testConnection.getRepositoryPath() + "/db-A-" + i); assertTrue( "Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists()); } // Tear down clientA.cleanup(); }
@Test public void testChangedModifiedDate() throws Exception { // Setup Connection testConnection = TestConfigUtil.createTestLocalConnection(); TestClient clientA = new TestClient("A", testConnection); TestClient clientB = new TestClient("B", testConnection); // Run // A, create two files with identical content and change mod. date of one of them clientA.createNewFile("A-file1.jpg", 50 * 1024); clientA.copyFile("A-file1.jpg", "A-file1-with-different-modified-date.jpg"); clientA.getLocalFile("A-file1.jpg").setLastModified(0); clientA.up(); // B, down, then move BOTH files clientB.down(); assertFileListEquals(clientA.getLocalFiles(), clientB.getLocalFiles()); assertDatabaseFileEquals( clientA.getLocalDatabaseFile(), clientB.getLocalDatabaseFile(), clientA.getConfig().getTransformer()); clientB.moveFile("A-file1.jpg", "A-file1-moved.jpg"); clientB.moveFile( "A-file1-with-different-modified-date.jpg", "A-file1-with-different-modified-date-moved.jpg"); clientB.up(); Database clientDatabaseB = clientB.loadLocalDatabase(); PartialFileHistory file1Orig = clientDatabaseB.getFileHistory("A-file1-moved.jpg"); PartialFileHistory file1WithDiffLastModDate = clientDatabaseB.getFileHistory("A-file1-with-different-modified-date-moved.jpg"); assertNotNull(file1Orig); assertNotNull(file1WithDiffLastModDate); FileVersion fileVersion1OrigV1 = file1Orig.getFileVersion(1); FileVersion fileVersion1OrigV2 = file1Orig.getFileVersion(2); FileVersion fileVersion1WithDiffLastModDateV1 = file1WithDiffLastModDate.getFileVersion(1); FileVersion fileVersion1WithDiffLastModDateV2 = file1WithDiffLastModDate.getFileVersion(2); assertNotNull(fileVersion1OrigV1); assertNotNull(fileVersion1OrigV2); assertNotNull(fileVersion1WithDiffLastModDateV1); assertNotNull(fileVersion1WithDiffLastModDateV2); assertEquals("A-file1.jpg", fileVersion1OrigV1.getName()); assertEquals("A-file1-moved.jpg", fileVersion1OrigV2.getName()); assertEquals( "A-file1-with-different-modified-date.jpg", fileVersion1WithDiffLastModDateV1.getName()); assertEquals( "A-file1-with-different-modified-date-moved.jpg", fileVersion1WithDiffLastModDateV2.getName()); // Tear down clientA.cleanup(); clientB.cleanup(); }
@Test public void testDirtyDatabase() throws Exception { // Setup Connection 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", 50 * 1024); clientB.up(upOptionsForceEnabled); clientB.down(); // This creates a dirty database assertTrue("Dirty database should exist.", clientB.getDirtyDatabaseFile().exists()); assertFileEquals( "Files should be identical", clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg")); assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead()); clientB.up(); // This deletes the dirty database file assertFalse("Dirty database should NOT exist.", clientB.getDirtyDatabaseFile().exists()); clientA.down(); // This pulls down the conflicting file assertFileListEquals( clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead()); assertDatabaseFileEquals( clientA.getLocalDatabaseFile(), clientB.getLocalDatabaseFile(), clientA.getConfig().getTransformer()); assertConflictingFileExists("A-file1.jpg", clientA.getLocalFilesExcludeLockedAndNoRead()); // Tear down clientA.cleanup(); clientB.cleanup(); }