Package org.syncany.tests.util

Examples of org.syncany.tests.util.TestClient


  @Test
  public void testEmptyFolderCreateAndSync() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // Run
    clientA.createNewFolder("A-folder1");
    clientA.createNewFolder("A-folder2");
    clientA.createNewFolder("A-folder3");
    clientA.up();   
   
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientB.createNewFolder("B-folder4");
    clientB.createNewFolder("B-folder5");
    clientB.up();
   
    SqlDatabase databaseB = clientB.loadLocalDatabase();
    DatabaseVersionHeader beforeDatabaseVersionHeader = databaseB.getLastDatabaseVersionHeader();
   
    clientB.up(); // double-up, has caused problems
   
    DatabaseVersionHeader afterDatabaseVersionHeader = databaseB.getLastDatabaseVersionHeader();
    assertEquals("Nothing changed. Local database file should not change.", beforeDatabaseVersionHeader, afterDatabaseVersionHeader);
   
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    Map<String, File> beforeSyncDownFileList = clientB.getLocalFilesExcludeLockedAndNoRead();
    clientA.down(); // double-down, has caused problems   
    assertFileListEquals("No change in file lists expected. Nothing changed", beforeSyncDownFileList, clientA.getLocalFilesExcludeLockedAndNoRead());        
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here


  @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));
    }
   
    clientB.down(); // << In issue 124, this failed because we tried to move the inner "file" to the folder with quotes
   
    if (EnvironmentUtil.isWindows()) {
      assertTrue(clientB.getLocalFile("folder with quotes (filename conflict)").exists());
      assertTrue(clientB.getLocalFile("folder with quotes (filename conflict)/file").exists());
    }
    else {
      assertTrue(clientB.getLocalFile("folder \"with\" quotes").exists());
      assertTrue(clientB.getLocalFile("folder \"with\" quotes/file").exists());
    }
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

     */

    // 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'?

    // 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"));
    UpOperationResult upResultB2 = clientB.up(); // (B2)
    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();
  }
View Full Code Here

  @Test
  public void testFileSystemActionReconDeleteNonExistingFolder() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    Config testConfigA = clientA.getConfig();
   
    // - Create first database version
    clientA.createNewFolder("new folder/some subfolder");
    clientA.upWithForceChecksum();
   
    clientA.deleteFile("new folder/some subfolder"); // Delete this!
   
    // - Create new version (delete folder)
    TestSqlDatabase sqlDatabaseA = new TestSqlDatabase(testConfigA);
    PartialFileHistory folderFileHistoryWithLastVersion = sqlDatabaseA.getFileHistoryWithLastVersion("new folder/some subfolder");

    FileVersion deletedFolderVersion = folderFileHistoryWithLastVersion.getLastVersion().clone();
    deletedFolderVersion.setStatus(FileStatus.DELETED);
    deletedFolderVersion.setVersion(deletedFolderVersion.getVersion()+1);
   
    PartialFileHistory deletedFolderVersionHistory = new PartialFileHistory(folderFileHistoryWithLastVersion.getFileHistoryId());
    deletedFolderVersionHistory.addFileVersion(deletedFolderVersion);
   
    DatabaseVersion winnersDatabaseVersion = TestDatabaseUtil.createDatabaseVersion(sqlDatabaseA.getLastDatabaseVersionHeader());   
    winnersDatabaseVersion.addFileHistory(deletedFolderVersionHistory);
   
    // - Create memory database with this version
    MemoryDatabase winnersDatabase = new MemoryDatabase();
    winnersDatabase.addDatabaseVersion(winnersDatabaseVersion);
   
    // Run! Finally!
    DownOperationResult outDownOperationResult = new DownOperationResult();
    FileSystemActionReconciliator fileSystemActionReconciliator = new FileSystemActionReconciliator(testConfigA, outDownOperationResult.getChangeSet());
    List<FileSystemAction> fileSystemActions = fileSystemActionReconciliator.determineFileSystemActions(winnersDatabase);
   
    assertNotNull(fileSystemActions);
    assertEquals(0, fileSystemActions.size());   
   
    // Tear down
    clientA.deleteTestData();
  }
View Full Code Here

  @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)
    for (int i=1; i<=50; i++) {
      clientA.createNewFile("file"+i, 1);
      clientA.up();   
    }
   
    // ROUND 2: sync down by B
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());   
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
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);
   
   
    // TODO Test not finished
   
    // ROUND 1: many sync up (cleanups expected)
    String[] names = new String[] { "one", "two", "three", "four", "five" };
    int nameIndex= 0;
   
    for (int i=1; i<=20; i++) {
      String filename = names[nameIndex++ % names.length];
     
      if (clientA.getLocalFile(filename).exists()) {
        clientA.deleteFile(filename);
      }
      else {
        clientA.createNewFile(filename);
      }
     
      clientA.up();   
    }
   
    // ROUND 2: sync down by B
    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=(11|12|13).+upload.+database", // << 3 retries!!
        }
            ));

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

    clientA.createNewFile("file");

    clientA.up();

    clientA.changeFile("file");
    clientA.upWithForceChecksum();

    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setKeepVersionsCount(1);
    boolean cleanupFailed = false;
    try {
      clientA.cleanup(cleanupOptions);
    }
    catch (StorageException e) {
      cleanupFailed = true;
    }

    assertTrue(cleanupFailed);
    TransferManager transferManager = new TransactionAwareTransferManager(
        new UnreliableLocalTransferPlugin().createTransferManager(testConnection, null), null);
    assertEquals(2, transferManager.list(MultichunkRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "multichunks").list().length);
    assertEquals(2, transferManager.list(DatabaseRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "databases").list().length);
    assertEquals(1, transferManager.list(TransactionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "transactions").list().length);
    assertEquals(1, transferManager.list(ActionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "actions").list().length);

    clientA.cleanup(cleanupOptions);
    assertEquals(1, transferManager.list(MultichunkRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "multichunks").list().length);
    assertEquals(3, transferManager.list(DatabaseRemoteFile.class).size());
    assertEquals(3, new File(testConnection.getPath(), "databases").list().length);
    assertEquals(0, transferManager.list(TransactionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "transactions").list().length);
    assertEquals(0, transferManager.list(ActionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "actions").list().length);

    clientA.deleteTestData();
  }
View Full Code Here

   
    // Setup
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
   
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    //Create ignore file and reload it
    File syncanyIgnore = clientA.getLocalFile(Config.FILE_IGNORE);
    TestFileUtil.createFileWithContent(syncanyIgnore, "ignoredfile.txt");
    clientA.getConfig().getIgnoredFiles().loadPatterns();
   
    // A new/up
    clientA.createNewFile("ignoredfile.txt")
    clientA.createNewFile("nonignoredfile.txt");
    clientA.up();
   
    clientB.down();

    // The ignored file should not exist at B
    assertTrue(clientA.getLocalFile("ignoredfile.txt").exists());
    assertTrue(clientA.getLocalFile("nonignoredfile.txt").exists());
    assertFalse(clientB.getLocalFile("ignoredfile.txt").exists());
    assertTrue(clientB.getLocalFile("nonignoredfile.txt").exists());
   
    //Delete ignore file and reload patterns
    TestFileUtil.deleteFile(syncanyIgnore);
    clientA.getConfig().getIgnoredFiles().loadPatterns();
    clientA.up();
   
    clientB.down();
   
    // All files should be synced
    assertTrue(clientA.getLocalFile("ignoredfile.txt").exists());
    assertTrue(clientA.getLocalFile("nonignoredfile.txt").exists());
    assertTrue(clientB.getLocalFile("ignoredfile.txt").exists());
    assertTrue(clientB.getLocalFile("nonignoredfile.txt").exists());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    TestFileUtil.deleteDirectory(tempDir);
  }
View Full Code Here

            // Format: abs=<count> rel=<count> op=<connect|init|upload|...> <operation description>
            "rel=(11|12|13).+upload.+database", // << 3 retries!!
        }
            ));

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

    clientA.createNewFile("file");

    clientA.up();

    clientA.changeFile("file");
    clientA.upWithForceChecksum();

    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMaxDatabaseFiles(1);
    boolean cleanupFailed = false;
    try {
      clientA.cleanup(cleanupOptions);
    }
    catch (StorageException e) {
      cleanupFailed = true;
    }

    assertTrue(cleanupFailed);
    TransferManager transferManager = new TransactionAwareTransferManager(
        new UnreliableLocalTransferPlugin().createTransferManager(testConnection, null), null);
    assertEquals(2, transferManager.list(MultichunkRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "multichunks").list().length);

    // Note that the list here differs from the actual files, because the transaction fails
    // while deletions have been done
    assertEquals(2, transferManager.list(DatabaseRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "databases").list().length);

    assertEquals(1, transferManager.list(TransactionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "transactions").list().length);

    assertEquals(1, transferManager.list(ActionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "actions").list().length);

    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    File tempFile = File.createTempFile("multichunk", "", tempDir);
    for (RemoteFile remoteFile : transferManager.list(DatabaseRemoteFile.class).values()) {
      transferManager.download(remoteFile, tempFile);
      assertTrue(tempFile.exists());
      tempFile.delete();
    }

    clientA.cleanup(cleanupOptions);

    assertEquals(2, transferManager.list(MultichunkRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "multichunks").list().length);

    assertEquals(1, transferManager.list(DatabaseRemoteFile.class).size());
View Full Code Here

            // Format: abs=<count> rel=<count> op=<connect|init|upload|...> <operation description>
            "rel=[678].+delete.+temp", // << 3 retries!!
        }
            ));

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

    clientA.createNewFile("file");

    clientA.up();

    clientA.changeFile("file");
    clientA.upWithForceChecksum();

    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMaxDatabaseFiles(1);
    boolean cleanupFailed = false;
    try {
      clientA.cleanup(cleanupOptions);
    }
    catch (StorageException e) {
      cleanupFailed = true;
    }

    TransferManager transferManager = new TransactionAwareTransferManager(
        new UnreliableLocalTransferPlugin().createTransferManager(testConnection, null), null);

    assertTrue(cleanupFailed);
    assertEquals(2, transferManager.list(MultichunkRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "multichunks").list().length);

    assertEquals(1, transferManager.list(DatabaseRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "databases").list().length);

    assertEquals(0, transferManager.list(TransactionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "transactions").list().length);

    assertEquals(1, transferManager.list(ActionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "actions").list().length);

    // Two temporary files left (first deletion failed)
    assertEquals(2, transferManager.list(TempRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "temporary").list().length);

    clientA.cleanup(cleanupOptions);

    // Functional cleanup results in removal of action file and unreferenced files
    assertEquals(0, transferManager.list(ActionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "actions").list().length);
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.