Search in sources :

Example 56 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class CleanupOperationTest method testEasyCleanup.

@Test
public void testEasyCleanup() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(true);
    options.setMinKeepSeconds(0);
    // Run
    // A: Create some file versions
    // These two files' chunks will be in one multichunk
    clientA.createNewFile("someotherfile.jpg");
    // Only one of the chunks will be needed after cleanup!
    clientA.createNewFile("file.jpg");
    // The multichunk will be 50% useless
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    clientA.createNewFile("otherfile.txt");
    for (int i = 1; i <= 3; i++) {
        clientA.changeFile("otherfile.txt");
        clientA.upWithForceChecksum();
    }
    clientA.createNewFile("deletedfile.txt");
    for (int i = 1; i <= 3; i++) {
        clientA.changeFile("deletedfile.txt");
        clientA.upWithForceChecksum();
    }
    clientA.deleteFile("deletedfile.txt");
    clientA.upWithForceChecksum();
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
    assertEquals("10", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionA));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionA));
    // B: Sync down by other client
    clientB.down();
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionB));
    assertEquals("10", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionB));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionB));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionB));
    // A: Cleanup this mess (except for two) <<<< This is the interesting part!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(11, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(7, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(4, cleanupOperationResult.getRemovedOldVersionsCount());
    // 1 version for "file.jpg", 1 versions for "otherfile.txt" and 1 version for "someotherfile.jpg"
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    // 4
    assertEquals("4", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='file.jpg'", databaseConnectionA));
    // 3
    assertEquals("3", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='otherfile.txt'", databaseConnectionA));
    assertEquals("1", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='someotherfile.jpg'", databaseConnectionA));
    // 3 chunks remain; one was obsolete so we removed it!
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
    // 3 chunks in 3 multichunks
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionA));
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionA));
    // Test the repo
    assertEquals(3, new File(testConnection.getPath() + "/multichunks/").list().length);
    assertEquals(1, new File(testConnection.getPath() + "/databases/").list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    // B: Sync down cleanup
    clientB.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) FilenameFilter(java.io.FilenameFilter) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 57 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class AllFilePossibilitiesScenarioTest method testAllPossibilities.

@Test
public void testAllPossibilities() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    ClientActions.run(clientA, new Executable() {

        @Override
        public void execute() throws Exception {
        // Nothing.
        }
    }, new AbstractClientAction[] { new CreateFileTree(), new ChangeContentWithoutFileSize(), new ChangeFileSize(), new ChangeLastModifiedDate(), new ChangePermissionsOfFile(), new ChangePermissionsOfFolder(), new ChangeSymlinkTarget(), new ChangeTypeFileToFolder(), new ChangeTypeFileToSymlinkWithNonExistingTarget(), new ChangeTypeFileToSymlinkWithTargetFile(), new ChangeTypeFileToSymlinkWithTargetFolder(), new ChangeTypeSymlinkWithNonExistingTargetToFile(), new ChangeTypeSymlinkWithTargetFileToFile(), new ChangeTypeSymlinkWithTargetFolderToFile(), new ChangeTypeSymlinkWithNonExistingTargetToFolder(), new ChangeTypeSymlinkWithTargetFileToFolder(), new ChangeTypeSymlinkWithTargetFolderToFolder(), new ChangeTypeFolderToFile(), new ChangeTypeFolderToSymlinkWithNonExistingTarget(), new ChangeTypeFolderToSymlinkWithTargetFile(), new ChangeTypeFolderToSymlinkWithTargetFolder(), new CreateFile(), new CreateFolder(), new CreateSymlinkToFile(), new CreateSymlinkToFolder(), new CreateSymlinkToNonExisting(), new DeleteFile(), new DeleteFolder(), new MoveFileToOtherFolder(), new MoveFileWithinFolder(), new MoveFolderToOtherFolder(), new MoveFolderWithinFolder() // new LockFile() and new UnlockFile() are not compatible with these tests
    }, new Executable() {

        @Override
        public void execute() throws Exception {
            clientA.upWithForceChecksum();
            clientB.down();
            assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
            assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
        }
    });
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : ChangeTypeSymlinkWithTargetFolderToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFolderToFolder) CreateSymlinkToFile(org.syncany.tests.integration.scenarios.framework.CreateSymlinkToFile) ChangeContentWithoutFileSize(org.syncany.tests.integration.scenarios.framework.ChangeContentWithoutFileSize) ChangeTypeFolderToSymlinkWithNonExistingTarget(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToSymlinkWithNonExistingTarget) CreateFile(org.syncany.tests.integration.scenarios.framework.CreateFile) ChangeTypeFileToSymlinkWithTargetFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithTargetFolder) MoveFolderWithinFolder(org.syncany.tests.integration.scenarios.framework.MoveFolderWithinFolder) TestClient(org.syncany.tests.util.TestClient) CreateFileTree(org.syncany.tests.integration.scenarios.framework.CreateFileTree) ChangePermissionsOfFile(org.syncany.tests.integration.scenarios.framework.ChangePermissionsOfFile) ChangePermissionsOfFolder(org.syncany.tests.integration.scenarios.framework.ChangePermissionsOfFolder) ChangeTypeFolderToSymlinkWithTargetFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToSymlinkWithTargetFolder) Executable(org.syncany.tests.integration.scenarios.framework.Executable) DeleteFolder(org.syncany.tests.integration.scenarios.framework.DeleteFolder) ChangeTypeFolderToSymlinkWithTargetFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToSymlinkWithTargetFile) DeleteFile(org.syncany.tests.integration.scenarios.framework.DeleteFile) ChangeTypeSymlinkWithNonExistingTargetToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithNonExistingTargetToFile) CreateSymlinkToNonExisting(org.syncany.tests.integration.scenarios.framework.CreateSymlinkToNonExisting) ChangeFileSize(org.syncany.tests.integration.scenarios.framework.ChangeFileSize) MoveFileWithinFolder(org.syncany.tests.integration.scenarios.framework.MoveFileWithinFolder) ChangeTypeSymlinkWithTargetFolderToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFolderToFile) TransferSettings(org.syncany.plugins.transfer.TransferSettings) ChangeTypeFileToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToFolder) ChangeTypeFileToSymlinkWithTargetFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithTargetFile) CreateSymlinkToFolder(org.syncany.tests.integration.scenarios.framework.CreateSymlinkToFolder) ChangeSymlinkTarget(org.syncany.tests.integration.scenarios.framework.ChangeSymlinkTarget) ChangeTypeSymlinkWithTargetFileToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFileToFolder) ChangeLastModifiedDate(org.syncany.tests.integration.scenarios.framework.ChangeLastModifiedDate) ChangeTypeFileToSymlinkWithNonExistingTarget(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithNonExistingTarget) CreateFolder(org.syncany.tests.integration.scenarios.framework.CreateFolder) ChangeTypeSymlinkWithTargetFileToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFileToFile) ChangeTypeSymlinkWithNonExistingTargetToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithNonExistingTargetToFolder) MoveFolderToOtherFolder(org.syncany.tests.integration.scenarios.framework.MoveFolderToOtherFolder) ChangeTypeFolderToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToFile) MoveFileToOtherFolder(org.syncany.tests.integration.scenarios.framework.MoveFileToOtherFolder) Test(org.junit.Test)

Example 58 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class AllFilePossibilitiesScenarioTest method testChangeTypeSymlinkWithTargetFileToFolder.

@Test
public void testChangeTypeSymlinkWithTargetFileToFolder() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    ClientActions.run(clientA, null, new CreateFileTree(), null);
    ClientActions.run(clientA, null, new ChangeTypeFileToSymlinkWithTargetFolder(), null);
    clientA.upWithForceChecksum();
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : ChangeTypeFileToSymlinkWithTargetFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithTargetFolder) TestClient(org.syncany.tests.util.TestClient) CreateFileTree(org.syncany.tests.integration.scenarios.framework.CreateFileTree) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 59 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class ChangedAttributesScenarioTest method testNewFileWithDifferingAttributes.

@Test
public void testNewFileWithDifferingAttributes() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create new file with differing attributes
    clientA.createNewFile("file1.jpg");
    FileUtils.copyFile(clientA.getLocalFile("file1.jpg"), clientB.getLocalFile("file1.jpg"));
    // Client B's attributes differ!
    File aFile = clientA.getLocalFile("file1.jpg");
    Path aFilePath = Paths.get(aFile.getAbsolutePath());
    Object aReadOnlyAttribute = null;
    Set<PosixFilePermission> aPosixFilePermissions = null;
    // Client B's attributes differ!
    File bFile = clientB.getLocalFile("file1.jpg");
    Path bFilePath = Paths.get(bFile.getAbsolutePath());
    if (EnvironmentUtil.isWindows()) {
        aReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
        Files.setAttribute(bFilePath, "dos:readonly", true);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        aPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
        Files.setPosixFilePermissions(bFilePath, PosixFilePermissions.fromString("rwxrwxrwx"));
    }
    clientA.upWithForceChecksum();
    // This is the key operation
    DownOperationResult downResult = clientB.down();
    // Test 1: Check result sets for inconsistencies
    assertTrue("File should be downloaded.", downResult.getChangeSet().hasChanges());
    // Test 2: file1.jpg permissions (again!
    if (EnvironmentUtil.isWindows()) {
        Object bReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
        assertEquals("Read-only should be true.", aReadOnlyAttribute, bReadOnlyAttribute);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        Set<PosixFilePermission> bPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
        assertEquals("Should be rwxrwxrwx.", PosixFilePermissions.toString(aPosixFilePermissions), PosixFilePermissions.toString(bPosixFilePermissions));
    }
    // Test 3: The rest
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) ChangeSet(org.syncany.operations.ChangeSet) DownOperationResult(org.syncany.operations.down.DownOperationResult) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) File(java.io.File) Test(org.junit.Test)

Example 60 with TestClient

use of org.syncany.tests.util.TestClient in project syncany by syncany.

the class ChangedAttributesScenarioTest method testChangeAttributes.

@Test
public void testChangeAttributes() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run
    clientA.createNewFile("file1.jpg");
    clientA.upWithForceChecksum();
    clientB.down();
    File bFile = clientB.getLocalFile("file1.jpg");
    Path bFilePath = Paths.get(bFile.getAbsolutePath());
    if (EnvironmentUtil.isWindows()) {
        Files.setAttribute(bFilePath, "dos:readonly", true);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        Files.setPosixFilePermissions(bFilePath, PosixFilePermissions.fromString("rwxrwxrwx"));
    }
    StatusOperationResult statusResult = clientB.status();
    assertNotNull(statusResult);
    ChangeSet changes = statusResult.getChangeSet();
    assertTrue("Status-Operation should return changes.", changes.hasChanges());
    UpOperationResult upResult = clientB.up();
    StatusOperationResult statusResultFromUp = upResult.getStatusResult();
    // Test 1: Check result sets for inconsistencies
    assertTrue("Status should return changes.", statusResultFromUp.getChangeSet().hasChanges());
    assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());
    // Test 2: Check database for inconsistencies
    SqlDatabase database = clientB.loadLocalDatabase();
    assertEquals("File should be uploaded.", 1, database.getFileList("file1.jpg", null, false, false, false, null).size());
    assertEquals("There should be a new database version, because file should not have been added.", 2, database.getLocalDatabaseBranch().size());
    // B down
    clientA.down();
    // Test 1: file1.jpg permissions
    File aFile = clientA.getLocalFile("file1.jpg");
    Path aFilePath = Paths.get(aFile.getAbsolutePath());
    if (EnvironmentUtil.isWindows()) {
        Object readOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
        assertTrue("Read-only should be true.", (Boolean) readOnlyAttribute);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(aFilePath);
        assertEquals("Should be rwxrwxrwx.", "rwxrwxrwx", PosixFilePermissions.toString(posixFilePermissions));
    }
    // Test 2: The rest
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) ChangeSet(org.syncany.operations.ChangeSet) TestClient(org.syncany.tests.util.TestClient) SqlDatabase(org.syncany.database.SqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) ChangeSet(org.syncany.operations.ChangeSet) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Aggregations

TestClient (org.syncany.tests.util.TestClient)126 Test (org.junit.Test)122 TransferSettings (org.syncany.plugins.transfer.TransferSettings)65 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)53 File (java.io.File)50 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)31 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)28 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)23 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)14 FilenameFilter (java.io.FilenameFilter)11 StorageException (org.syncany.plugins.transfer.StorageException)11 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)10 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)10 DownOperationResult (org.syncany.operations.down.DownOperationResult)9 UpOperationResult (org.syncany.operations.up.UpOperationResult)8 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6 SqlDatabase (org.syncany.database.SqlDatabase)5 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)5 PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)5 PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)5