Search in sources :

Example 1 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class MixedUpDownScenarioTest method testMixedScenario1.

@Test
@Ignore
public void testMixedScenario1() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    // Run 
    clientC.createNewFile("C1");
    clientC.up();
    clientC.createNewFile("C2");
    clientC.up();
    clientC.createNewFile("C3");
    clientC.up();
    // NO CONFLICT
    clientB.down();
    assertFileListEquals("Client B and C should be on the same versions.", clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    // up without down! Evil!
    clientC.createNewFile("C4");
    clientC.up();
    // NO CONFLICT
    clientA.down();
    assertFileListEquals("Client A and C should be on the same versions.", clientA.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    assertEquals("Client A should have C4, client B should not", clientA.getLocalFilesExcludeLockedAndNoRead().size() - 1, clientB.getLocalFilesExcludeLockedAndNoRead().size());
    clientB.createNewFile("B1,C3");
    clientB.up();
    clientA.createNewFile("A1,C4");
    clientA.up();
    clientA.createNewFile("A2,C4");
    clientA.up();
    clientA.createNewFile("A3,C4");
    clientA.up();
    // CONFLICT 1
    clientB.down();
    fail("Add some asserts");
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // CONFLICT 2
    clientA.down();
    // CONFLICT 3
    clientC.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    clientA.createNewFile("A4,C4");
    clientA.up();
    clientA.createNewFile("A5,C4");
    clientA.up();
    clientC.createNewFile("A3,C5");
    clientC.up();
    clientC.createNewFile("A3,C6");
    clientC.up();
    clientC.createNewFile("A3,C7");
    clientC.up();
    clientB.createNewFile("A3,B2,C4");
    clientB.up();
    clientB.createNewFile("A3,B3,C4");
    clientB.up();
    clientB.createNewFile("A3,B4,C4");
    clientB.up();
    clientA.createNewFile("A6,C4");
    clientA.up();
    clientB.createNewFile("A3,B5,C4");
    clientB.up();
    clientC.createNewFile("A3,C8");
    clientC.up();
    // CONFLICT 4
    clientB.down();
    // CONFLICT 5
    clientA.down();
    // CONFLICT 6
    clientC.down();
    clientA.up();
    clientA.down();
    clientB.up();
    clientB.down();
    clientC.up();
    clientC.down();
    clientC.up();
    clientB.up();
    // CONFLICT 7
    clientC.down();
    // CONFLICT 8
    clientB.down();
    // CONFLICT 9
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    assertEquals("File list count does not match.", 19, clientA.getLocalFilesExcludeLockedAndNoRead().size());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class RenameDeleteScenarioTest method testDeleteFileThatHasAlreadyMoved.

@Test
public void testDeleteFileThatHasAlreadyMoved() throws Exception {
    // Scenario: A deletes a file that B has already moved
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // A new/up
    clientA.createNewFile("A-original");
    clientA.up();
    // B down/move/up
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // A moves, and up
    clientA.deleteFile("A-original");
    clientA.up();
    // B deletes, then down; this should not fail or throw exceptions
    clientB.moveFile("A-original", "B-moved");
    clientB.down();
    assertFalse("File A-orginal should not be recreated.", clientB.getLocalFile("A-original").exists());
    // Sync them
    clientB.sync();
    clientA.sync();
    assertFalse("File A-orginal should not be recreated.", clientA.getLocalFile("A-original").exists());
    assertFalse("File A-orginal should not be recreated.", clientB.getLocalFile("A-original").exists());
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 3 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class RenameFileWithDiffModifiedDateScenarioTest method testChangedModifiedDate.

@Test
public void testChangedModifiedDate() throws Exception {
    // Setup 
    TransferSettings 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.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    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();
    TestSqlDatabase clientDatabaseB = clientB.loadLocalDatabase();
    PartialFileHistory file1Orig = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-moved.jpg");
    PartialFileHistory file1WithDiffLastModDate = clientDatabaseB.getFileHistoryWithFileVersions("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.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) TestSqlDatabase(org.syncany.tests.util.TestSqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 4 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class RenameNoDownloadMultiChunksScenarioTest method testRenameAndCheckIfMultiChunksAreDownloaded.

@Test
public void testRenameAndCheckIfMultiChunksAreDownloaded() throws Exception {
    // Setup 
    TransferSettings 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.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : DownOperationResult(org.syncany.operations.down.DownOperationResult) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 5 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class RestoreFileScenarioTest method testRestoreDeletedFileWithTargetFile.

@Test
public void testRestoreDeletedFileWithTargetFile() throws Exception {
    // Setup 
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    // A new/up
    clientA.createNewFile("A-original");
    clientA.upWithForceChecksum();
    String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
    assertNotNull(originalFileHistoryStr);
    FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
    // A "delete"
    File deletedFile = new File(tempDir, "A-original-DELETED");
    FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
    clientA.upWithForceChecksum();
    // A restore
    RestoreOperationOptions operationOptions = new RestoreOperationOptions();
    operationOptions.setFileHistoryId(originalFileHistoryId);
    operationOptions.setFileVersion(1);
    operationOptions.setRelativeTargetPath("restored-file");
    clientA.restore(operationOptions);
    assertTrue(clientA.getLocalFile("restored-file").exists());
    assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("restored-file"))));
    assertEquals(deletedFile.lastModified(), clientA.getLocalFile("restored-file").lastModified());
    assertEquals(deletedFile.length(), clientA.getLocalFile("restored-file").length());
    // Tear down
    clientA.deleteTestData();
    TestFileUtil.deleteDirectory(tempDir);
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Aggregations

TestClient (org.syncany.tests.util.TestClient)126 Test (org.junit.Test)122 TransferSettings (org.syncany.plugins.transfer.TransferSettings)65 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)53 File (java.io.File)50 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)31 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)28 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)23 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)14 FilenameFilter (java.io.FilenameFilter)11 StorageException (org.syncany.plugins.transfer.StorageException)11 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)10 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)10 DownOperationResult (org.syncany.operations.down.DownOperationResult)9 UpOperationResult (org.syncany.operations.up.UpOperationResult)8 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6 SqlDatabase (org.syncany.database.SqlDatabase)5 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)5 PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)5 PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)5