Search in sources :

Example 31 with TestClient

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

the class SingleFolderNoConflictsScenarioTest method testFolderEmptyNewNoConflicts.

@Test
public void testFolderEmptyNewNoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create files and upload
    clientA.createNewFolder("folder");
    clientA.up();
    clientB.down();
    assertFileEquals(clientA.getLocalFile("folder"), clientB.getLocalFile("folder"));
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 32 with TestClient

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

the class SingleFolderNoConflictsScenarioTest method testFolderEmptyMoveNoConflicts.

@Test
public void testFolderEmptyMoveNoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create files and upload
    clientA.createNewFolder("folder");
    clientA.up();
    clientB.down();
    clientB.moveFile("folder", "moved");
    clientB.up();
    clientA.down();
    assertFileEquals(clientA.getLocalFile("moved"), clientB.getLocalFile("moved"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 33 with TestClient

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

the class Issue288ScenarioTest method testIssue288.

@Test
public void testIssue288() throws Exception {
    /*
		 * This tests issue #288, an issue in which a file with duplicate chunks are created
		 * incorrectly, because the cleanup throws away too many entries in the filecontent_chunks
		 * database table. 
		 * 
		 * The test first creates a file with duplicate chunks, then syncs this file, and then 
		 * moves this file on both clients -- that forces the other client to recreate the file 
		 * from scratch.
		 */
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
    cleanupOptionsKeepOne.setForce(true);
    // Create file content with two duplicate chunks
    // The file has 4 chunks (4 * 512 bytes), the middle chunks are identical
    // 1 MB
    byte[] fileContentA = new byte[2 * 1024 * 1024];
    for (int i = 0; i < 512 * 1024; i++) {
        // First chunk
        fileContentA[i] = (byte) i;
    }
    for (int i = 512 * 1024; i < 1536 * 1024; i++) {
        // Two identical middle chunks
        fileContentA[i] = 99;
    }
    for (int i = 1536 * 1024; i < 2 * 1024 * 1024; i++) {
        // Last chunk
        fileContentA[i] = (byte) (i + i);
    }
    FileUtils.writeByteArrayToFile(clientA.getLocalFile("fileA"), fileContentA);
    clientA.upWithForceChecksum();
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from filecontent_chunk", databaseConnectionA));
    // Sync file to client B
    clientB.down();
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionB));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from filecontent_chunk", databaseConnectionB));
    // Move file, sync again and perform cleanup (wipe everything but one file version)
    clientA.moveFile("fileA", "fileA-moved");
    clientA.upWithForceChecksum();
    clientA.cleanup(cleanupOptionsKeepOne);
    // Delete file locally and sync down
    clientB.deleteFile("fileA");
    // <<<< This throws an exception!
    clientB.down();
    // Tear down
    clientB.deleteTestData();
    clientA.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) Test(org.junit.Test)

Example 34 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 35 with TestClient

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

the class Issue429ScenarioTest method testSpecificQueue.

@Ignore
public void testSpecificQueue() throws Exception {
    String[] commands = new String[] { "A5", "B5", "B0", "B0", "A7", "A3", "B6", "B1", "A7", "A6", "A7", "B5", "A1", "A0", "B6", "A5", "B0", "B6", "A7", "A0", "B7", "A5", "B1", "B7", "A6", "B7", "A0", "A3", "B4", "B7", "A2", "A7", "A4", "B1", "B4", "A3", "B0", "A0", "A4", "A6", "B3", "B3", "B2", "A1", "B1", "B3", "A1", "A7", "B7", "B7", "A1", "B4", "A4", "A4", "A1", "B4", "A6", "B2", "B5", "B7", "A5", "B2", "B2", "B3", "B1", "B5", "B3", "B1", "B3", "B2", "B4" };
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    for (String command : commands) {
        int choice = Integer.parseInt(command.substring(1));
        if (command.contains("A")) {
            performAction(clientA, choice);
        } else {
            performAction(clientB, choice);
        }
    }
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) 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