Search in sources :

Example 1 with UpOperationResult

use of org.syncany.operations.up.UpOperationResult in project syncany by syncany.

the class FileLockedScenarioTest method runUpAndTestForEmptyDatabase.

private void runUpAndTestForEmptyDatabase(TransferSettings connection, TestClient client) throws Exception {
    UpOperationResult upResult = client.up();
    StatusOperationResult statusResult = upResult.getStatusResult();
    // Test 1: Check result sets for inconsistencies
    assertFalse("Status command expected to return NO changes.", statusResult.getChangeSet().hasChanges());
    assertFalse("File should NOT be uploaded while it is locked.", upResult.getChangeSet().hasChanges());
    // Test 2: Check database for inconsistencies
    SqlDatabase database = client.loadLocalDatabase();
    assertEquals("File should NOT be uploaded while it is locked.", 0, database.getFileList("large-test-file", null, false, false, false, null).size());
    assertNull("There should NOT be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());
    // Test 3: Check file system for inconsistencies
    File repoPath = ((LocalTransferSettings) connection).getPath();
    String[] repoFileList = repoPath.list(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    });
    assertEquals("Repository should NOT contain any files.", 0, repoFileList.length);
}
Also used : FilenameFilter(java.io.FilenameFilter) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) SqlDatabase(org.syncany.database.SqlDatabase) RandomAccessFile(java.io.RandomAccessFile) LockFile(org.syncany.tests.integration.scenarios.framework.LockFile) File(java.io.File) UnlockFile(org.syncany.tests.integration.scenarios.framework.UnlockFile) UpOperationResult(org.syncany.operations.up.UpOperationResult) StatusOperationResult(org.syncany.operations.status.StatusOperationResult)

Example 2 with UpOperationResult

use of org.syncany.operations.up.UpOperationResult in project syncany by syncany.

the class CleanupMergeDatabaseFilesScenarioTest method testIssue266_EmptyDatabaseAfterCleanup.

@Test
public void testIssue266_EmptyDatabaseAfterCleanup() throws Exception {
    // Test for https://github.com/syncany/syncany/issues/266#issuecomment-64472059
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    TestClient clientD = new TestClient("D", testConnection);
    TestClient clientE = new TestClient("E", testConnection);
    CleanupOperationOptions cleanupOptionsKeepOneForce = new CleanupOperationOptions();
    cleanupOptionsKeepOneForce.setRemoveOldVersions(true);
    cleanupOptionsKeepOneForce.setForce(true);
    cleanupOptionsKeepOneForce.setMinKeepSeconds(0);
    // Create a couple of files, then delete them and do a cleanup
    clientA.createNewFile("fileA");
    clientA.upWithForceChecksum();
    clientB.down();
    clientB.createNewFile("fileB");
    clientB.upWithForceChecksum();
    clientC.down();
    clientC.createNewFile("fileC");
    clientC.upWithForceChecksum();
    clientD.down();
    clientD.deleteFile("fileA");
    clientD.deleteFile("fileB");
    clientD.deleteFile("fileC");
    clientD.upWithForceChecksum();
    clientD.cleanup(cleanupOptionsKeepOneForce);
    java.sql.Connection databaseConnectionD = DatabaseConnectionFactory.createConnection(clientD.getDatabaseFile(), false);
    assertEquals("A,2\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionD));
    assertEquals("", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionD));
    // Now the remote databases are completely empty (no files, no histories, no database versions!)
    /* Case 1: 
		 * 
		 * Client A now knows "fileA" and must react on the cleanup by client D.
		 * The remote databases do NOT contain any trace of "fileA" anymore, so
		 * client A has to detect the deletion by comparing the local database with 
		 * the winner database. "fileA" should be deleted after the next 'down'.
		 */
    // Existing client  << This created a NullPointerException in #266
    clientA.down();
    assertFalse("File 'fileA' should have been deleted.", clientA.getLocalFile("fileA").exists());
    assertFalse("File 'fileB' should not have been created.", clientA.getLocalFile("fileB").exists());
    assertFalse("File 'fileC' should not have been created.", clientA.getLocalFile("fileC").exists());
    assertConflictingFileNotExists("fileA", clientA.getLocalFiles());
    assertConflictingFileNotExists("fileB", clientA.getLocalFiles());
    assertConflictingFileNotExists("fileC", clientA.getLocalFiles());
    assertSqlDatabaseEquals(clientD.getDatabaseFile(), clientA.getDatabaseFile());
    assertFileListEquals(clientD.getLocalFiles(), clientA.getLocalFiles());
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    assertEquals("A,2\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionA));
    /*
		 * Case 2:
		 * 
		 * Client E is a completely new client. It's the first time downloading anything, so
		 * it has no local database, and (in this case), the remote/winner database is completely
		 * empty!
		 */
    // Empty/new client << This created a NullPointerException 
    clientE.down();
    assertFalse("File 'fileA' should not have been created.", clientE.getLocalFile("fileA").exists());
    assertFalse("File 'fileB' should not have been created.", clientE.getLocalFile("fileB").exists());
    assertFalse("File 'fileC' should not have been created.", clientE.getLocalFile("fileC").exists());
    assertConflictingFileNotExists("fileA", clientA.getLocalFiles());
    assertConflictingFileNotExists("fileB", clientA.getLocalFiles());
    assertConflictingFileNotExists("fileC", clientA.getLocalFiles());
    assertSqlDatabaseEquals(clientD.getDatabaseFile(), clientE.getDatabaseFile());
    assertFileListEquals(clientD.getLocalFiles(), clientE.getLocalFiles());
    java.sql.Connection databaseConnectionE = DatabaseConnectionFactory.createConnection(clientE.getDatabaseFile(), false);
    assertEquals("A,2\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionE));
    // After a successful down, create a new database version (continue numbering!)
    clientA.createNewFile("fileA");
    UpOperationResult upResult = clientA.upWithForceChecksum();
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResult.getResultCode());
    assertEquals("(A3,B2,C2,D2)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionA));
    // Check if E applies everything correctly and check E's numbering
    clientE.down();
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientE.getDatabaseFile());
    assertFileListEquals(clientA.getLocalFiles(), clientE.getLocalFiles());
    assertEquals("A,2\nA,3\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionE));
    clientE.changeFile("fileA");
    upResult = clientE.upWithForceChecksum();
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResult.getResultCode());
    assertEquals("(A3,B2,C2,D2)\n(A3,B2,C2,D2,E1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionE));
    // And with D ...
    clientD.down();
    assertSqlDatabaseEquals(clientE.getDatabaseFile(), clientD.getDatabaseFile());
    assertFileListEquals(clientE.getLocalFiles(), clientD.getLocalFiles());
    assertEquals("A,2\nA,3\nB,2\nC,2\nD,2\nE,1", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionD));
    assertEquals("(A3,B2,C2,D2)\n(A3,B2,C2,D2,E1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionD));
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
    clientD.deleteTestData();
    clientE.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 3 with UpOperationResult

use of org.syncany.operations.up.UpOperationResult in project syncany by syncany.

the class CleanupInterruptedTest method testUnreliableCleanup_failBlocksOtherClients.

@Test
public void testUnreliableCleanup_failBlocksOtherClients() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
    "rel=(12|13|14).+upload.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    clientA.createNewFile("file");
    clientA.up();
    clientA.changeFile("file");
    clientA.upWithForceChecksum();
    clientB.down();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinKeepSeconds(0);
    boolean cleanupFailed = false;
    try {
        clientA.cleanup(cleanupOptions);
    } catch (StorageException e) {
        cleanupFailed = true;
    }
    assertTrue(cleanupFailed);
    // Pretend time has passed by deleting the action file:
    TestFileUtil.deleteFile(new File(testConnection.getPath(), "/actions/").listFiles()[0]);
    CleanupOperationResult cleanupResult = clientB.cleanup(cleanupOptions);
    assertEquals(CleanupResultCode.NOK_REPO_BLOCKED, cleanupResult.getResultCode());
    clientB.createNewFile("file2");
    UpOperationResult upResult = clientB.up();
    assertEquals(UpResultCode.NOK_REPO_BLOCKED, upResult.getResultCode());
    clientA.deleteTestData();
    clientB.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) StorageException(org.syncany.plugins.transfer.StorageException) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionRemoteFile(org.syncany.plugins.transfer.files.ActionRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 4 with UpOperationResult

use of org.syncany.operations.up.UpOperationResult in project syncany by syncany.

the class UpCommand method execute.

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

Example 5 with UpOperationResult

use of org.syncany.operations.up.UpOperationResult in project syncany by syncany.

the class WatchOperation method runSync.

/**
	 * Runs one iteration of the main synchronization loop, containing a {@link DownOperation},
	 * an {@link UpOperation} and (if required), a {@link CleanupOperation}.
	 */
private void runSync() throws Exception {
    if (!syncRunning.get()) {
        syncRunning.set(true);
        syncRequested.set(false);
        logger.log(Level.INFO, "RUNNING SYNC ...");
        fireStartEvent();
        try {
            boolean notifyChanges = false;
            // Run down
            DownOperationResult downResult = new DownOperation(config, options.getDownOptions()).execute();
            if (downResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
            // TODO [low] Do something?
            }
            // Run up
            UpOperationResult upOperationResult = new UpOperation(config, options.getUpOptions()).execute();
            if (upOperationResult.getResultCode() == UpResultCode.OK_CHANGES_UPLOADED && upOperationResult.getChangeSet().hasChanges()) {
                upCount.incrementAndGet();
                notifyChanges = true;
            }
            CleanupOperationResult cleanupOperationResult = new CleanupOperation(config, options.getCleanupOptions()).execute();
            if (cleanupOperationResult.getResultCode() == CleanupResultCode.OK) {
                notifyChanges = true;
            }
            // Fire change event if up and/or cleanup
            if (notifyChanges) {
                notifyChanges();
            }
        } finally {
            logger.log(Level.INFO, "SYNC DONE.");
            syncRunning.set(false);
            fireEndEvent();
        }
    } else {
        // Can't do a log message here, because this bit is called thousand
        // of times when file system events occur.
        syncRequested.set(true);
    }
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) DownOperationResult(org.syncany.operations.down.DownOperationResult) DownOperation(org.syncany.operations.down.DownOperation) CleanupOperation(org.syncany.operations.cleanup.CleanupOperation) UpOperationResult(org.syncany.operations.up.UpOperationResult)

Aggregations

UpOperationResult (org.syncany.operations.up.UpOperationResult)13 File (java.io.File)9 Test (org.junit.Test)8 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)8 TestClient (org.syncany.tests.util.TestClient)8 SqlDatabase (org.syncany.database.SqlDatabase)5 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)5 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 TransferSettings (org.syncany.plugins.transfer.TransferSettings)4 FilenameFilter (java.io.FilenameFilter)3 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)3 UpOperation (org.syncany.operations.up.UpOperation)3 RandomAccessFile (java.io.RandomAccessFile)2 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)2 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)2 LockFile (org.syncany.tests.integration.scenarios.framework.LockFile)2 UnlockFile (org.syncany.tests.integration.scenarios.framework.UnlockFile)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1