Search in sources :

Example 6 with StatusOperationResult

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

the class ChangedAttributesScenarioTest method testChangeAttributes.

@Test
public void testChangeAttributes() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run 
    clientA.createNewFile("file1.jpg");
    clientA.upWithForceChecksum();
    clientB.down();
    File bFile = clientB.getLocalFile("file1.jpg");
    Path bFilePath = Paths.get(bFile.getAbsolutePath());
    if (EnvironmentUtil.isWindows()) {
        Files.setAttribute(bFilePath, "dos:readonly", true);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        Files.setPosixFilePermissions(bFilePath, PosixFilePermissions.fromString("rwxrwxrwx"));
    }
    StatusOperationResult statusResult = clientB.status();
    assertNotNull(statusResult);
    ChangeSet changes = statusResult.getChangeSet();
    assertTrue("Status-Operation should return changes.", changes.hasChanges());
    UpOperationResult upResult = clientB.up();
    StatusOperationResult statusResultFromUp = upResult.getStatusResult();
    // Test 1: Check result sets for inconsistencies
    assertTrue("Status should return changes.", statusResultFromUp.getChangeSet().hasChanges());
    assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());
    // Test 2: Check database for inconsistencies
    SqlDatabase database = clientB.loadLocalDatabase();
    assertEquals("File should be uploaded.", 1, database.getFileList("file1.jpg", null, false, false, false, null).size());
    assertEquals("There should be a new database version, because file should not have been added.", 2, database.getLocalDatabaseBranch().size());
    // B down
    clientA.down();
    // Test 1: file1.jpg permissions
    File aFile = clientA.getLocalFile("file1.jpg");
    Path aFilePath = Paths.get(aFile.getAbsolutePath());
    if (EnvironmentUtil.isWindows()) {
        Object readOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
        assertTrue("Read-only should be true.", (Boolean) readOnlyAttribute);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(aFilePath);
        assertEquals("Should be rwxrwxrwx.", "rwxrwxrwx", PosixFilePermissions.toString(posixFilePermissions));
    }
    // Test 2: The rest
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) ChangeSet(org.syncany.operations.ChangeSet) TestClient(org.syncany.tests.util.TestClient) SqlDatabase(org.syncany.database.SqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) ChangeSet(org.syncany.operations.ChangeSet) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 7 with StatusOperationResult

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

the class DirtyDatabaseScenarioTest method testDirtyCleanupDirty.

@Test
public void testDirtyCleanupDirty() 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);
    TestClient clientD = new TestClient("D", testConnection);
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
    upOptionsForceEnabled.setStatusOptions(statusOptions);
    upOptionsForceEnabled.setForceUploadEnabled(true);
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);
    cleanupOptions.setForce(true);
    // Run
    //// 1. CREATE FIRST DIRTY VERSION
    clientA.createNewFile("A-file1.jpg", 50 * 1024);
    // (A1)
    clientA.up(upOptionsForceEnabled);
    clientB.down();
    clientB.changeFile("A-file1.jpg");
    // (A1,B1)
    clientB.up(upOptionsForceEnabled);
    clientA.down();
    // conflict (winner)
    clientA.changeFile("A-file1.jpg");
    // (A2,B1)
    clientA.up(upOptionsForceEnabled);
    // conflict (loser)
    clientB.changeFile("A-file1.jpg");
    clientB.up(upOptionsForceEnabled);
    // don't care about the conflict, just continue
    clientA.createNewFolder("new folder at A");
    // (A3,B1)
    clientA.up(upOptionsForceEnabled);
    // don't care about the conflict, just continue
    clientB.createNewFolder("new folder at B");
    clientB.up(upOptionsForceEnabled);
    // resolve conflict (wins, no DIRTY)
    clientA.down();
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    // resolve conflict (loses, creates DIRTY version)
    clientB.down();
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
    assertEquals("(A1,B2)\n(A1,B3)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status='DIRTY' order by id", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionB));
    StatusOperationResult statusResultBAfterDirty = clientB.status();
    assertNotNull(statusResultBAfterDirty);
    ChangeSet changeSetBAfterDirty = statusResultBAfterDirty.getChangeSet();
    assertEquals(2, changeSetBAfterDirty.getNewFiles().size());
    TestAssertUtil.assertConflictingFileExists("A-file1.jpg", clientB.getLocalFiles());
    // (A3,B2)
    clientB.up(upOptionsForceEnabled);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
    // (A1), (A1,B1), (A2,B1), (A3,B1)
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionA));
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));
    //// 2. NOW THAT CLIENT B RESOLVED IT, A GETS DIRTY
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty1");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty2");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty3");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty4");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty5");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty6");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty7");
    clientA.up(upOptionsForceEnabled);
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    clientA.down();
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("7", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionA));
    // Does nothing; A versions lose against (A3,B2) // same as above!
    clientB.down();
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));
    //// 3. NEW CLIENT JOINS
    clientC.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientB.getDatabaseFile(), clientC.getDatabaseFile());
    //// 4. FORCE MERGE DATABASES ON CLIENT A
    clientA.deleteFile("dirty1");
    clientA.deleteFile("dirty2");
    // upload DIRTY version
    clientA.up(upOptionsForceEnabled);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
    clientA.createNewFile("A-file2.jpg");
    // For every X up's call 'cleanup' ("X" is larger than the max. length of file versions in a history)
    int cleanupEveryXUps = 7;
    for (int i = 1; i <= 21; i++) {
        clientA.changeFile("A-file2.jpg");
        clientA.up(upOptionsForceEnabled);
        if (i % cleanupEveryXUps == 0) {
            clientA.cleanup(cleanupOptions);
        }
    }
    clientA.cleanup(cleanupOptions);
    clientB.down();
    clientC.down();
    clientD.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientD.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
    clientD.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) ChangeSet(org.syncany.operations.ChangeSet) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) Test(org.junit.Test)

Example 8 with StatusOperationResult

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

the class FileLockedScenarioTest method runUpAndTestForConsistentDatabase.

private void runUpAndTestForConsistentDatabase(TransferSettings connection, TestClient client) throws Exception {
    UpOperationResult upResult = client.up();
    StatusOperationResult statusResult = upResult.getStatusResult();
    // Test 1: Check result sets for inconsistencies
    assertTrue("Status command expected to return changes.", statusResult.getChangeSet().hasChanges());
    assertTrue("File should be uploaded while it is read-only.", upResult.getChangeSet().hasChanges());
    // Test 2: Check database for inconsistencies
    SqlDatabase database = client.loadLocalDatabase();
    assertNotNull("There should be a new database version, because files should have been added.", database.getLastDatabaseVersionHeader());
    // Test 3: Check file system for inconsistencies
    File repoPath = ((LocalTransferSettings) connection).getPath();
    assertEquals("Repository should contain any files.", 5, repoPath.list().length);
}
Also used : 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 9 with StatusOperationResult

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

the class SymlinkSyncScenarioTest method testSymlinkOneUpOneDown.

@Test
public void testSymlinkOneUpOneDown() throws Exception {
    if (!EnvironmentUtil.symlinksSupported()) {
        // Skip test for Windows, no symlinks there!
        return;
    }
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run
    File symlinkFile = clientA.getLocalFile("symlink-name");
    FileUtil.createSymlink("/etc/hosts", symlinkFile);
    assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());
    UpOperationResult upResult = clientA.up();
    StatusOperationResult statusResult = upResult.getStatusResult();
    // Test 1: Check result sets for inconsistencies
    assertTrue("Status should return changes.", statusResult.getChangeSet().hasChanges());
    assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());
    // Test 2: Check database for inconsistencies
    SqlDatabase database = clientA.loadLocalDatabase();
    assertEquals("File should be uploaded.", 1, database.getFileList("symlink-name", null, false, false, false, null).size());
    assertNotNull("There should be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());
    // Test 3: Check file system for inconsistencies
    File repoPath = new File(((LocalTransferSettings) testConnection).getPath() + "/databases");
    String[] repoFileList = repoPath.list(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    });
    assertEquals("Repository should contain only ONE database file, not multichunks.", 1, repoFileList.length);
    // B down
    clientB.down();
    assertEquals("Local folder should contain one file (link!)", 1, clientB.getLocalFilesExcludeLockedAndNoRead().size());
    File localSymlinkFile = clientB.getLocalFile("symlink-name");
    assertTrue("Local symlink file should exist.", localSymlinkFile.exists());
    assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
    assertEquals("Local symlink file should point to actual target.", "/etc/hosts", FileUtil.readSymlinkTarget(localSymlinkFile));
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) SqlDatabase(org.syncany.database.SqlDatabase) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) UpOperationResult(org.syncany.operations.up.UpOperationResult) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) Test(org.junit.Test)

Aggregations

StatusOperationResult (org.syncany.operations.status.StatusOperationResult)9 File (java.io.File)5 SqlDatabase (org.syncany.database.SqlDatabase)5 UpOperationResult (org.syncany.operations.up.UpOperationResult)5 Test (org.junit.Test)4 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)4 TransferSettings (org.syncany.plugins.transfer.TransferSettings)4 TestClient (org.syncany.tests.util.TestClient)4 FilenameFilter (java.io.FilenameFilter)3 ChangeSet (org.syncany.operations.ChangeSet)3 StatusOperation (org.syncany.operations.status.StatusOperation)3 RandomAccessFile (java.io.RandomAccessFile)2 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)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 Path (java.nio.file.Path)1 Random (java.util.Random)1 Set (java.util.Set)1