Search in sources :

Example 31 with LocalTransferSettings

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

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

the class Issue227_2_ScenarioTest method testIssue227_MOM.

@Test
public void testIssue227_MOM() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientIH = new TestClient("iH", testConnection);
    TestClient clientMOM = new TestClient("MOM", testConnection);
    TestClient clientHSE = new TestClient("hSE", testConnection);
    UpOperationOptions upOptionsWithForce = new UpOperationOptions();
    upOptionsWithForce.setForceUploadEnabled(true);
    clientIH.createNewFile("file1.jpg");
    clientIH.up();
    clientIH.createNewFile("file2.jpg");
    clientIH.up();
    clientMOM.down();
    clientHSE.down();
    // -
    clientMOM.createNewFile("file3.jpg");
    clientMOM.up();
    clientMOM.createNewFile("file4.jpg");
    clientMOM.up();
    clientIH.down();
    clientHSE.down();
    // All in sync
    /*
		 * We want to create a time difference situation here between different clients.
		 *
		 * In reality:
		 * - Client "hSE" uploads a new database AFTER client "MOM"
		 *
		 * In this test:
		 * 1. Client "hSE" uploads a new database BEFORE client "MOM"
		 * 2. We hide "hSE"'s database by moving it to a temp. file
		 *    // ...
		 * 5. When we do 'down' at client "IH", the databases of client "MOM" are considered DIRTY
		 *
		 */
    // 1. Upload new database for hSE
    clientHSE.createNewFile("fileHSE-1.jpg");
    clientHSE.up(upOptionsWithForce);
    File[] hSEDatabaseFiles = new File(testConnection.getPath() + "/databases/").listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.contains("hSE");
        }
    });
    assertEquals(1, hSEDatabaseFiles.length);
    // 2. Hide database from other clients
    File hSEDatabaseFile = hSEDatabaseFiles[0];
    File hSEDatabaseFileHidden = new File(hSEDatabaseFile.getParentFile(), "HIDE_THIS_FILE_" + hSEDatabaseFile.getName());
    hSEDatabaseFile.renameTo(hSEDatabaseFileHidden);
    // 3. This shouldn't do anything; no new databases!
    DownOperationResult downOperationResult = clientIH.down();
    assertEquals(0, downOperationResult.getDownloadedUnknownDatabases().size());
    // 4. Upload database from client "MOM" (later considered DIRTY)
    clientMOM.createNewFile("fileMOM-1.jpg");
    clientMOM.up(upOptionsWithForce);
    clientMOM.createNewFile("fileMOM-2.jpg");
    clientMOM.up(upOptionsWithForce);
    // 5. Download changes from "MOM" (apply databases and files that will later be DIRTY)
    downOperationResult = clientIH.down();
    assertEquals(0, downOperationResult.getDirtyDatabasesCreated().size());
    // 6. Rename hidden database (= the later winner!)Now download the changes that
    // Databases of client "MOM" will be considered "DIRTY"
    hSEDatabaseFileHidden.renameTo(hSEDatabaseFile);
    downOperationResult = clientIH.down();
    assertEquals(2, downOperationResult.getDirtyDatabasesCreated().size());
    // 7. This should remove DIRTY database versions from the database
    // and ADD the multichunks from the previous database versions to the new database version (<< this is what kills MOM)
    clientIH.up();
    // <<<<<<<< This should produce Pim's stack trace from issue #227
    clientMOM.down();
    // Tear down
    clientIH.deleteTestData();
    clientMOM.deleteTestData();
    clientHSE.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) 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) Test(org.junit.Test)

Example 33 with LocalTransferSettings

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

the class Issue227_2_ScenarioTest method testIssue227_IH.

@Test
public void testIssue227_IH() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientIH = new TestClient("iH", testConnection);
    TestClient clientMOM = new TestClient("MOM", testConnection);
    TestClient clientHSE = new TestClient("hSE", testConnection);
    TestClient clientMee = new TestClient("Mee", testConnection);
    UpOperationOptions upOptionsWithForce = new UpOperationOptions();
    upOptionsWithForce.setForceUploadEnabled(true);
    clientIH.createNewFile("file1.jpg");
    clientIH.up();
    clientIH.createNewFile("file2.jpg");
    clientIH.up();
    clientMOM.down();
    clientHSE.down();
    // -
    clientMOM.createNewFile("file3.jpg");
    clientMOM.up();
    clientMOM.createNewFile("file4.jpg");
    clientMOM.up();
    clientIH.down();
    clientHSE.down();
    // All in sync
    /*
		 * We want to create a time difference situation here between different clients.
		 *
		 * In reality:
		 * - Client "hSE" uploads a new database AFTER client "MOM"
		 *
		 * In this test:
		 * 1. Client "hSE" uploads a new database BEFORE client "MOM"
		 * 2. We hide "hSE"'s database by moving it to a temp. file
		 *    // ...
		 * 5. When we do 'down' at client "IH", the databases of client "MOM" are considered DIRTY
		 *
		 */
    // 1. Upload new database for hSE
    clientHSE.createNewFile("fileHSE-1.jpg");
    clientHSE.up(upOptionsWithForce);
    File[] hSEDatabaseFiles = new File(testConnection.getPath() + "/databases/").listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.contains("hSE");
        }
    });
    assertEquals(1, hSEDatabaseFiles.length);
    // 2. Hide database from other clients
    File hSEDatabaseFile = hSEDatabaseFiles[0];
    File hSEDatabaseFileHidden = new File(hSEDatabaseFile.getParentFile(), "HIDE_THIS_FILE_" + hSEDatabaseFile.getName());
    hSEDatabaseFile.renameTo(hSEDatabaseFileHidden);
    // 3. This shouldn't do anything; no new databases!
    DownOperationResult downOperationResult = clientIH.down();
    assertEquals(0, downOperationResult.getDownloadedUnknownDatabases().size());
    // 4. Upload database from client "MOM" (later considered DIRTY)
    clientMOM.createNewFile("fileMOM-1.jpg");
    clientMOM.changeFile("file1.jpg");
    clientMOM.up(upOptionsWithForce);
    clientMOM.createNewFile("fileMOM-2.jpg");
    clientMOM.up(upOptionsWithForce);
    // 5. Download changes from "MOM" (apply databases and files that will later be DIRTY)
    downOperationResult = clientIH.down();
    assertEquals(0, downOperationResult.getDirtyDatabasesCreated().size());
    // 6. Rename hidden database (= the later winner!)Now download the changes that
    // Databases of client "MOM" will be considered "DIRTY"
    hSEDatabaseFileHidden.renameTo(hSEDatabaseFile);
    downOperationResult = clientIH.down();
    assertEquals(2, downOperationResult.getDirtyDatabasesCreated().size());
    // 7. This should remove DIRTY database versions from the database
    // and ADD the multichunks from the previous database versions to the new database version (<< this is what kills MOM)
    clientIH.up();
    clientIH.down();
    // <<< This copies a file for which the filecontent has been deleted
    clientIH.copyFile("file2.jpg", "file2copy.jpg");
    clientIH.up();
    // << This should throw Philipp's stack trace in #227
    clientMee.down();
    // Tear down
    clientIH.deleteTestData();
    clientMOM.deleteTestData();
    clientHSE.deleteTestData();
    clientMee.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) 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) Test(org.junit.Test)

Example 34 with LocalTransferSettings

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

the class Issue227_2_ScenarioTest method testIssue227_multiple_resolve.

@Test
public void testIssue227_multiple_resolve() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientIH = new TestClient("iH", testConnection);
    TestClient clientMOM = new TestClient("MOM", testConnection);
    TestClient clientHSE = new TestClient("hSE", testConnection);
    TestClient clientMee = new TestClient("Mee", testConnection);
    TestClient clientIHtwo = new TestClient("IHtwo", testConnection);
    UpOperationOptions upOptionsWithForce = new UpOperationOptions();
    upOptionsWithForce.setForceUploadEnabled(true);
    clientIH.createNewFile("file1.jpg");
    clientIH.up();
    clientIH.createNewFile("file2.jpg");
    clientIH.up();
    clientMOM.down();
    clientHSE.down();
    // -
    clientMOM.createNewFile("file3.jpg");
    clientMOM.up();
    clientMOM.createNewFile("file4.jpg");
    clientMOM.up();
    clientIH.down();
    clientIHtwo.down();
    clientHSE.down();
    // All in sync
    /*
		 * We want to create a time difference situation here between different clients.
		 *
		 * In reality:
		 * - Client "hSE" uploads a new database AFTER client "MOM"
		 *
		 * In this test:
		 * 1. Client "hSE" uploads a new database BEFORE client "MOM"
		 * 2. We hide "hSE"'s database by moving it to a temp. file
		 *    // ...
		 * 5. When we do 'down' at client "IH", the databases of client "MOM" are considered DIRTY
		 *
		 */
    // 1. Upload new database for hSE
    clientHSE.createNewFile("fileHSE-1.jpg");
    clientHSE.up(upOptionsWithForce);
    File[] hSEDatabaseFiles = new File(testConnection.getPath() + "/databases/").listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.contains("hSE");
        }
    });
    assertEquals(1, hSEDatabaseFiles.length);
    // 2. Hide database from other clients
    File hSEDatabaseFile = hSEDatabaseFiles[0];
    File hSEDatabaseFileHidden = new File(hSEDatabaseFile.getParentFile(), "HIDE_THIS_FILE_" + hSEDatabaseFile.getName());
    hSEDatabaseFile.renameTo(hSEDatabaseFileHidden);
    // 3. This shouldn't do anything; no new databases!
    DownOperationResult downOperationResult = clientIH.down();
    assertEquals(0, downOperationResult.getDownloadedUnknownDatabases().size());
    // same as IH!
    clientIHtwo.down();
    // 4. Upload database from client "MOM" (later considered DIRTY)
    clientMOM.createNewFile("fileMOM-1.jpg");
    clientMOM.changeFile("file1.jpg");
    clientMOM.up(upOptionsWithForce);
    clientMOM.createNewFile("fileMOM-2.jpg");
    clientMOM.up(upOptionsWithForce);
    // 5. Download changes from "MOM" (apply databases and files that will later be DIRTY)
    downOperationResult = clientIH.down();
    assertEquals(0, downOperationResult.getDirtyDatabasesCreated().size());
    // same as IH!
    clientIHtwo.down();
    // 6. Rename hidden database (= the later winner!)Now download the changes that
    // Databases of client "MOM" will be considered "DIRTY"
    hSEDatabaseFileHidden.renameTo(hSEDatabaseFile);
    downOperationResult = clientIH.down();
    assertEquals(2, downOperationResult.getDirtyDatabasesCreated().size());
    // same as IH!
    clientIHtwo.down();
    // 7. This should remove DIRTY database versions from the database
    // and ADD the multichunks from the previous database versions to the new database version (<< this is what kills MOM)
    clientIH.up(upOptionsWithForce);
    clientIHtwo.up(upOptionsWithForce);
    /*clientIH.down();
		clientIH.copyFile("file2.jpg", "file2copy.jpg"); // <<< This copies a file for which the filecontent has been deleted
		clientIH.up();*/
    // << This should throw Philipp's stack trace in #227
    clientMee.down();
    // Tear down
    clientIH.deleteTestData();
    clientMOM.deleteTestData();
    clientHSE.deleteTestData();
    clientMee.deleteTestData();
    clientIHtwo.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) 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) Test(org.junit.Test)

Example 35 with LocalTransferSettings

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

the class Issue429ScenarioTest method testIssue492UploadDuplicateFile.

@Ignore
public void testIssue492UploadDuplicateFile() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    clientA.createNewFile("file1.txt", 1024);
    clientA.upWithForceChecksum();
    FileUtils.copyFile(clientA.getLocalFile("file1.txt"), clientB.getLocalFile("file2.txt"));
    clientB.down();
    clientB.up();
    clientA.deleteFile("file1.txt");
    clientA.deleteFile("file2.txt");
    clientA.upWithForceChecksum();
    clientB.cleanup();
    clientC.down();
// Tear down
// clientB.deleteTestData();
// clientA.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Ignore(org.junit.Ignore)

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