Package org.syncany.tests.util

Examples of org.syncany.tests.util.TestClient


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

    // Run
   
    // A, create two files with identical content and change mod. date of one of them
    clientA.createNewFile("A-file1.jpg", 50*1024);
    clientA.copyFile("A-file1.jpg", "A-file1-with-different-modified-date.jpg");   
    clientA.getLocalFile("A-file1.jpg").setLastModified(0);       
    clientA.up();   
   
    // B, down, then move BOTH files
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientB.moveFile("A-file1.jpg", "A-file1-moved.jpg");
    clientB.moveFile("A-file1-with-different-modified-date.jpg", "A-file1-with-different-modified-date-moved.jpg");       
    clientB.up();
   
    TestSqlDatabase clientDatabaseB = clientB.loadLocalDatabase();
   
    PartialFileHistory file1Orig = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-moved.jpg");
    PartialFileHistory file1WithDiffLastModDate = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-with-different-modified-date-moved.jpg");
   
    assertNotNull(file1Orig);
    assertNotNull(file1WithDiffLastModDate);
   
    FileVersion fileVersion1OrigV1 = file1Orig.getFileVersion(1);
    FileVersion fileVersion1OrigV2 = file1Orig.getFileVersion(2);
   
    FileVersion fileVersion1WithDiffLastModDateV1 = file1WithDiffLastModDate.getFileVersion(1);
    FileVersion fileVersion1WithDiffLastModDateV2 = file1WithDiffLastModDate.getFileVersion(2);
   
    assertNotNull(fileVersion1OrigV1);
    assertNotNull(fileVersion1OrigV2);
    assertNotNull(fileVersion1WithDiffLastModDateV1);
    assertNotNull(fileVersion1WithDiffLastModDateV2);
   
    assertEquals("A-file1.jpg", fileVersion1OrigV1.getName());
    assertEquals("A-file1-moved.jpg", fileVersion1OrigV2.getName());
    assertEquals("A-file1-with-different-modified-date.jpg", fileVersion1WithDiffLastModDateV1.getName());
    assertEquals("A-file1-with-different-modified-date-moved.jpg", fileVersion1WithDiffLastModDateV2.getName());
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here


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

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMergeRemoteFiles(true);
    options.setRemoveOldVersions(false);
    options.setMinSecondsBetweenCleanups(40000000);

    // Run

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

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

    for (int i = 1; i <= 15; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    // Because of minimum timeout, this cleanup should not do anything
    cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.NOK_RECENTLY_CLEANED, cleanupOperationResult.getResultCode());

    // When force is on, the cleanup should go through
    options.setForce(true);

    cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(16, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());

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

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

        "rel=(13|14|15).+move" // << 3 retries!
    }));

    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();

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

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setStatusOptions(forceChecksumStatusOperationOptions);
    options.setMergeRemoteFiles(true);
    options.setRemoveOldVersions(true);
    options.setMinSecondsBetweenCleanups(40000000);
    options.setForce(true);

    File repoDir = testConnection.getPath();
    File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
    File repoActionsDir = new File(testConnection.getPath() + "/actions");
    File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
    File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
    File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");

    // Run

    clientA.createNewFile("A-file1", 5 * 1024);
    clientA.up();

    for (int i = 0; i < 5; i++) {
      clientA.changeFile("A-file1");
      clientA.upWithForceChecksum();
    }

    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
   
    // Run cleanup, fails mid-move!
    boolean operationFailed = false;

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

    assertTrue(operationFailed);
    assertEquals(1, repoTransactionsDir.list().length);
    assertEquals(1, repoTemporaryDir.list().length);
    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
   
    // Retry
    clientA.cleanup(options);

    assertEquals(1, repoDatabasesDir.listFiles().length);
    assertEquals(5, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals(0, repoDir.list(new FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.startsWith("transaction-");
      }
    }).length);
    assertEquals(0, repoDir.list(new FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.startsWith("temp-");
      }
    }).length);
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
   

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

public class ManySyncUpsAndDatabaseFileCleanupScenarioTest {
  @Test
  public void testManySyncUpsAndDatabaseFileCleanup() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();   
    TestClient clientA = new TestClient("A", testConnection);
   
    // ROUND 1: many sync up (no cleanup expected here)   
    for (int i=1; i<=15; i++) {
      clientA.createNewFile("file"+i, 1);
      clientA.up();   
    }
   
    for (int i=1; i<=15; i++) {
      DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
      File expectedDatabaseFile = new File(testConnection.getPath()+"/databases/"+expectedDatabaseRemoteFile.getName());
     
      assertTrue("Database file SHOULD exist: "+expectedDatabaseFile, expectedDatabaseFile.exists());
    }

    // ROUND 2: 1x sync up (cleanup expected!)
    clientA.createNewFile("file16", 1);
    clientA.up();   
   
    clientA.cleanup(); // Force cleanup

    for (int i=1; i<=15; i++) {
      DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
      File expectedDatabaseFile = new File(testConnection.getPath()+"/databases/"+expectedDatabaseRemoteFile.getName());
     
      assertTrue("Database file should NOT exist: "+expectedDatabaseFile, !expectedDatabaseFile.exists());
    }
   
    for (int i=16; i<=16; i++) {
      DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
      File expectedDatabaseFile = new File(testConnection.getPath()+"/databases/"+expectedDatabaseRemoteFile.getName());
     
      assertTrue("Database file SHOULD exist: "+expectedDatabaseFile, expectedDatabaseFile.exists());
    }
   
    // ROUND 3: many sync up (no cleanup expected here)   
    for (int i=17; i<=30; i++) {
      clientA.createNewFile("file"+i, 1);
      clientA.up();   
    }
   
    for (int i=1; i<=15; i++) {
      DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
      File expectedDatabaseFile = new File(testConnection.getPath()+"/databases/"+expectedDatabaseRemoteFile.getName());
     
      assertTrue("Database file should NOT exist: "+expectedDatabaseFile, !expectedDatabaseFile.exists());
    }
   
    for (int i=16; i<=30; i++) {
      DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
      File expectedDatabaseFile = new File(testConnection.getPath()+"/databases/"+expectedDatabaseRemoteFile.getName());
     
      assertTrue("Database file SHOULD exist: "+expectedDatabaseFile, expectedDatabaseFile.exists());
    }   
   
    // ROUND 4: 1x sync up (cleanup expected!)
    clientA.createNewFile("file31", 1);
    clientA.up();   
   
    CleanupOperationOptions options = new CleanupOperationOptions();
   
    options.setForce(true);
   
    clientA.cleanup(options); // Force cleanup

    for (int i=1; i<=30; i++) {
      DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
      File expectedDatabaseFile = new File(testConnection.getPath()+"/databases/"+expectedDatabaseRemoteFile.getName());
     
      assertTrue("Database file should NOT exist: "+expectedDatabaseFile, !expectedDatabaseFile.exists());
    }
    
    for (int i=31; i<=31; i++) {
      DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
      File expectedDatabaseFile = new File(testConnection.getPath()+"/databases/"+expectedDatabaseRemoteFile.getName());
     
      assertTrue("Database file SHOULD exist: "+expectedDatabaseFile, expectedDatabaseFile.exists());
   
   
    // Tear down
    // TODO [medium] Test the content of these database files
    clientA.deleteTestData();   
  }
View Full Code Here

  @Ignore
  public void testMixedScenario1() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
   
    // Run
    clientC.createNewFile("C1");
    clientC.up();
    clientC.createNewFile("C2");
    clientC.up();
    clientC.createNewFile("C3");
    clientC.up();
   
    clientB.down(); // NO CONFLICT
    assertFileListEquals("Client B and C should be on the same versions.", clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());   

    clientC.createNewFile("C4"); // up without down! Evil!
    clientC.up();
   
    clientA.down(); // NO CONFLICT
    assertFileListEquals("Client A and C should be on the same versions.", clientA.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    assertEquals("Client A should have C4, client B should not", clientA.getLocalFilesExcludeLockedAndNoRead().size()-1, clientB.getLocalFilesExcludeLockedAndNoRead().size());
   
    clientB.createNewFile("B1,C3");
    clientB.up();
   
    clientA.createNewFile("A1,C4");
    clientA.up();
    clientA.createNewFile("A2,C4");
    clientA.up();
    clientA.createNewFile("A3,C4");
    clientA.up();
   
    clientB.down(); // CONFLICT 1
    fail("Add some asserts");
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    clientA.down(); // CONFLICT 2
    clientC.down(); // CONFLICT 3
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
   
    clientA.createNewFile("A4,C4");
    clientA.up();
    clientA.createNewFile("A5,C4");
    clientA.up();

    clientC.createNewFile("A3,C5");
    clientC.up();
    clientC.createNewFile("A3,C6");
    clientC.up();
    clientC.createNewFile("A3,C7");
    clientC.up();
   
    clientB.createNewFile("A3,B2,C4");
    clientB.up();       
    clientB.createNewFile("A3,B3,C4");
    clientB.up();   
    clientB.createNewFile("A3,B4,C4");
    clientB.up()
   
    clientA.createNewFile("A6,C4");
    clientA.up();
   
    clientB.createNewFile("A3,B5,C4");
    clientB.up()
   
    clientC.createNewFile("A3,C8");
    clientC.up();
       
    clientB.down(); // CONFLICT 4
    clientA.down(); // CONFLICT 5
    clientC.down(); // CONFLICT 6
   
    clientA.up();
    clientA.down();
   
    clientB.up();
    clientB.down();
   
    clientC.up();
    clientC.down();
       
    clientC.up();
    clientB.up();
   
    clientC.down(); // CONFLICT 7
    clientB.down(); // CONFLICT 8
    clientA.down(); // CONFLICT 9
   
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
   
    assertEquals("File list count does not match.", 19, clientA.getLocalFilesExcludeLockedAndNoRead().size());
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
  }
View Full Code Here

  @Test
  public void testEmptyFileCreateAndSync() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // A
    clientA.createNewFile("File|\u0002|", 100);
    clientA.up();   
   
    // B
    clientB.down();
    assertFileEquals(clientA.getLocalFile("File|\u0002|"), clientB.getLocalFile("File|\u0002|"));
    assertEquals(clientB.getLocalFile("File|\u0002|").length(), 100);

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

    // Scenario: A moves a file, but B creates another file at the same destination
   
    // 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());
   
    // A moves, and up
    clientA.moveFile("A-original", "A-moved");
    clientA.up();
   
    // B creates file at same location
    clientB.createNewFile("A-moved"); // << same as above
    clientB.down();
    assertConflictingFileExists("A-moved", clientB.getLocalFilesExcludeLockedAndNoRead());

    // Sync them
    clientB.sync();   
    clientA.sync();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());   
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

    // Scenario: A deletes a file that B has already moved
   
    // 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());
   
    // A moves, and up
    clientA.deleteFile("A-original");
    clientA.up();
   
    // B deletes, then down; this should not fail or throw exceptions
    clientB.moveFile("A-original", "B-moved");
    clientB.down();
    assertFalse("File A-orginal should not be recreated.", clientB.getLocalFile("A-original").exists());

    // Sync them
    clientB.sync();   
    clientA.sync();
    assertFalse("File A-orginal should not be recreated.", clientA.getLocalFile("A-original").exists());
    assertFalse("File A-orginal should not be recreated.", clientB.getLocalFile("A-original").exists());
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());   
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

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

    // Run
    clientA.createNewFolder("Somefolder");
    clientA.upWithForceChecksum();
   
    clientB.createNewFolder("Somefolder");
   
    if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
      Set<PosixFilePermission> expectedPosixPermissions = Files.getPosixFilePermissions(clientB.getLocalFile("Somefolder").toPath());
     
      Set<PosixFilePermission> changedPosixPermissions = PosixFilePermissions.fromString("rwxrwxrwx");
      Files.setPosixFilePermissions(clientB.getLocalFile("Somefolder").toPath(), changedPosixPermissions);
 
      clientB.down();
     
      assertEquals(1, clientB.getLocalFiles().size());
      assertEquals(PosixFilePermissions.toString(expectedPosixPermissions), PosixFilePermissions.toString(Files.getPosixFilePermissions(clientB.getLocalFile("Somefolder").toPath())));
    }
    else if (EnvironmentUtil.isWindows()) {
      DosFileAttributes expectedDosAttrs = Files.readAttributes(clientB.getLocalFile("Somefolder").toPath(), DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
     
      Files.setAttribute(clientB.getLocalFile("Somefolder").toPath(), "dos:hidden", true);
      Files.setAttribute(clientB.getLocalFile("Somefolder").toPath(), "dos:archive", true);
      Files.setAttribute(clientB.getLocalFile("Somefolder").toPath(), "dos:system", true);
      Files.setAttribute(clientB.getLocalFile("Somefolder").toPath(), "dos:readonly", true);
   
      clientB.down();
     
      assertEquals(1, clientB.getLocalFiles().size());
     
      DosFileAttributes actualDosAttrs = Files.readAttributes(clientB.getLocalFile("Somefolder").toPath(), DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
      assertEquals(LimitedDosFileAttributes.toString(expectedDosAttrs), LimitedDosFileAttributes.toString(actualDosAttrs));     
    }
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }   
View Full Code Here

  @Test
  public void testRestoreDeletedFile() throws Exception {
    // Setup
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();   
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile());
       
    // A new/up
    clientA.createNewFile("A-original");   
    clientA.upWithForceChecksum();
   
    String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
    assertNotNull(originalFileHistoryStr);
   
    FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
       
    // A "delete"
    File deletedFile = new File(tempDir, "A-original-DELETED");
    FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
           
    clientA.upWithForceChecksum();
   
    // A restore
    RestoreOperationOptions operationOptions = new RestoreOperationOptions();
   
    operationOptions.setFileHistoryId(originalFileHistoryId);
    operationOptions.setFileVersion(1);
   
    clientA.restore(operationOptions);
   
    assertTrue(clientA.getLocalFile("A-original (restored version 1)").exists());
    assertEquals(
        StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)),
        StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-original (restored version 1)"))));
    assertEquals(deletedFile.lastModified(), clientA.getLocalFile("A-original (restored version 1)").lastModified());
    assertEquals(deletedFile.length(), clientA.getLocalFile("A-original (restored version 1)").length());
   
    // Tear down
    clientA.deleteTestData();
    TestFileUtil.deleteDirectory(tempDir);
  }
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.