Package org.syncany.tests.util

Examples of org.syncany.tests.util.TestClient


  @Test
  public void testCleanupNoChangeBecauseDirty() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);

    CleanupOperationOptions removeOldCleanupOperationOptions = new CleanupOperationOptions();
    removeOldCleanupOperationOptions.setMergeRemoteFiles(false);
    removeOldCleanupOperationOptions.setRemoveOldVersions(true);
    removeOldCleanupOperationOptions.setKeepVersionsCount(2);

    StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
    forceChecksumStatusOperationOptions.setForceChecksum(true);

    UpOperationOptions noCleanupAndForceUpOperationOptions = new UpOperationOptions();
    noCleanupAndForceUpOperationOptions.setForceUploadEnabled(true);
    noCleanupAndForceUpOperationOptions.setStatusOptions(forceChecksumStatusOperationOptions);

    // Run

    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    // B: Sync down, add something
    clientB.down();

    // A: Change file.jpg (first step in creating a conflict)
    clientA.changeFile("file.jpg");
    clientA.up(noCleanupAndForceUpOperationOptions);

    // B: Change file.jpg (second step in creating a conflict)
    clientB.changeFile("file.jpg");
    clientB.up(noCleanupAndForceUpOperationOptions); // << creates conflict

    // B: Sync down (creates a local conflict file and marks local changes as DRITY)
    clientB.down(); // << creates DIRTY database entries

    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(removeOldCleanupOperationOptions);
    assertEquals(CleanupResultCode.NOK_DIRTY_LOCAL, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here


  @Test
  public void testCleanupMergeDatabaseFilesScenario1() 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);

    CleanupOperationOptions cleanupOptionsOnlyMergeDatabases = new CleanupOperationOptions();
    cleanupOptionsOnlyMergeDatabases.setMergeRemoteFiles(true);
    cleanupOptionsOnlyMergeDatabases.setRemoveOldVersions(false);

    UpOperationOptions upOperationOptionsNoCleanup = new UpOperationOptions();
    upOperationOptionsNoCleanup.setForceUploadEnabled(true);

    // Run preparations
    int[] clientUpSequence = new int[] {
        // Modeled after a crashing real-world scenario
        // 1 = A down+up, 2 = B down+up

        // The actual sequence was:
        // 1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 1, 2,
        // 2, 2, 2, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 1, 2, 1, 1

        // This simplified sequence also crashes/crashed
        // 16x "1", merge happens after 15!
        1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
    };

    for (int i = 0; i < clientUpSequence.length; i++) {
      if (clientUpSequence[i] == 1) {
        clientA.down();

        clientA.createNewFile("A-file" + i + ".jpg", i);
        clientA.up(upOperationOptionsNoCleanup);
      }
      else {
        clientB.down();

        clientB.createNewFile("B-file" + i + ".jpg", i);
        clientB.up(upOperationOptionsNoCleanup);
      }
    }

    clientA.cleanup();

    clientA.down();
    clientB.down();

    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());

    // Make sure the "merge" process actually happened
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000001").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000005").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000010").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000030").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000031").exists());

    // Run
    clientC.down(); // <<< Here is/was the issue: Client C failed when downloading
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
  }
View Full Code Here

     */

    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();

    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);

    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile());
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile());

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMergeRemoteFiles(true);
    options.setRemoveOldVersions(true);
    options.setKeepVersionsCount(5);
    options.setMinSecondsBetweenCleanups(0);
    options.setMaxDatabaseFiles(7);

    StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
    statusOptionsForceChecksum.setForceChecksum(true);

    UpOperationOptions upOperationOptionsWithCleanupForce = new UpOperationOptions();
    upOperationOptionsWithCleanupForce.setStatusOptions(statusOptionsForceChecksum);
    upOperationOptionsWithCleanupForce.setForceUploadEnabled(true);

    // Run preparations

    clientA.down();
    clientA.createNewFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A1)
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000001").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000002").exists());

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A2)
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000002").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000003").exists());

    clientB.down();
    clientB.changeFile("A-file.jpg");
    clientB.up(upOperationOptionsWithCleanupForce); // (A2,B1)
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000001").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-B-0000000002").exists());

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A3,B1)
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000003").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000004").exists());

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A4,B1)
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000004").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000005").exists());

    clientB.down();
    clientB.changeFile("A-file.jpg");
    clientB.up(upOperationOptionsWithCleanupForce); // (A4,B2) + (A4,B3) [PURGE]
    clientB.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000002").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000003").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-B-0000000004").exists());

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A5,B3) + (A6,B3) [PURGE]
    clientA.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000005").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000006").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000007").exists());

    clientB.down();
    clientB.changeFile("A-file.jpg");
    clientB.up(upOperationOptionsWithCleanupForce); // (A6,B4) + (A6,B5) [PURGE]
    clientB.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000004").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000005").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-B-0000000006").exists());

    /*
     * For some reason, this chunk checksum in the following commit is the reason for the exception. So we record it here to see where it vanishes
     * from the databases.
     */

    clientA.down();
    clientA.changeFile("A-file.jpg");

    String fileAndChunkChecksumThatRaisesException = StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-file.jpg")));
    System.out.println("Chunk/File checksum that raises the issue: " + fileAndChunkChecksumThatRaisesException);

    clientA.createNewFile("ADDED_IN_DBV_A7_B5");
    clientA.up(upOperationOptionsWithCleanupForce); // (A7,B5) + (A8,B5) [PURGE]
    clientA.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000007").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000008").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000009").exists());
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionA));

    clientB.down();
    clientB.changeFile("A-file.jpg");
    clientB.up(upOperationOptionsWithCleanupForce); // (A8,B6) + (A8,B7) [PURGE]
    clientB.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000007").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-B-0000000008").exists());
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionB));

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A9,B7) + (A10,B7) [PURGE]
    clientA.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000009").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000010").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000011").exists());
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionA));

    clientB.down();
    clientB.changeFile("A-file.jpg");
    clientB.up(upOperationOptionsWithCleanupForce); // (A10,B8) + (A10,B9) [PURGE]
    clientB.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000008").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000009").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-B-0000000010").exists());
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionB));

    clientB.down();
    clientB.changeFile("A-file.jpg");
    clientB.up(upOperationOptionsWithCleanupForce); // (A10,B10) + (A10,B11) [PURGE]
    clientB.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000010").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000011").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-B-0000000012").exists());
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionB));

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A11,B11) + (A12,B11) [PURGE]
    clientA.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000011").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000012").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000013").exists());
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionA));

    // ^^^ Old chunk deleted!

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A13,B11) + (A14,B11) [PURGE]
    clientA.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000013").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000014").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000015").exists());
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionA));

    clientB.down();
    clientB.changeFile("A-file.jpg");
    clientB.up(upOperationOptionsWithCleanupForce); // (A14,B12) + (A14,B13) [PURGE]
    clientB.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000012").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-B-0000000013").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-B-0000000014").exists());
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionB));

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A15,B13) + (A16,B13) [PURGE]
    clientA.cleanup(options);
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000015").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000016").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000017").exists());
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionA));

    clientA.down();
    clientA.changeFile("A-file.jpg");
    clientA.up(upOperationOptionsWithCleanupForce); // (A17,B13) + (A18,B13) [PURGE]
    clientA.cleanup(options);
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000017").exists());
    assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000018").exists());
    assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000019").exists());
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionA));

    // Sync them up
    clientA.down();
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionA));

    clientB.down();
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'",
        databaseConnectionB));

    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());

    // Run
    clientC.down(); // <<< Here is/was the issue: Client C failed when downloading
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
  }
View Full Code Here

  @Test
  public void testIssue58_3() 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);

    CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
    cleanupOptionsKeep1.setMergeRemoteFiles(true);
    cleanupOptionsKeep1.setRemoveOldVersions(true);
    cleanupOptionsKeep1.setKeepVersionsCount(1);

    StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
    statusOptionsForceChecksum.setForceChecksum(true);

    UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
    upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);

    UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
    upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);

    clientA.createNewFile("fileA");
    clientB.createNewFile("fileB");

    clientA.up(upNoCleanupForceChecksum);
    clientB.down();

    TestFileUtil.copyFile(clientA.getLocalFile("fileA"), clientB.getLocalFile("fileB"));
    String problemChecksum = StringUtil.toHex(FileUtil.createChecksum(clientA.getLocalFile("fileA"), "SHA1"));
    clientB.up(upNoCleanupForceChecksum);

    for (int i = 0; i < 20; i++) {
      clientA.down();
      clientA.changeFile("fileA");
      clientA.up(upNoCleanupForceChecksum);

      clientB.down();
      clientB.changeFile("fileB");
      clientB.up(upNoCleanupForceChecksum);
    }

    System.out.println("Problem checksum: " + problemChecksum);

    clientB.cleanup();

    clientA.down();

    clientA.cleanup();

    clientA.down();
    clientC.down();

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
  }
View Full Code Here

    // Test for https://github.com/syncany/syncany/issues/58#issuecomment-43472118

    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();

    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);

    CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
    cleanupOptionsKeep1.setMergeRemoteFiles(true);
    cleanupOptionsKeep1.setRemoveOldVersions(true);
    cleanupOptionsKeep1.setKeepVersionsCount(1);

    StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
    statusOptionsForceChecksum.setForceChecksum(true);

    UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
    upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);

    UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
    upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);

    clientB.createNewFile("fileB");
    clientB.up(upNoCleanupForceChecksum);

    clientA.down();
    TestFileUtil.copyFile(clientB.getLocalFile("fileB"), clientA.getLocalFile("fileBcopy"));
    clientA.up(upNoCleanupForceChecksum);

    for (int i = 0; i < 30; i++) {
      clientB.down();
      clientB.changeFile("fileB");
      clientB.up(upNoCleanupForceChecksum);
    }

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "1_before_cleanup"));

    CleanupOperationOptions cleanupMergeAndRemoveOldFiles = new CleanupOperationOptions();
    cleanupMergeAndRemoveOldFiles.setMergeRemoteFiles(true);
    cleanupMergeAndRemoveOldFiles.setRemoveOldVersions(true);
    clientB.cleanup(cleanupMergeAndRemoveOldFiles);

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_2_after_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "2_after_cleanup"));

    clientC.down(); // <<< "Cannot determine file content for checksum X"

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
  }
View Full Code Here

    // Test for https://github.com/syncany/syncany/issues/58#issuecomment-43472118

    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();

    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    TestClient clientD = new TestClient("D", testConnection);
    TestClient clientE = new TestClient("E", testConnection);

    CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
    cleanupOptionsKeep1.setMergeRemoteFiles(true);
    cleanupOptionsKeep1.setRemoveOldVersions(true);
    cleanupOptionsKeep1.setKeepVersionsCount(1);

    StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
    statusOptionsForceChecksum.setForceChecksum(true);

    UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
    upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);

    UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
    upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);

    // First round

    clientB.createNewFile("fileA");
    clientB.up(upNoCleanupForceChecksum);

    clientA.down();
    TestFileUtil.copyFile(clientA.getLocalFile("fileA"), clientA.getLocalFile("fileAcopy"));
    clientA.up(upNoCleanupForceChecksum);

    clientA.down();

    for (int i = 0; i < 30; i++) {
      clientA.down();
      clientA.changeFile("fileA");
      clientA.up(upNoCleanupForceChecksum);
    }

    // First cleanup

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_cleanup"));
    FileUtils.copyDirectory(clientA.getConfig().getDatabaseDir(), new File(clientA.getConfig().getAppDir(), "1_before_cleanup"));

    CleanupOperationOptions cleanupMergeAndRemoveOldFiles = new CleanupOperationOptions();
    cleanupMergeAndRemoveOldFiles.setMergeRemoteFiles(true);
    cleanupMergeAndRemoveOldFiles.setRemoveOldVersions(true);
    clientA.cleanup(cleanupMergeAndRemoveOldFiles);

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_2_after_cleanup"));
    FileUtils.copyDirectory(clientA.getConfig().getDatabaseDir(), new File(clientA.getConfig().getAppDir(), "2_after_cleanup"));

    clientC.down(); // If this doesn't crash that's a win!

    // Second round

    for (int i = 0; i < 30; i++) {
      clientB.down();
      clientB.changeFile("fileA");
      clientB.up(upNoCleanupForceChecksum);
    }

    // Second cleanup

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_3_before_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "3_before_cleanup"));

    clientB.cleanup(cleanupMergeAndRemoveOldFiles);

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_4_after_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "4_after_cleanup"));

    clientD.down(); // If this doesn't crash that's a win!

    // Third round

    for (int i = 0; i < 30; i++) {
      clientB.down();
      clientB.changeFile("fileA");
      clientB.up(upNoCleanupForceChecksum);
    }

    clientB.deleteFile("fileAcopy"); // < Remove original checksum from first DBV
    clientB.up(upNoCleanupForceChecksum);

    // Third cleanup

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_5_before_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "5_before_cleanup"));

    clientB.cleanup(cleanupMergeAndRemoveOldFiles);

    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_6_after_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "6_after_cleanup"));

    clientE.down(); // If this doesn't crash that's a win!

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
View Full Code Here

  @Test
  public void testIssue200() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // Run
    clientA.createNewFolder("folder");
    clientA.createNewFile("folder/file");
    clientA.upWithForceChecksum();   
   
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientA.changeFile("folder/file");
    clientA.upWithForceChecksum();
   
    clientB.deleteFile("folder/file");
    clientB.down();
    assertTrue(clientB.getLocalFile("folder/file").exists());

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

  @Test
  public void testManyRenames() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // A new/up
    clientA.createNewFile("A-original");
    clientA.up();
   
    // B down/move/up
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientB.moveFile("A-original", "B-moved");
    clientB.up();
   
    // A down/move/up
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientA.moveFile("B-moved", "A-moved");
    clientA.up();
   
    // B down only
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    // A down/move/up
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientA.moveFile("A-moved", "A-moved-again");
    clientA.up();
   
    // B down/move/up
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientB.moveFile("A-moved-again", "B-moved"); // same filename as above!
    clientB.up();
   
    // A down/move/up
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientA.moveFile("B-moved", "A-moved")// same filename as above!
    clientA.up();
   
    // B down only
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

        // Format: abs=<count> rel=<count> op=<connect|init|upload|...> <operation description>

        "rel=[456].+upload.+multichunk" // << 3 retries!
    }));

    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);

    StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
    forceChecksumStatusOperationOptions.setForceChecksum(true);

    UpOperationOptions noCleanupAndForceUpOperationOptions = new UpOperationOptions();
    noCleanupAndForceUpOperationOptions.setForceUploadEnabled(true);
    noCleanupAndForceUpOperationOptions.setStatusOptions(forceChecksumStatusOperationOptions);

    // Run

    // 1. Call A.up(); this fails AFTER the first multichunk
    clientA.createNewFile("A-file1", 5 * 1024 * 1024);
    boolean operationFailed = false;

    try {
      clientA.up();
    }
    catch (Exception e) {
      operationFailed = true; // That is supposed to happen!
    }

    File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
    File repoActionsDir = new File(testConnection.getPath() + "/actions");

    assertTrue(operationFailed);
    // Atomic operation, so multichunk is not yet present at location
    assertEquals(0, repoMultiChunkDir.listFiles().length);
    assertEquals(1, repoActionsDir.listFiles().length);

    // 2. Call A.cleanup(); this does not run, because there are local changes
    CleanupOperationResult cleanupOperationResultA = clientA.cleanup();
    assertEquals(CleanupResultCode.NOK_LOCAL_CHANGES, cleanupOperationResultA.getResultCode());

    // 3. Call B.cleanup(); this does not run, because of the leftover 'action' file
    CleanupOperationResult cleanupOperationResultB = clientB.cleanup();
    assertEquals(CleanupResultCode.NOK_OTHER_OPERATIONS_RUNNING, cleanupOperationResultB.getResultCode());

    // 4. Call B.down(); this does not deliver any results, because no databases have been uploaded
    DownOperationResult downOperationResult = clientB.down();
    assertEquals(DownResultCode.OK_NO_REMOTE_CHANGES, downOperationResult.getResultCode());

    // 5. Call 'up' again, this uploads previously crashed stuff, and then runs cleanup.
    // The cleanup then removes the old multichunk and the old action files.

    UpOperationResult secondUpResult = clientA.up();
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, secondUpResult.getResultCode());
    assertEquals(2, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);

    // 6. Call 'cleanup' manually (Nothing happens, since transaction was cleaned on second up)
    CleanupOperationResult cleanupOperationResult = clientA.cleanup();
    assertEquals(CleanupOperationResult.CleanupResultCode.OK_NOTHING_DONE, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, repoActionsDir.listFiles().length);

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

  @Test
  public void testCleanupMaxDatabaseFiles() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMergeRemoteFiles(true);
    options.setRemoveOldVersions(true);
    options.setKeepVersionsCount(10);
    options.setMaxDatabaseFiles(3);

    // Run

    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(4, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());

    TestClient clientB = new TestClient("B", testConnection);
    clientB.down();

    // B: Create some file versions
    clientB.createNewFile("file-B.jpg");
    for (int i = 1; i <= 6; i++) {
      clientB.changeFile("file-B.jpg");
      clientB.upWithForceChecksum();
    }

    // B: Cleanup (2 clients, so 7 databases is too much)
    cleanupOperationResult = clientB.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(7, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());

    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

TOP

Related Classes of org.syncany.tests.util.TestClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.