Search in sources :

Example 36 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class ManySyncUpsAndOtherClientSyncDownScenarioTest method testManySyncUpsAndOtherClientSyncDownSameFileAddRemove.

@Test
public void testManySyncUpsAndOtherClientSyncDownSameFileAddRemove() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // TODO Test not finished
    // ROUND 1: many sync up (cleanups expected)
    String[] names = new String[] { "one", "two", "three", "four", "five" };
    int nameIndex = 0;
    for (int i = 1; i <= 20; i++) {
        String filename = names[nameIndex++ % names.length];
        if (clientA.getLocalFile(filename).exists()) {
            clientA.deleteFile(filename);
        } else {
            clientA.createNewFile(filename);
        }
        clientA.up();
    }
    // ROUND 2: sync down by B
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Test(org.junit.Test)

Example 37 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings 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)

Example 38 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class DoSameActionAtTwoClientsTest method testIssue76.

@Test
public void testIssue76() throws Exception {
    /*
		 * If two clients create the same file at the same time, different multichunks will contain the same chunks. This lead to issue 76.
		 */
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    UpOperationOptions upOperationOptionsWithForce = new UpOperationOptions();
    upOperationOptionsWithForce.setForceUploadEnabled(true);
    // Client A creates some files
    clientA.getLocalFile("sphinxbase-0.8").mkdirs();
    clientA.getLocalFile("sphinxbase-0.8/win32/sphinx_jsgf2fsg").mkdirs();
    clientA.getLocalFile("sphinxbase-0.8/src/sphinx_adtools").mkdirs();
    clientA.createNewFile("sphinxbase-0.8/config.sub");
    clientA.createNewFile("sphinxbase-0.8/win32/sphinx_jsgf2fsg/sphinx_jsgf2fsg.vcxproj");
    clientA.createNewFile("sphinxbase-0.8/src/sphinx_adtools/sphinx_pitch.c");
    // Client B creates the exact SAME FILES (here: copies the file tree from A)
    FileUtils.copyDirectory(clientA.getLocalFile("sphinxbase-0.8"), clientB.getLocalFile("sphinxbase-0.8"), true);
    // Now, both upload that
    // (A1)
    UpOperationResult upResultA = clientA.upWithForceChecksum();
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResultA.getResultCode());
    assertEquals(8, upResultA.getChangeSet().getNewFiles().size());
    // (B1)
    UpOperationResult upResultB = clientB.up(upOperationOptionsWithForce);
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResultB.getResultCode());
    assertEquals(8, upResultB.getChangeSet().getNewFiles().size());
    DownOperationResult downResultA = clientA.down();
    assertEquals(DownResultCode.OK_NO_REMOTE_CHANGES, downResultA.getResultCode());
    assertEquals(0, downResultA.getDirtyDatabasesCreated().size());
    assertEquals(false, downResultA.getChangeSet().hasChanges());
    // For peaking (does NOT affect the test)
    FileUtils.copyFile(new File(testConnection.getPath(), "databases/database-B-0000000001"), new File(testConnection.getPath(), "databases/TEMP_db-B-0000000001"));
    // creates DIRTY; deletes (B1)
    DownOperationResult downResultB = clientB.down();
    assertEquals(DownResultCode.OK_WITH_REMOTE_CHANGES, downResultB.getResultCode());
    assertEquals(1, downResultB.getDirtyDatabasesCreated().size());
    // TODO [low] Shouldn't this be 'true'?
    assertEquals(false, downResultB.getChangeSet().hasChanges());
    // For peaking (does NOT affect the test)
    FileUtils.copyDirectory(clientB.getLocalFile(".syncany/db"), clientB.getLocalFile(".syncany/db_WITH_DIRTY_B1"));
    Files.setPosixFilePermissions(clientB.getLocalFile("sphinxbase-0.8").toPath(), PosixFilePermissions.fromString("rwxrwxrwx"));
    // (B2)
    UpOperationResult upResultB2 = clientB.up();
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResultB2.getResultCode());
    assertEquals(1, upResultB2.getChangeSet().getChangedFiles().size());
    // For peaking (does NOT affect the test)
    FileUtils.copyDirectory(clientB.getLocalFile(".syncany/db"), clientB.getLocalFile(".syncany/db_DELETED_B1_WITH_B2"));
    clientA.down();
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) DownOperationResult(org.syncany.operations.down.DownOperationResult) TestClient(org.syncany.tests.util.TestClient) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) File(java.io.File) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 39 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class Issue247ScenarioTest method testIssue247.

@Test
public void testIssue247() throws Exception {
    // Setup
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientDzHome = new TestClient("Dz", testConnection);
    TestClient clientUxWork = new TestClient("Ux", testConnection);
    UpOperationOptions upOptionsWithForce = new UpOperationOptions();
    upOptionsWithForce.setForceUploadEnabled(true);
    // home -- generate some database versions so that the cleanup/merge will have something to merge
    clientDzHome.createNewFile("someotherfile0.xml");
    clientDzHome.upWithForceChecksum();
    for (int i = 0; i < 30; i++) {
        clientDzHome.changeFile("someotherfile0.xml");
        clientDzHome.upWithForceChecksum();
    }
    // home
    // <<<<< This is the file/checksum causing the issue
    clientDzHome.createNewFile("config.xml");
    clientDzHome.upWithForceChecksum();
    // Make a copy (for later)
    TestFileUtil.copyFile(clientDzHome.getLocalFile("config.xml"), new File(tempDir, "config.xml"));
    // work
    clientUxWork.down();
    clientUxWork.changeFile("config.xml");
    clientUxWork.upWithForceChecksum();
    clientUxWork.createNewFile("someotherfile1.xml");
    clientUxWork.upWithForceChecksum();
    clientUxWork.createNewFile("someotherfile2.xml");
    clientUxWork.upWithForceChecksum();
    clientUxWork.createNewFile("someotherfile3.xml");
    clientUxWork.upWithForceChecksum();
    // home
    clientDzHome.down();
    clientDzHome.changeFile("config.xml");
    clientDzHome.upWithForceChecksum();
    clientDzHome.changeFile("config.xml");
    clientDzHome.upWithForceChecksum();
    // work
    clientUxWork.down();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    clientUxWork.cleanup(cleanupOptions);
    // home
    clientDzHome.down();
    // Recreate problematic config.xml/checksum
    clientDzHome.deleteFile("config.xml");
    TestFileUtil.copyFile(new File(tempDir, "config.xml"), clientDzHome.getLocalFile("config.xml"));
    clientDzHome.upWithForceChecksum();
    // work
    clientUxWork.down();
    // Tear down
    TestFileUtil.deleteDirectory(tempDir);
    clientUxWork.deleteTestData();
    clientDzHome.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) File(java.io.File) Test(org.junit.Test)

Example 40 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class Issue303ScenarioTest method testIssue303DeleteMovedFile.

@Test
public void testIssue303DeleteMovedFile() throws Exception {
    /*
		 * This test moves a file and then deletes it. In issue #303, clients
		 * that had not moved the file already did not delete the file. It was left over
		 * leading to re-synchronization with the next 'up'.
		 */
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    clientA.createNewFile("Hello Christian, did something break?.txt");
    clientA.upWithForceChecksum();
    clientB.down();
    clientB.moveFile("Hello Christian, did something break?.txt", "Hello Christian, did something break (filename conflict).txt");
    clientB.upWithForceChecksum();
    clientB.deleteFile("Hello Christian, did something break (filename conflict).txt");
    clientB.upWithForceChecksum();
    clientA.down();
    assertFalse("File should have been deleted.", clientA.getLocalFile("Hello Christian, did something break?.txt").exists());
    assertFalse("File should not have been created.", clientA.getLocalFile("Hello Christian, did something break (filename conflict).txt").exists());
    // Tear down
    clientB.deleteTestData();
    clientA.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Test(org.junit.Test)

Aggregations

LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)61 Test (org.junit.Test)50 TestClient (org.syncany.tests.util.TestClient)46 File (java.io.File)33 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)21 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)17 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)13 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)8 FilenameFilter (java.io.FilenameFilter)7 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)7 UpOperationResult (org.syncany.operations.up.UpOperationResult)7 Random (java.util.Random)6 ConfigTO (org.syncany.config.to.ConfigTO)6 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)6 SqlDatabase (org.syncany.database.SqlDatabase)5 PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)5 PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)5 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)4 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 InitOperation (org.syncany.operations.init.InitOperation)4