Package org.syncany.tests.util

Examples of org.syncany.tests.util.TestClient


            "rel=[234].+move.+multichunk",
            "rel=(8|9|10).+upload.+transaction",
        }
            ));

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

    clientA.createNewFile("A-original", 5 * 1024 * 1024); // << larger than one multichunk!

    boolean firstUpFailed = false;

    try {
      clientA.up();
    }
    catch (StorageException e) {
      firstUpFailed = true;
      logger.log(Level.INFO, e.getMessage());
    }

    assertTrue(firstUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    File[] tempFiles = new File(testConnection.getPath() + "/temporary/").listFiles();

    assertEquals(2, tempFiles.length);
    assertTrue(tempFiles[0].length() > 500 * 1024 || tempFiles[1].length() > 500 * 1024); // The second multichunk should be >500 KB
    assertTrue(tempFiles[0].length() < 100 * 1024 || tempFiles[1].length() < 100 * 1024); // The database file should be <100 KB

    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);

    assertEquals(3, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(2).getRemoteFile().getName().contains("database-"));

    // 2. Double check if list() does not return the multichunk
    TransferManager transferManager = new TransactionAwareTransferManager(
        new UnreliableLocalTransferPlugin().createTransferManager(testConnection, null), null);
    Map<String, MultichunkRemoteFile> multiChunkList = transferManager.list(MultichunkRemoteFile.class);
    assertEquals(0, multiChunkList.size());

    // 3. Second try fails in the beginning, to see if cleanTransactions was successful
    boolean secondUpFailed = false;

    try {
      clientA.up();
    }
    catch (StorageException e) {
      secondUpFailed = true;
      logger.log(Level.INFO, e.getMessage());
    }

    assertTrue(secondUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(2, new File(testConnection.getPath() + "/actions/").listFiles().length); // Shouldn't this be 1
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    assertEquals(0, new File(testConnection.getPath() + "/").listFiles(new FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.contains("temp-");
      }
    }).length);

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


            "rel=[234].+move.+multichunk",
            "rel=[234].+delete.+temp",
        }
            ));

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

    clientA.createNewFile("A-original", 5 * 1024 * 1024); // << larger than one multichunk!

    boolean firstUpFailed = false;

    try {
      clientA.up();
    }
    catch (StorageException e) {
      firstUpFailed = true;
      logger.log(Level.INFO, e.getMessage());
    }

    assertTrue(firstUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    File[] tempFiles = new File(testConnection.getPath() + "/temporary").listFiles();

    assertEquals(2, tempFiles.length);
    assertTrue(tempFiles[0].length() > 500 * 1024 || tempFiles[1].length() > 500 * 1024); // The second multichunk should be >500 KB
    assertTrue(tempFiles[0].length() < 100 * 1024 || tempFiles[1].length() < 100 * 1024); // The database file should be <100 KB

    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);

    assertEquals(3, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(2).getRemoteFile().getName().contains("database-"));

    // 2. Double check if list() does not return the multichunk
    TransferManager transferManager = new TransactionAwareTransferManager(
        new UnreliableLocalTransferPlugin().createTransferManager(testConnection, null), null);
    Map<String, MultichunkRemoteFile> multiChunkList = transferManager.list(MultichunkRemoteFile.class);
    assertEquals(0, multiChunkList.size());

    // 3. Second try fails in the beginning, to see if cleanTransactions was successful
    boolean secondUpFailed = false;

    try {
      clientA.up();
    }
    catch (StorageException e) {
      secondUpFailed = true;
      logger.log(Level.INFO, e.getMessage());
    }

    assertTrue(secondUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(2, new File(testConnection.getPath() + "/actions/").listFiles().length); // left over, 2 failed ops
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(4, new File(testConnection.getPath() + "/temporary/").listFiles().length);

    // 4. Third try; this should finally succeed
    clientA.up();

    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(2, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length); // cleaned
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(4, new File(testConnection.getPath() + "/temporary/").listFiles().length); // cleaned

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

      return; // Skip test for Windows, no symlinks there!
    }

    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);

    // Run
    File symlinkFile = clientA.getLocalFile("symlink-name");
    FileUtil.createSymlink("/etc/hosts", symlinkFile);

    assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());

    UpOperationResult upResult = clientA.up();
    StatusOperationResult statusResult = upResult.getStatusResult();

    // Test 1: Check result sets for inconsistencies
    assertTrue("Status should return changes.", statusResult.getChangeSet().hasChanges());
    assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());

    // Test 2: Check database for inconsistencies
    SqlDatabase database = clientA.loadLocalDatabase();

    assertNotNull("File should be uploaded.", database.getFileVersionByPath("symlink-name"));
    assertNotNull("There should be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());

    // Test 3: Check file system for inconsistencies
    File repoPath = new File(((LocalTransferSettings) testConnection).getPath() + "/databases");
    String[] repoFileList = repoPath.list(new FilenameFilter() {
      @Override
      public boolean accept(File dir, String name) {
        return name.startsWith("database-");
      }
    });

    assertEquals("Repository should contain only ONE database file, not multichunks.", 1, repoFileList.length);

    // B down
    clientB.down();
    assertEquals("Local folder should contain one file (link!)", 1, clientB.getLocalFilesExcludeLockedAndNoRead().size());

    File localSymlinkFile = clientB.getLocalFile("symlink-name");
    assertTrue("Local symlink file should exist.", localSymlinkFile.exists());
    assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
    assertEquals("Local symlink file should point to actual target.", "/etc/hosts", FileUtil.readSymlinkTarget(localSymlinkFile));

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

      return; // Skip test for Windows, no symlinks there!
    }

    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);

    // Run
    clientA.createNewFile("symlink-target");

    File symlinkFile = clientA.getLocalFile("symlink-name");
    FileUtil.createSymlink("symlink-target", symlinkFile); // << relative target

    assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());

    clientA.up();

    // B down
    clientB.down();

    assertEquals("Local folder should contain two files (symlink and target!)", 2, clientB.getLocalFilesExcludeLockedAndNoRead().size());

    File localSymlinkFile = clientB.getLocalFile("symlink-name");

    assertTrue("Local symlink file should exist.", Files.exists(Paths.get(localSymlinkFile.getAbsolutePath()), LinkOption.NOFOLLOW_LINKS));
    assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
    assertEquals("Local symlink file should point to actual target.", "symlink-target", FileUtil.readSymlinkTarget(localSymlinkFile));

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

      return; // Skip test for Windows, no symlinks there!
    }

    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);

    // A
    clientA.createNewFolder("folder1");
    clientA.up();

    // B
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());

    // A
    File symlinkFile = clientA.getLocalFile("folder1/symlink-name");
    FileUtil.createSymlink("/does/not/exist", symlinkFile);
    clientA.up();

    // B
    clientB.deleteFile("folder1");
    clientB.down();
    assertTrue(FileUtil.exists(clientB.getLocalFile("folder1/symlink-name")));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());

    // Tear down
    clientA.deleteTestData();
    clientB.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);
   
    // Run
    clientA.createNewFile("A-file1.jpg", 0);
    clientA.up();   
   
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    clientB.createNewFile("B-file2", 0);
    clientB.moveFile("A-file1.jpg", "B-file1-moved");
    clientB.up();
   
    SqlDatabase database = clientB.loadLocalDatabase();
    DatabaseVersionHeader lastDatabaseVersionHeaderBeforeUp = database.getLastDatabaseVersionHeader();
   
    clientB.up(); // double-up, has caused problems
    DatabaseVersionHeader lastDatabaseVersionHeaderAfterUp = database.getLastDatabaseVersionHeader();

    assertEquals("Nothing changed. Local database file should not change.", lastDatabaseVersionHeaderBeforeUp, lastDatabaseVersionHeaderAfterUp);
   
    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

public class SingleFolderNoConflictsScenarioTest
  @Test
  public void testFolderEmptyNewNoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // Create files and upload
    clientA.createNewFolder("folder");   
    clientA.up();
   
    clientB.down();
    assertFileEquals(clientA.getLocalFile("folder"), clientB.getLocalFile("folder"));   
   
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
  }   
View Full Code Here

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

    // Create files and upload
    clientA.createNewFolder("folder");   
    clientA.up();
   
    clientB.down();
    clientB.moveFile("folder", "moved");
    clientB.up();
   
    clientA.down();
    assertFileEquals(clientA.getLocalFile("moved"), clientB.getLocalFile("moved"))
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
  }     
View Full Code Here

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

    // Create files and upload
    clientA.createNewFolder("folder");   
    clientA.up();
   
    clientB.down();
    clientB.deleteFile("folder");
    clientB.up();
   
    clientA.down()
    assertFalse("Deleted folder should not exist.", clientA.getLocalFile("folder").exists());   
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
 
View Full Code Here

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

    // Create files and upload
    clientA.createNewFolder("folder");   
    clientA.createNewFile("folder/file");
    clientA.up();
   
    clientB.down();
    assertFileEquals(clientA.getLocalFile("folder"), clientB.getLocalFile("folder"));
    assertFileEquals(clientA.getLocalFile("folder/file"), clientB.getLocalFile("folder/file"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    // Cleanup
    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.