Search in sources :

Example 66 with TestClient

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

the class FileLockedScenarioTest method testPermissionDeniedNotWritable.

@Test
public void testPermissionDeniedNotWritable() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    // Run
    File noReadPermissionFile = clientA.createNewFile("no-read-permission-file");
    noReadPermissionFile.setWritable(false, false);
    runUpAndTestForConsistentDatabase(testConnection, clientA);
    // Tear down
    clientA.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) RandomAccessFile(java.io.RandomAccessFile) LockFile(org.syncany.tests.integration.scenarios.framework.LockFile) File(java.io.File) UnlockFile(org.syncany.tests.integration.scenarios.framework.UnlockFile) Test(org.junit.Test)

Example 67 with TestClient

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

the class FileVanishedScenarioTest method testCallUpWhileDeletingFiles.

// TODO [low] If a file has vanished, are its chunks and multichunks still added to the database, and then uploaded? If so, fix this!
@Test
public void testCallUpWhileDeletingFiles() throws Exception {
    // Setup
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    final int numFiles = 100;
    final int numFilesVanished = 50;
    final int numFilesRemaining = numFiles - numFilesVanished;
    final int sizeFiles = 500 * 1024;
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMinKeepSeconds(0);
    // Prepare by creating test files
    logger.log(Level.INFO, "Creating test files ...");
    for (int i = 0; i <= numFiles; i++) {
        clientA.createNewFile("A-original" + i, sizeFiles);
    }
    // Prepare threads (delete & run up)
    Thread deleteFilesThread = new Thread(new Runnable() {

        @Override
        public void run() {
            for (int i = numFiles; i >= numFilesVanished; i--) {
                boolean deleteSuccess = clientA.deleteFile("A-original" + i);
                if (deleteSuccess) {
                    logger.log(Level.SEVERE, "Deleted " + clientA.getLocalFile("A-original" + i));
                } else {
                    logger.log(Level.SEVERE, "FAILED TO DELETE FILE " + clientA.getLocalFile("A-original" + i));
                }
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    logger.log(Level.FINE, "Thread interrupted", e);
                }
            }
        }
    }, "A-delete");
    Thread runUpThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(40);
                clientA.up();
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.getMessage());
            }
        }
    }, "A-up");
    // Before we start: init database (this takes a while)
    clientA.status();
    clientB.status();
    // Delete files and run up simultaneously
    // --> This will hopefully lead to a couple of 'vanished' files
    logger.log(Level.INFO, "Starting 'up' thread ...");
    runUpThread.start();
    logger.log(Level.INFO, "Starting 'delete' thread ...");
    deleteFilesThread.start();
    runUpThread.join();
    deleteFilesThread.join();
    // Test 1: There should be between 50 and 100 file histories in the database
    SqlDatabase databaseClientA = clientA.loadLocalDatabase();
    assertTrue("There should be less file histories than originally added files.", databaseClientA.getFileHistoriesWithFileVersions().size() < numFiles);
    assertTrue("There should be more (or equal size) file histories than files there are.", databaseClientA.getFileHistoriesWithFileVersions().size() >= numFilesRemaining);
    // Test 2: Now up the rest, there should be exactly 50 files in the database
    clientA.up();
    clientA.cleanup(options);
    databaseClientA = clientA.loadLocalDatabase();
    assertEquals("There should be EXACTLY " + numFilesRemaining + " file histories in the database.", numFilesRemaining, databaseClientA.getFileHistoriesWithFileVersions().size());
    // Test 3: After that, the sync between the clients should of course still work
    clientB.down();
    assertFileListEquals("Files of both clients should be identical.", clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) SqlDatabase(org.syncany.database.SqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 68 with TestClient

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

the class FileVanishedScenarioTest method testFolderVanishesWhenSyncingDown.

@Test
public void testFolderVanishesWhenSyncingDown() throws Exception {
    // 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
    clientA.createNewFile("folder1/file1");
    clientA.up();
    // B
    clientB.deleteFile("folder1");
    assertFalse(clientB.getLocalFile("folder1").exists());
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 69 with TestClient

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

the class FirstVersionDirtyScenarioTest method testFirstVersionDirty.

@Test
public void testFirstVersionDirty() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    UpOperationOptions forceUpOperationOptions = new UpOperationOptions();
    forceUpOperationOptions.setForceUploadEnabled(true);
    // Run
    clientA.createNewFile("A-file1.jpg", 1 * 1024 * 1024);
    clientA.up(forceUpOperationOptions);
    // B's timestamp must be later
    Thread.sleep(200);
    TestFileUtil.copyFile(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
    clientB.up(forceUpOperationOptions);
    // Client B loses
    // <<<<<<< This used to throw all sorts of PRIMARY KEY CONSTRAINT errors
    clientB.down();
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    TestAssertUtil.assertSqlDatabaseTablesEqual(clientA.getDatabaseFile(), clientB.getDatabaseFile(), new String[] { "chunk", "multichunk", "filecontent", "filecontent_chunk" });
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from filehistory", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from filehistory", databaseConnectionB));
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));
    // The table "multichunk_chunk" has 4 entries in B, but only 2 in A (!)
    // This is because the same file (= same chunks) are uploaded twice.
    // TODO [medium] The cleanup operation does not clean multichunks with redundant chunks, or does it?!
    assertEquals(2 * Integer.parseInt(TestSqlUtil.runSqlSelect("select count(*) from multichunk_chunk", databaseConnectionA)), Integer.parseInt(TestSqlUtil.runSqlSelect("select count(*) from multichunk_chunk", databaseConnectionB)));
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) Test(org.junit.Test)

Example 70 with TestClient

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

the class Issue143ScenarioTest method testChangeAttributes.

@Test
public void testChangeAttributes() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);
    cleanupOptions.setMinKeepSeconds(0);
    // Scenario, see
    // https://github.com/syncany/syncany/issues/143#issuecomment-50964685
    // Run
    clientA.createNewFile("file1.jpg");
    clientA.upWithForceChecksum();
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    TestFileUtil.copyFile(clientA.getLocalFile("file1.jpg"), clientA.getLocalFile("file1 (copy).jpg"));
    clientA.upWithForceChecksum();
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    clientA.deleteFile("file1 (copy).jpg");
    clientA.upWithForceChecksum();
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    // Database versions of deleted file are removed
    clientA.cleanup(cleanupOptions);
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    TestFileUtil.copyFile(clientA.getLocalFile("file1.jpg"), clientA.getLocalFile("file1 (copy).jpg"));
    clientA.upWithForceChecksum();
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    clientA.deleteFile("file1.jpg");
    clientA.upWithForceChecksum();
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    // Database version of deleted file is removed
    clientA.cleanup(cleanupOptions);
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    // <<<< This creates the exception in #143
    clientB.down();
    // integrity constraint violation: foreign key no parent; SYS_FK_10173 table: FILEVERSION
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) TransferSettings(org.syncany.plugins.transfer.TransferSettings) 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