Search in sources :

Example 41 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class Issue520NoResumeOnCorruptXmlScenarioTest method testCorruptTransactionFile.

@Test
public void testCorruptTransactionFile() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    clientA.createNewFile("file1.txt", 1024);
    clientA.upWithForceChecksum();
    TestFileUtil.createFileWithContent(new File(clientA.getConfig().getAppDir(), "/state/transaction-list.txt"), "0000000001");
    TestFileUtil.createFileWithContent(new File(clientA.getConfig().getAppDir(), "/state/transaction-database.0000000001.xml"), "invalid");
    clientA.createNewFile("file2.txt", 1024);
    // This did FAIL due to an XML parsing exception
    clientA.upWithForceChecksum();
    assertEquals("There should be exactly two database files", 2, new File(testConnection.getPath() + "/databases").listFiles().length);
    assertEquals("There should be exactly two multichunks", 2, new File(testConnection.getPath() + "/multichunks").listFiles().length);
    // Tear down
    clientA.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) File(java.io.File) Test(org.junit.Test)

Example 42 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class Issue520NoResumeOnCorruptXmlScenarioTest method testCorruptTransactionListFile.

@Test
public void testCorruptTransactionListFile() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    clientA.createNewFile("file1.txt", 1024);
    clientA.upWithForceChecksum();
    TestFileUtil.createFileWithContent(new File(clientA.getConfig().getAppDir(), "/state/transaction-list.txt"), "INVALID");
    clientA.createNewFile("file2.txt", 1024);
    // This did FAIL due to an XML parsing exception
    clientA.upWithForceChecksum();
    assertEquals("There should be exactly two database files", 2, new File(testConnection.getPath() + "/databases").listFiles().length);
    assertEquals("There should be exactly two multichunks", 2, new File(testConnection.getPath() + "/multichunks").listFiles().length);
    // Tear down
    clientA.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) File(java.io.File) Test(org.junit.Test)

Example 43 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class ManySyncUpsLargeFileScenarioTest method testManySyncUpsWithLargeFile.

@Test
public void testManySyncUpsWithLargeFile() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Cause Cleanup with a moderately large file
    for (int i = 1; i <= 16; i++) {
        clientA.createNewFile("file" + i, 600181);
        TestFileUtil.changeRandomPartOfBinaryFile(clientA.getLocalFile("file" + i));
        if (i > 2) {
            TestFileUtil.changeRandomPartOfBinaryFile(clientA.getLocalFile("file" + (i - 1)));
            TestFileUtil.changeRandomPartOfBinaryFile(clientA.getLocalFile("file1"));
        }
        clientA.up();
    }
    clientB.down();
    for (int i = 1; i <= 16; i++) {
        assertTrue(clientA.getLocalFile("file" + i).exists());
        assertTrue(clientB.getLocalFile("file" + i).exists());
    }
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Test(org.junit.Test)

Example 44 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class MoveFolderWithQuotesOnWindowsScenario method testMoveFolderWithQuotes_issue124.

@Test
public void testMoveFolderWithQuotes_issue124() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create folder with file without quotes
    clientA.createNewFolder("folder_without_quotes");
    clientA.createNewFile("folder_without_quotes/file");
    clientA.up();
    // Sync to B
    clientB.down();
    // Now we should move to a folder with quotes, e.g.  folder "with" quotes
    // To make this work on Windows, we first move the folder and then modify
    // the database file on the remote storage to mock it
    clientA.moveFile("folder_without_quotes", "folder_with_quotes");
    clientA.up();
    for (File databaseFile : new File(testConnection.getPath() + "/databases/").listFiles()) {
        String databaseFileA2Content = IOUtils.toString(new FileInputStream(databaseFile), "UTF-8");
        String databaseFileA2NewContent = databaseFileA2Content.replaceAll("folder_with_quotes", "folder &quot;with&quot; quotes");
        IOUtils.write(databaseFileA2NewContent, new FileOutputStream(databaseFile));
    }
    // << In issue 124, this failed because we tried to move the inner "file" to the folder with quotes
    clientB.down();
    if (EnvironmentUtil.isWindows()) {
        assertTrue(clientB.getLocalFile("folder with quotes (filename conflict)").exists());
        assertTrue(clientB.getLocalFile("folder with quotes (filename conflict)/file").exists());
    } else {
        assertTrue(clientB.getLocalFile("folder \"with\" quotes").exists());
        assertTrue(clientB.getLocalFile("folder \"with\" quotes/file").exists());
    }
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 45 with LocalTransferSettings

use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.

the class ConnectOperationTest method testConnectOperationWithLink.

@Test
public void testConnectOperationWithLink() throws Exception {
    // A.init()
    InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
    InitOperationResult initOperationResultA = initOperationA.execute();
    String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
    assertNotNull(connectLinkA);
    // B.connect()
    File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("clientB", initOperationOptionsA));
    File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
    ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
    connectionConfigToB.setMachineName("clientB" + Math.abs(new Random().nextInt()));
    connectionConfigToB.setMasterKey(null);
    ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
    connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_LINK);
    connectOperationOptionsB.setConnectLink(connectLinkA);
    connectOperationOptionsB.setConfigTO(connectionConfigToB);
    connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
    connectOperationOptionsB.setLocalDir(localDirB);
    ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
    ConnectOperationResult connectOperationResultB = connectOperationB.execute();
    assertEquals(ConnectResultCode.OK, connectOperationResultB.getResultCode());
    assertTrue(new File(localConnectDirB, Config.DIR_DATABASE).exists());
    assertTrue(new File(localConnectDirB, Config.DIR_CACHE).exists());
    assertTrue(new File(localConnectDirB, Config.FILE_CONFIG).exists());
    assertTrue(new File(localConnectDirB, Config.DIR_LOG).exists());
    assertTrue(new File(localConnectDirB, Config.FILE_REPO).exists());
    assertEquals(new File(localConnectDirB, Config.FILE_MASTER).exists(), TestConfigUtil.getCrypto());
    File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(localConnectDirB);
    TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
    TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
Also used : ConnectOperationResult(org.syncany.operations.init.ConnectOperationResult) InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) Random(java.util.Random) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) ConnectOperation(org.syncany.operations.init.ConnectOperation) ConfigTO(org.syncany.config.to.ConfigTO) File(java.io.File) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions) Test(org.junit.Test)

Aggregations

LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)61 Test (org.junit.Test)50 TestClient (org.syncany.tests.util.TestClient)46 File (java.io.File)33 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)21 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)17 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)13 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)8 FilenameFilter (java.io.FilenameFilter)7 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)7 UpOperationResult (org.syncany.operations.up.UpOperationResult)7 Random (java.util.Random)6 ConfigTO (org.syncany.config.to.ConfigTO)6 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)6 SqlDatabase (org.syncany.database.SqlDatabase)5 PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)5 PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)5 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)4 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 InitOperation (org.syncany.operations.init.InitOperation)4