Search in sources :

Example 46 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class FileLockedScenarioTest method testFileLocked.

// TODO [high] Fix issues with readonly files on Windows, and r------ files on Linux
@Test
public void testFileLocked() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    // Run!
    clientA.createNewFile("locked-file");
    RandomAccessFile lockedFile = new RandomAccessFile(clientA.getLocalFile("locked-file"), "rw");
    FileLock lockedFileLock = lockedFile.getChannel().lock();
    runUpAndTestForEmptyDatabase(testConnection, clientA);
    // Tear down
    lockedFileLock.release();
    lockedFile.close();
    clientA.deleteTestData();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) TestClient(org.syncany.tests.util.TestClient) FileLock(java.nio.channels.FileLock) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 47 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings 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 48 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings 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 49 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings 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 50 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings 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)

Aggregations

TransferSettings (org.syncany.plugins.transfer.TransferSettings)78 Test (org.junit.Test)67 TestClient (org.syncany.tests.util.TestClient)65 File (java.io.File)20 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)10 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)7 SqlDatabase (org.syncany.database.SqlDatabase)5 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 CreateFileTree (org.syncany.tests.integration.scenarios.framework.CreateFileTree)4 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 Path (java.nio.file.Path)3 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)3 Config (org.syncany.config.Config)3 ConfigTO (org.syncany.config.to.ConfigTO)3 PartialFileHistory (org.syncany.database.PartialFileHistory)3 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)3