Search in sources :

Example 71 with TestClient

use of org.syncany.tests.util.TestClient 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 72 with TestClient

use of org.syncany.tests.util.TestClient 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 73 with TestClient

use of org.syncany.tests.util.TestClient 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 74 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class Issue316ScenarioTest method testIssue316CleanupThenDeleteFile.

@Test
public void testIssue316CleanupThenDeleteFile() throws Exception {
    /*
		 * This is a test for issue #316. It creates a situation in which a 'down'
		 * fails after a cleanup. In that first down, the local database is deleted 
		 * entirely, so that all databases are downloaded again, so all remote file
		 * versions are compared to "null". In this bug, comparing a deleted file version
		 * to a local existing file failed, because this case was thought to not happen
		 * ever.  
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=(5|6|7) .+download.+multichunk" }));
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    java.sql.Connection databaseConnectionB = clientB.getConfig().createDatabaseConnection();
    CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
    cleanupOptionsKeepOne.setMaxDatabaseFiles(1);
    cleanupOptionsKeepOne.setForce(true);
    clientA.createNewFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    clientB.down();
    assertTrue(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    clientA.createNewFile("SomeFileTOIncreaseTheDatabaseFileCount");
    clientA.upWithForceChecksum();
    CleanupOperationResult cleanupResult = clientA.cleanup(cleanupOptionsKeepOne);
    assertEquals(CleanupResultCode.OK, cleanupResult.getResultCode());
    clientA.deleteFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    // First 'down' of client B after the cleanup.
    // This fails AFTER the local database was wiped.
    boolean downFailedAtB = false;
    try {
        clientB.down();
    } catch (Exception e) {
        downFailedAtB = true;
    }
    assertTrue("Down operation should have failed.", downFailedAtB);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from known_databases", databaseConnectionB));
    // Second 'down' of client B; This should delete the file 'Kazam_screencast_00010.mp4',
    // because it matches the checksum of the 'DELETED' entry
    clientB.down();
    assertConflictingFileNotExists("Kazam_screencast_00010.mp4", clientB.getLocalFiles());
    assertFalse(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    // Tear down
    clientB.deleteTestData();
    clientA.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) Test(org.junit.Test)

Example 75 with TestClient

use of org.syncany.tests.util.TestClient 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

TestClient (org.syncany.tests.util.TestClient)126 Test (org.junit.Test)122 TransferSettings (org.syncany.plugins.transfer.TransferSettings)65 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)53 File (java.io.File)50 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)31 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)28 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)23 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)14 FilenameFilter (java.io.FilenameFilter)11 StorageException (org.syncany.plugins.transfer.StorageException)11 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)10 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)10 DownOperationResult (org.syncany.operations.down.DownOperationResult)9 UpOperationResult (org.syncany.operations.up.UpOperationResult)8 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6 SqlDatabase (org.syncany.database.SqlDatabase)5 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)5 PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)5 PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)5