Search in sources :

Example 21 with UpOperationOptions

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

the class DirtyDatabaseVersionsScenarioTest method testRemoveDirtyLostMultiChunksIssue132_1.

@Test
public void testRemoveDirtyLostMultiChunksIssue132_1() throws Exception {
    /*
		 * This test tries to provoke issue #132, i.e. the deletion of 
		 * multichunks of DIRTY database versions of other clients. 
		 */
    // Setup 
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    UpOperationOptions upOptionsWithForce = new UpOperationOptions();
    upOptionsWithForce.setForceUploadEnabled(true);
    // Run 
    clientA.createNewFile("file1.jpg");
    clientA.up();
    clientB.down();
    clientB.createNewFile("file2.jpg");
    clientB.up();
    clientA.createNewFile("file3.jpg");
    // No 'down' (creates dirty version)	
    clientA.up(upOptionsWithForce);
    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_down"));
    FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir() + "_1_before_down"));
    assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "0");
    // Download A's version, realize it's muddy (= dirty by other client)
    clientB.down();
    assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "1");
    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath(), "_2_after_down_before_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir() + "_2_after_down_before_cleanup"));
    assertEquals(3, new File(testConnection.getPath(), "multichunks").listFiles().length);
    // <<< This should NOT delete any lost multichunks of DIRTY database versions!
    clientB.cleanup();
    assertEquals(3, new File(testConnection.getPath(), "multichunks").listFiles().length);
    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_3_after_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir() + "_3_after_cleanup"));
    // Adds dirty database
    clientA.down();
    assertSqlResultEquals(clientA.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "1");
    clientA.up();
    assertSqlResultEquals(clientA.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "0");
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "0");
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    System.out.println(new File(testConnection.getPath() + "_1_before_down"));
    System.out.println(new File(clientB.getConfig().getLocalDir(), "_1_before_down"));
    FileUtils.deleteDirectory(new File(testConnection.getPath() + "_1_before_down"));
    FileUtils.deleteDirectory(new File(clientB.getConfig().getLocalDir() + "_1_before_down"));
    FileUtils.deleteDirectory(new File(testConnection.getPath() + "_2_after_down_before_cleanup"));
    FileUtils.deleteDirectory(new File(clientB.getConfig().getLocalDir() + "_2_after_down_before_cleanup"));
    FileUtils.deleteDirectory(new File(testConnection.getPath() + "_3_after_cleanup"));
    FileUtils.deleteDirectory(new File(clientB.getConfig().getLocalDir() + "_3_after_cleanup"));
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 22 with UpOperationOptions

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

the class DirtyDatabaseVersionsScenarioTest method testThreeClientsOneLoser.

@Test
public void testThreeClientsOneLoser() 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);
    UpOperationOptions cUpOptionsWithForce = new UpOperationOptions();
    cUpOptionsWithForce.setForceUploadEnabled(true);
    // Run 
    clientA.createNewFile("file1.jpg");
    clientA.upWithForceChecksum();
    clientB.down();
    clientB.createNewFile("file2.jpg");
    clientB.upWithForceChecksum();
    // Client C: No down!
    clientC.createNewFile("file3.jpg");
    clientC.up(cUpOptionsWithForce);
    // A tries to upload, this fails due to C's unknown database
    clientA.createNewFile("file4.jpg");
    // 
    UpOperationResult aUpResult = clientA.upWithForceChecksum();
    assertEquals("Expected to fail, because db-C-1 has not been looked at", UpResultCode.NOK_UNKNOWN_DATABASES, aUpResult.getResultCode());
    assertFalse(clientA.getLocalFile("file2.jpg").exists());
    assertFalse(clientA.getLocalFile("file3.jpg").exists());
    // A downloads C's changes, no file changes are expected
    DownOperationResult aDownResult = clientA.down();
    assertEquals("Expected to succeed with remote changes (a new database file, but no file changes!).", DownResultCode.OK_WITH_REMOTE_CHANGES, aDownResult.getResultCode());
    assertTrue(clientA.getLocalFile("file2.jpg").exists());
    assertFalse(clientA.getLocalFile("file3.jpg").exists());
    // TODO [low] Add assert: "no file changes are expected"
    // A uploads again, this time it should succeed, because C's file is in knowndbs.list
    aUpResult = clientA.upWithForceChecksum();
    assertEquals("Expected to succeed, because db-C-1 has already been looked at", UpResultCode.OK_CHANGES_UPLOADED, aUpResult.getResultCode());
    // C calls down and up, to sync its changes
    // Adds dirty database
    clientC.down();
    assertSqlResultEquals(clientC.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "1");
    clientC.upWithForceChecksum();
    assertSqlResultEquals(clientC.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "0");
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
}
Also used : DownOperationResult(org.syncany.operations.down.DownOperationResult) TestClient(org.syncany.tests.util.TestClient) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 23 with UpOperationOptions

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

the class FirstVersionDirtyScenarioTest method testFirstVersionDirty.

@Test
public void testFirstVersionDirty() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    UpOperationOptions forceUpOperationOptions = new UpOperationOptions();
    forceUpOperationOptions.setForceUploadEnabled(true);
    // Run 
    clientA.createNewFile("A-file1.jpg", 1 * 1024 * 1024);
    clientA.up(forceUpOperationOptions);
    // B's timestamp must be later
    Thread.sleep(200);
    TestFileUtil.copyFile(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
    clientB.up(forceUpOperationOptions);
    // Client B loses		
    // <<<<<<< This used to throw all sorts of PRIMARY KEY CONSTRAINT errors
    clientB.down();
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    TestAssertUtil.assertSqlDatabaseTablesEqual(clientA.getDatabaseFile(), clientB.getDatabaseFile(), new String[] { "chunk", "multichunk", "filecontent", "filecontent_chunk" });
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from filehistory", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from filehistory", databaseConnectionB));
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));
    // The table "multichunk_chunk" has 4 entries in B, but only 2 in A (!)
    // This is because the same file (= same chunks) are uploaded twice. 
    // TODO [medium] The cleanup operation does not clean multichunks with redundant chunks, or does it?!
    assertEquals(2 * Integer.parseInt(TestSqlUtil.runSqlSelect("select count(*) from multichunk_chunk", databaseConnectionA)), Integer.parseInt(TestSqlUtil.runSqlSelect("select count(*) from multichunk_chunk", databaseConnectionB)));
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) Test(org.junit.Test)

Example 24 with UpOperationOptions

use of org.syncany.operations.up.UpOperationOptions 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 25 with UpOperationOptions

use of org.syncany.operations.up.UpOperationOptions 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)

Aggregations

UpOperationOptions (org.syncany.operations.up.UpOperationOptions)29 Test (org.junit.Test)25 TestClient (org.syncany.tests.util.TestClient)23 File (java.io.File)16 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)14 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)10 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)8 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)7 DownOperationResult (org.syncany.operations.down.DownOperationResult)6 FilenameFilter (java.io.FilenameFilter)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 StorageException (org.syncany.plugins.transfer.StorageException)4 TransferSettings (org.syncany.plugins.transfer.TransferSettings)4 Config (org.syncany.config.Config)3 UpOperation (org.syncany.operations.up.UpOperation)3 Persister (org.simpleframework.xml.core.Persister)2 ChangeSet (org.syncany.operations.ChangeSet)2 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)2 TransferManager (org.syncany.plugins.transfer.TransferManager)2 TransactionAware (org.syncany.plugins.transfer.features.TransactionAware)2