Package org.syncany.plugins.local

Examples of org.syncany.plugins.local.LocalTransferSettings


public class CleanupMergeDatabaseFilesScenarioTest {
  @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());
View Full Code Here


    /*
     * This is the attempt to reproduce issue #58 https://github.com/syncany/syncany/issues/58
     */

    // 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();
View Full Code Here

    // Run!
    UpOperation op = new UpOperation(testConfig);
    op.execute();

    // Get databases (for comparison)
    LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();

    File localDatabaseDir = testConfig.getDatabaseDir();
    File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-0000000001");

    assertNotNull(localDatabaseDir.listFiles());
    assertTrue(localDatabaseDir.listFiles().length > 0);
    assertTrue(remoteDatabaseFile.exists());
View Full Code Here

public class MoveFolderWithQuotesOnWindowsScenario
  @Test
  public void testMoveFolderWithQuotes_issue124() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // Create folder with file without quotes
    clientA.createNewFolder("folder_without_quotes");
    clientA.createNewFile("folder_without_quotes/file");
    clientA.up();
   
    // Sync to B
    clientB.down();
   
    // Now we should move to a folder with quotes, e.g.  folder "with" quotes
    // To make this work on Windows, we first move the folder and then modify
    // the database file on the remote storage to mock it
   
    clientA.moveFile("folder_without_quotes", "folder_with_quotes");
    clientA.up();
   
    for (File databaseFile : new File(testConnection.getPath()+"/databases/").listFiles()) {
      String databaseFileA2Content = IOUtils.toString(new FileInputStream(databaseFile), "UTF-8");
      String databaseFileA2NewContent = databaseFileA2Content.replaceAll("folder_with_quotes", "folder &quot;with&quot; quotes");

      IOUtils.write(databaseFileA2NewContent, new FileOutputStream(databaseFile));
    }
View Full Code Here

    /*
     * 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
    UpOperationResult upResultA = clientA.upWithForceChecksum(); // (A1)
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResultA.getResultCode());
    assertEquals(8, upResultA.getChangeSet().getNewFiles().size());

    UpOperationResult upResultB = clientB.up(upOperationOptionsWithForce); // (B1)
    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"));

    DownOperationResult downResultB = clientB.down(); // creates DIRTY; deletes (B1)
    assertEquals(DownResultCode.OK_WITH_REMOTE_CHANGES, downResultB.getResultCode());
    assertEquals(1, downResultB.getDirtyDatabasesCreated().size());
    assertEquals(false, downResultB.getChangeSet().hasChanges()); // TODO [low] Shouldn't this be 'true'?
View Full Code Here

public class ManySyncUpsAndOtherClientSyncDownScenarioTest {
  @Test
  public void testManySyncUpsAndOtherClientSyncDown() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();   
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // ROUND 1: many sync up (cleanups expected)
View Full Code Here

  }
 
  @Test
  public void testManySyncUpsAndOtherClientSyncDownSameFileAddRemove() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();   
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
   
View Full Code Here

  private static final int EXPECTED_NUM_PLUGINS = 3;

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

    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginAction.LIST);
    pluginOptions.setListMode(PluginListMode.LOCAL);
View Full Code Here

  public void testPluginListRemoteOnlyReleasesOnly() throws Exception {
    // Tests which plugin releases are available. This is difficult because
    // that will change. So we can only test the bare minimum.

    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);

    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginAction.LIST);
    pluginOptions.setListMode(PluginListMode.REMOTE);
View Full Code Here

  public void testPluginListRemoteOnlyIncludingSnapshots() throws Exception {
    // Tests which plugin snapshots are available. This is difficult because
    // that will change. So we can only test the bare minimum.

    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);

    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginAction.LIST);
    pluginOptions.setListMode(PluginListMode.REMOTE);
View Full Code Here

TOP

Related Classes of org.syncany.plugins.local.LocalTransferSettings

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.