Search in sources :

Example 6 with TestClient

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

the class RestoreFileScenarioTest method testRestoreDeletedFile.

@Test
public void testRestoreDeletedFile() 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);
    clientA.restore(operationOptions);
    assertTrue(clientA.getLocalFile("A-original (restored version 1)").exists());
    assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-original (restored version 1)"))));
    assertEquals(deletedFile.lastModified(), clientA.getLocalFile("A-original (restored version 1)").lastModified());
    assertEquals(deletedFile.length(), clientA.getLocalFile("A-original (restored version 1)").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)

Example 7 with TestClient

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

the class RestoreFileScenarioTest method testRestoreDeletedWithSubfolders.

@Test
public void testRestoreDeletedWithSubfolders() 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.createNewFolder("folder/subfolder");
    clientA.createNewFile("folder/subfolder/A-original");
    clientA.upWithForceChecksum();
    String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion where path='folder/subfolder/A-original'", databaseConnectionA);
    assertNotNull(originalFileHistoryStr);
    FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
    // A "delete"
    FileUtils.deleteDirectory(clientA.getLocalFile("folder"));
    clientA.upWithForceChecksum();
    assertFalse(clientA.getLocalFile("folder").exists());
    // A restore
    RestoreOperationOptions operationOptions = new RestoreOperationOptions();
    operationOptions.setFileHistoryId(originalFileHistoryId);
    operationOptions.setFileVersion(1);
    clientA.restore(operationOptions);
    assertTrue(clientA.getLocalFile("folder/subfolder").exists());
    assertTrue(clientA.getLocalFile("folder/subfolder/A-original (restored version 1)").exists());
    // 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)

Example 8 with TestClient

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

the class Issue316ScenarioTest method testIssue316CleanupThenDeleteFileButLocalFileChanged.

@Test
public void testIssue316CleanupThenDeleteFileButLocalFileChanged() throws Exception {
    /*
		 * Same test as above, but local file has changed at client B.
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=(5|6|7) .+download.+multichunk" }));
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
    cleanupOptionsKeepOne.setMaxDatabaseFiles(1);
    cleanupOptionsKeepOne.setForce(true);
    clientA.createNewFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    clientB.down();
    assertTrue(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    // <<<<<<<<< Different from above test
    clientB.changeFile("Kazam_screencast_00010.mp4");
    clientA.createNewFile("SomeFileTOIncreaseTheDatabaseFileCount");
    clientA.upWithForceChecksum();
    CleanupOperationResult cleanupResult = clientA.cleanup(cleanupOptionsKeepOne);
    assertEquals(CleanupResultCode.OK, cleanupResult.getResultCode());
    clientA.deleteFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    // First 'down' of client B after the cleanup. 
    // This fails AFTER the local database was wiped.
    boolean downFailedAtB = false;
    try {
        clientB.down();
    } catch (Exception e) {
        downFailedAtB = true;
    }
    assertTrue("Down operation should have failed.", downFailedAtB);
    // Second 'down' of client B; This should delete the file 'Kazam_screencast_00010.mp4',
    // because it matches the checksum of the 'DELETED' entry
    clientB.down();
    // <<<<<<<<< Different from above test 
    assertConflictingFileExists("Kazam_screencast_00010.mp4", clientB.getLocalFiles());
    assertFalse(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    // Tear down
    clientB.deleteTestData();
    clientA.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) Test(org.junit.Test)

Example 9 with TestClient

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

the class Issue374Pre1965DateScenarioTest method testIssue316CleanupThenDeleteFile.

@Test
public void testIssue316CleanupThenDeleteFile() throws Exception {
    /*
		 * This test simulates files with a timestamp before 1965 (unix time < 0).  
		 */
    // Setup 
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    clientA.createNewFile("pre1965.txt");
    Date dateBefore1965 = new SimpleDateFormat("dd-MM-yyyy").parse("31-12-1964");
    Files.setLastModifiedTime(clientA.getLocalFile("pre1965.txt").toPath(), FileTime.fromMillis(dateBefore1965.getTime()));
    clientA.upWithForceChecksum();
    // This was throwing an exception in FileSystemAction.setLastModified()
    clientB.down();
    // Tear down
    clientB.deleteTestData();
    clientA.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 10 with TestClient

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

the class Issue429ScenarioTest method testSameFileDifferentNameFuzzy.

@Ignore
public void testSameFileDifferentNameFuzzy() throws Exception {
    for (int seed = 0; seed < 1000; seed++) {
        LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
        TestClient clientA = new TestClient("A", testConnection);
        TestClient clientB = new TestClient("B", testConnection);
        Random randomA = new Random(2 * seed);
        Random randomB = new Random(2 * seed + 1);
        Queue<String> queue = new ConcurrentLinkedQueue<>();
        activeThread A = new activeThread(randomA, clientA, queue);
        activeThread B = new activeThread(randomB, clientB, queue);
        Thread AThread = new Thread(A, "A");
        Thread BThread = new Thread(B, "B");
        try {
            AThread.start();
            BThread.start();
            for (int i = 0; i < 50; i++) {
                TestClient clientC = new TestClient("C", testConnection);
                clientC.down();
                if (!AThread.isAlive() || !BThread.isAlive()) {
                    throw new RuntimeException("One of the threads died");
                }
                FileUtils.deleteDirectory(clientC.getLocalFile(""));
                Thread.sleep(2000);
            }
            AThread.interrupt();
            BThread.interrupt();
        } catch (Exception e) {
            logger.log(Level.INFO, "Queue:" + queue.toString());
            logger.log(Level.INFO, "Something went wrong at seed: " + seed);
            throw e;
        }
        clientA.deleteTestData();
        clientB.deleteTestData();
    }
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) Random(java.util.Random) TestClient(org.syncany.tests.util.TestClient) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Ignore(org.junit.Ignore)

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