Search in sources :

Example 26 with UpOperationOptions

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

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

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

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

the class TestClient method upWithForceChecksum.

public UpOperationResult upWithForceChecksum() throws Exception {
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    UpOperationOptions upOptions = new UpOperationOptions();
    upOptions.setStatusOptions(statusOptions);
    return up(upOptions);
}
Also used : UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions)

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