Search in sources :

Example 1 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class CleanupOperationTest method testCleanupFailsMidCommit.

@Test
public void testCleanupFailsMidCommit() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=(13|14|15).+move" }));
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
    forceChecksumStatusOperationOptions.setForceChecksum(true);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setStatusOptions(forceChecksumStatusOperationOptions);
    options.setRemoveOldVersions(true);
    options.setMinKeepSeconds(0);
    options.setMinSecondsBetweenCleanups(40000000);
    options.setForce(true);
    File repoDir = testConnection.getPath();
    File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
    File repoActionsDir = new File(testConnection.getPath() + "/actions");
    File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
    File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
    File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");
    // Run
    clientA.createNewFile("A-file1", 5 * 1024);
    clientA.up();
    for (int i = 0; i < 5; i++) {
        clientA.changeFile("A-file1");
        clientA.upWithForceChecksum();
    }
    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Run cleanup, fails mid-move!
    boolean operationFailed = false;
    try {
        clientA.cleanup(options);
    } catch (Exception e) {
        // That is supposed to happen!
        operationFailed = true;
        e.printStackTrace();
    }
    assertTrue(operationFailed);
    assertEquals(1, repoTransactionsDir.listFiles().length);
    assertEquals(0, repoTemporaryDir.listFiles().length);
    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Retry
    clientA.cleanup(options);
    assertEquals(1, repoDatabasesDir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    assertEquals(1, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals(0, repoDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("transaction-");
        }
    }).length);
    assertEquals(0, repoDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("temp-");
        }
    }).length);
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Tear down
    clientA.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 2 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_2.

@Test
public void testIssue58_2() throws Exception {
    /*
		 * This is the attempt to reproduce issue #58 https://github.com/syncany/syncany/issues/58
		 */
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(true);
    options.setMinSecondsBetweenCleanups(0);
    options.setMaxDatabaseFiles(7);
    StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
    statusOptionsForceChecksum.setForceChecksum(true);
    UpOperationOptions upOperationOptionsWithCleanupForce = new UpOperationOptions();
    upOperationOptionsWithCleanupForce.setStatusOptions(statusOptionsForceChecksum);
    upOperationOptionsWithCleanupForce.setForceUploadEnabled(true);
    // Run preparations
    clientA.down();
    clientA.createNewFile("A-file.jpg");
    // (A1)
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A2)
    clientA.up(upOperationOptionsWithCleanupForce);
    clientB.down();
    clientB.changeFile("A-file.jpg");
    // (A2,B1)
    clientB.up(upOperationOptionsWithCleanupForce);
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A3,B1)
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A4,B1)
    clientA.up(upOperationOptionsWithCleanupForce);
    clientB.down();
    clientB.changeFile("A-file.jpg");
    // (A4,B2) + (A4,B3) [PURGE]
    clientB.up(upOperationOptionsWithCleanupForce);
    clientB.cleanup(options);
    clientC.down();
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A5,B3) + (A6,B3) [PURGE]
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.cleanup(options);
    clientB.down();
    clientB.changeFile("A-file.jpg");
    // (A6,B4) + (A6,B5) [PURGE]
    clientB.up(upOperationOptionsWithCleanupForce);
    clientB.cleanup(options);
    /*
		 * For some reason, this chunk checksum in the following commit is the reason for the exception. So we record it here to see where it vanishes
		 * from the databases.
		 */
    clientA.down();
    clientA.changeFile("A-file.jpg");
    String fileAndChunkChecksumThatRaisesException = StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-file.jpg")));
    System.out.println("Chunk/File checksum that raises the issue: " + fileAndChunkChecksumThatRaisesException);
    clientA.createNewFile("ADDED_IN_DBV_A7_B5");
    // (A7,B5) + (A8,B5) [PURGE]
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.cleanup(options);
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionA));
    clientB.down();
    clientB.changeFile("A-file.jpg");
    // (A8,B6) + (A8,B7) [PURGE]
    clientB.up(upOperationOptionsWithCleanupForce);
    clientB.cleanup(options);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionB));
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A9,B7) + (A10,B7) [PURGE]
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.cleanup(options);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionA));
    clientB.down();
    clientB.changeFile("A-file.jpg");
    // (A10,B8) + (A10,B9) [PURGE]
    clientB.up(upOperationOptionsWithCleanupForce);
    clientB.cleanup(options);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionB));
    clientB.down();
    clientB.changeFile("A-file.jpg");
    // (A10,B10) + (A10,B11) [PURGE]
    clientB.up(upOperationOptionsWithCleanupForce);
    clientB.cleanup(options);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionB));
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A11,B11) + (A12,B11) [PURGE]
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.cleanup(options);
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A13,B11) + (A14,B11) [PURGE]
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.cleanup(options);
    clientB.down();
    clientB.changeFile("A-file.jpg");
    // (A14,B12) + (A14,B13) [PURGE]
    clientB.up(upOperationOptionsWithCleanupForce);
    clientB.cleanup(options);
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A15,B13) + (A16,B13) [PURGE]
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.cleanup(options);
    clientA.down();
    clientA.changeFile("A-file.jpg");
    // (A17,B13) + (A18,B13) [PURGE]
    clientA.up(upOperationOptionsWithCleanupForce);
    clientA.cleanup(options);
    // Sync them up
    clientA.down();
    clientB.down();
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Run
    // <<< Here is/was the issue: Client C failed when downloading
    clientC.down();
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) Test(org.junit.Test)

Example 3 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_4.

@Test
public void testIssue58_4() throws Exception {
    // Test for https://github.com/syncany/syncany/issues/58#issuecomment-43472118
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
    cleanupOptionsKeep1.setRemoveOldVersions(true);
    StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
    statusOptionsForceChecksum.setForceChecksum(true);
    UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
    upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);
    UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
    upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);
    clientB.createNewFile("fileB");
    clientB.up(upNoCleanupForceChecksum);
    clientA.down();
    TestFileUtil.copyFile(clientB.getLocalFile("fileB"), clientA.getLocalFile("fileBcopy"));
    clientA.up(upNoCleanupForceChecksum);
    for (int i = 0; i < 30; i++) {
        clientB.down();
        clientB.changeFile("fileB");
        clientB.up(upNoCleanupForceChecksum);
    }
    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "1_before_cleanup"));
    CleanupOperationOptions cleanupMergeAndRemoveOldFiles = new CleanupOperationOptions();
    cleanupMergeAndRemoveOldFiles.setRemoveOldVersions(true);
    clientB.cleanup(cleanupMergeAndRemoveOldFiles);
    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_2_after_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "2_after_cleanup"));
    // <<< "Cannot determine file content for checksum X"
    clientC.down();
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
    FileUtils.deleteDirectory(new File(testConnection.getPath() + "_1_before_cleanup"));
    FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "1_before_cleanup"));
    FileUtils.deleteDirectory(new File(testConnection.getPath() + "_2_after_cleanup"));
    FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "2_after_cleanup"));
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 4 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class StatusCommand method parseOptions.

@Override
public StatusOperationOptions parseOptions(String[] operationArgs) throws Exception {
    StatusOperationOptions operationOptions = new StatusOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<Void> optionForceChecksum = parser.acceptsAll(asList("f", "force-checksum"));
    OptionSpec<Void> optionNoDeleteUpload = parser.acceptsAll(asList("D", "no-delete"));
    OptionSet options = parser.parse(operationArgs);
    // --force-checksum
    operationOptions.setForceChecksum(options.has(optionForceChecksum));
    // -D, --no-delete
    operationOptions.setDelete(!options.has(optionNoDeleteUpload));
    return operationOptions;
}
Also used : OptionSet(joptsimple.OptionSet) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) OptionParser(joptsimple.OptionParser)

Example 5 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class StatusCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    StatusOperationOptions operationOptions = parseOptions(operationArgs);
    StatusOperationResult operationResult = new StatusOperation(config, operationOptions).execute();
    printResults(operationResult);
    return 0;
}
Also used : StatusOperation(org.syncany.operations.status.StatusOperation) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) StatusOperationResult(org.syncany.operations.status.StatusOperationResult)

Aggregations

StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)15 Test (org.junit.Test)12 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)10 TestClient (org.syncany.tests.util.TestClient)10 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)8 File (java.io.File)6 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)6 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)4 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)3 Config (org.syncany.config.Config)2 ChangeSet (org.syncany.operations.ChangeSet)2 StatusOperation (org.syncany.operations.status.StatusOperation)2 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)2 UpOperation (org.syncany.operations.up.UpOperation)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 FilenameFilter (java.io.FilenameFilter)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 DaemonConfigTO (org.syncany.config.to.DaemonConfigTO)1 FileVersion (org.syncany.database.FileVersion)1