Search in sources :

Example 71 with TransferSettings

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

the class LongRunningLotsOfSmallFilesScenarioTest method testLotsOfSmallFiles.

@Test
public void testLotsOfSmallFiles() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    for (int i = 0; i < 10000; i++) {
        clientA.createNewFile("file" + i, 100 + i);
    }
    // This has caused a heap space exception
    clientA.up();
    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 72 with TransferSettings

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

the class CallUpWhileStillWritingFileScenarioTest method testUpWhileWritingFile.

@Test
public void testUpWhileWritingFile() throws Exception {
    // Setup
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    final File testFile = clientA.getLocalFile("large-test-file");
    final long testFileLength = 100 * 1024 * 1024;
    Thread writeFileThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                logger.log(Level.INFO, "Started thread to write file to " + testFile + "  ...");
                FileOutputStream fos = new FileOutputStream(testFile);
                Random randomEngine = new Random();
                byte[] buf = new byte[4096];
                int writtenLen = 0;
                while (writtenLen < testFileLength) {
                    randomEngine.nextBytes(buf);
                    fos.write(buf, 0, buf.length);
                    writtenLen += buf.length;
                }
                fos.close();
                logger.log(Level.INFO, "Ended thread to write file to " + testFile + "  ...");
            } catch (IOException e) {
                logger.log(Level.FINE, "Thread failed to write to file", e);
            }
        }
    }, "writerThread");
    // Before start: setup up databases (takes a while)
    clientA.status();
    clientB.status();
    // Run!
    writeFileThread.start();
    Thread.sleep(50);
    logger.log(Level.INFO, "Started clientA.up()");
    UpOperationResult upResult = clientA.up();
    StatusOperationResult statusResult = upResult.getStatusResult();
    logger.log(Level.INFO, "Ended clientA.up()");
    writeFileThread.join();
    // Test 1: Check result sets for inconsistencies
    assertTrue("Status command expected to return changes.", statusResult.getChangeSet().hasChanges());
    assertFalse("File should NOT be uploaded while still writing (no half-file upload).", upResult.getChangeSet().hasChanges());
    // Test 2: Check database for inconsistencies
    SqlDatabase database = clientA.loadLocalDatabase();
    assertEquals("File should NOT be uploaded while still writing (no half-file upload).", 0, database.getFileList("large-test-file", null, false, false, false, null).size());
    assertNull("There should NOT 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 NOT contain any files.", 0, repoFileList.length);
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) IOException(java.io.IOException) UpOperationResult(org.syncany.operations.up.UpOperationResult) FilenameFilter(java.io.FilenameFilter) Random(java.util.Random) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) FileOutputStream(java.io.FileOutputStream) SqlDatabase(org.syncany.database.SqlDatabase) File(java.io.File) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) Test(org.junit.Test)

Example 73 with TransferSettings

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

the class ChangedModifiedDateScenarioTest method testChangeModifiedDate.

@Test
public void testChangeModifiedDate() 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();
    FileUtils.copyFile(clientA.getLocalFile("file1.jpg"), clientB.getLocalFile("file1.jpg"));
    clientB.getLocalFile("file1.jpg").setLastModified(123456789);
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // 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 74 with TransferSettings

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

the class DirtyDatabaseScenarioTest method testDirtyCleanupDirty.

@Test
public void testDirtyCleanupDirty() 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);
    TestClient clientD = new TestClient("D", testConnection);
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
    upOptionsForceEnabled.setStatusOptions(statusOptions);
    upOptionsForceEnabled.setForceUploadEnabled(true);
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);
    cleanupOptions.setForce(true);
    // Run
    // // 1. CREATE FIRST DIRTY VERSION
    clientA.createNewFile("A-file1.jpg", 50 * 1024);
    // (A1)
    clientA.up(upOptionsForceEnabled);
    clientB.down();
    clientB.changeFile("A-file1.jpg");
    // (A1,B1)
    clientB.up(upOptionsForceEnabled);
    clientA.down();
    // conflict (winner)
    clientA.changeFile("A-file1.jpg");
    // (A2,B1)
    clientA.up(upOptionsForceEnabled);
    // conflict (loser)
    clientB.changeFile("A-file1.jpg");
    clientB.up(upOptionsForceEnabled);
    // don't care about the conflict, just continue
    clientA.createNewFolder("new folder at A");
    // (A3,B1)
    clientA.up(upOptionsForceEnabled);
    // don't care about the conflict, just continue
    clientB.createNewFolder("new folder at B");
    clientB.up(upOptionsForceEnabled);
    // resolve conflict (wins, no DIRTY)
    clientA.down();
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    // resolve conflict (loses, creates DIRTY version)
    clientB.down();
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
    assertEquals("(A1,B2)\n(A1,B3)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status='DIRTY' order by id", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionB));
    StatusOperationResult statusResultBAfterDirty = clientB.status();
    assertNotNull(statusResultBAfterDirty);
    ChangeSet changeSetBAfterDirty = statusResultBAfterDirty.getChangeSet();
    assertEquals(2, changeSetBAfterDirty.getNewFiles().size());
    TestAssertUtil.assertConflictingFileExists("A-file1.jpg", clientB.getLocalFiles());
    // (A3,B2)
    clientB.up(upOptionsForceEnabled);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
    // (A1), (A1,B1), (A2,B1), (A3,B1)
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionA));
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));
    // // 2. NOW THAT CLIENT B RESOLVED IT, A GETS DIRTY
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty1");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty2");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty3");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty4");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty5");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty6");
    clientA.up(upOptionsForceEnabled);
    // No 'down'! This version will become DIRTY
    clientA.changeFile("A-file1.jpg");
    clientA.createNewFile("dirty7");
    clientA.up(upOptionsForceEnabled);
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    clientA.down();
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("7", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionA));
    // Does nothing; A versions lose against (A3,B2) // same as above!
    clientB.down();
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));
    // // 3. NEW CLIENT JOINS
    clientC.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientB.getDatabaseFile(), clientC.getDatabaseFile());
    // // 4. FORCE MERGE DATABASES ON CLIENT A
    clientA.deleteFile("dirty1");
    clientA.deleteFile("dirty2");
    // upload DIRTY version
    clientA.up(upOptionsForceEnabled);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
    clientA.createNewFile("A-file2.jpg");
    // For every X up's call 'cleanup' ("X" is larger than the max. length of file versions in a history)
    int cleanupEveryXUps = 7;
    for (int i = 1; i <= 21; i++) {
        clientA.changeFile("A-file2.jpg");
        clientA.up(upOptionsForceEnabled);
        if (i % cleanupEveryXUps == 0) {
            clientA.cleanup(cleanupOptions);
        }
    }
    clientA.cleanup(cleanupOptions);
    clientB.down();
    clientC.down();
    clientD.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientD.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
    clientD.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) ChangeSet(org.syncany.operations.ChangeSet) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) Test(org.junit.Test)

Example 75 with TransferSettings

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

the class DirtyDatabaseScenarioTest method testDirtyDatabase.

@Test
public void testDirtyDatabase() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run
    UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
    upOptionsForceEnabled.setForceUploadEnabled(true);
    clientA.createNewFile("A-file1.jpg", 50 * 1024);
    clientA.up(upOptionsForceEnabled);
    clientB.createNewFile("A-file1.jpg", 51 * 1024);
    clientB.up(upOptionsForceEnabled);
    // This creates a dirty database
    clientB.down();
    // Test (for dirty database existence)
    Config configB = clientB.getConfig();
    java.sql.Connection databaseConnectionB = configB.createDatabaseConnection();
    ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnectionB);
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnectionB);
    FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnectionB);
    FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnectionB, fileVersionDao);
    FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnectionB);
    DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnectionB, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
    Iterator<DatabaseVersion> databaseVersionsDirtyB = databaseVersionDao.getDirtyDatabaseVersions();
    List<DatabaseVersion> databaseVersionsDirtyListB = TestCollectionUtil.toList(databaseVersionsDirtyB);
    assertEquals(1, databaseVersionsDirtyListB.size());
    DatabaseVersion dirtyDatabaseVersionB = databaseVersionsDirtyListB.get(0);
    assertNotNull(dirtyDatabaseVersionB);
    assertEquals(1, dirtyDatabaseVersionB.getFileHistories().size());
    PartialFileHistory fileHistoryFile1B = dirtyDatabaseVersionB.getFileHistories().iterator().next();
    assertNotNull(fileHistoryFile1B);
    assertEquals(1, fileHistoryFile1B.getFileVersions().size());
    assertEquals("A-file1.jpg", fileHistoryFile1B.getLastVersion().getPath());
    assertFileEquals(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
    assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead());
    // Run (part 2)
    // This deletes the dirty database file
    clientB.up();
    Iterator<DatabaseVersion> databaseVersionsDirtyB2 = databaseVersionDao.getDirtyDatabaseVersions();
    List<DatabaseVersion> databaseVersionsDirtyListB2 = TestCollectionUtil.toList(databaseVersionsDirtyB2);
    assertEquals(0, databaseVersionsDirtyListB2.size());
    // Run (part 3)
    // This pulls down the conflicting file
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    assertConflictingFileExists("A-file1.jpg", clientA.getLocalFilesExcludeLockedAndNoRead());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : Config(org.syncany.config.Config) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) PartialFileHistory(org.syncany.database.PartialFileHistory) ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) TestClient(org.syncany.tests.util.TestClient) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) 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