Search in sources :

Example 26 with LocalTransferSettings

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

the class ConnectOperationTest method testConnectOperationSuccess.

@Test
public void testConnectOperationSuccess() 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_TO);
    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)

Example 27 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)

Example 28 with LocalTransferSettings

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

the class PluginOperationTest method testPluginListLocalOnly.

@Test
public void testPluginListLocalOnly() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);
    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginOperationAction.LIST);
    pluginOptions.setListMode(PluginListMode.LOCAL);
    // Run
    PluginOperationResult pluginResult = client.plugin(pluginOptions);
    // for comparison only!
    List<Plugin> pluginList = Plugins.list();
    // Test
    assertNotNull(pluginResult);
    assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
    assertEquals(pluginList.size(), pluginResult.getPluginList().size());
    // local and unreliable_local
    assertEquals(EXPECTED_NUM_PLUGINS, pluginResult.getPluginList().size());
    for (ExtendedPluginInfo pluginInfo : pluginResult.getPluginList()) {
        assertNull(pluginInfo.getRemotePluginInfo());
        assertNotNull(pluginInfo.getLocalPluginInfo());
        assertNull(pluginInfo.getLocalPluginInfo().getDownloadUrl());
        assertNull(pluginInfo.getLocalPluginInfo().getSha256sum());
        assertNotNull(pluginInfo.getLocalPluginInfo().getPluginId());
        assertNotNull(pluginInfo.getLocalPluginInfo().getPluginVersion());
        // The rest is not important for processing ...
        assertNotNull(Plugins.get(pluginInfo.getLocalPluginInfo().getPluginId()));
    }
    // Tear down
    client.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) ExtendedPluginInfo(org.syncany.operations.plugin.ExtendedPluginInfo) TestClient(org.syncany.tests.util.TestClient) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) Plugin(org.syncany.plugins.Plugin) Test(org.junit.Test)

Example 29 with LocalTransferSettings

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

the class PluginOperationTest method testPluginListRemoteOnlyReleasesOnly.

@Test
public void testPluginListRemoteOnlyReleasesOnly() throws Exception {
    // Tests which plugin releases are available. This is difficult because
    // that will change. So we can only test the bare minimum.
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);
    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginOperationAction.LIST);
    pluginOptions.setListMode(PluginListMode.REMOTE);
    pluginOptions.setSnapshots(false);
    PluginOperationResult pluginResult = client.plugin(pluginOptions);
    assertNotNull(pluginResult);
    assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
    // Tear down
    client.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) Test(org.junit.Test)

Example 30 with LocalTransferSettings

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

the class SplitSyncUpOperationTest method testUploadLocalDatabase.

private void testUploadLocalDatabase(int fileSize, int fileAmount, int expectedTransactions, UpOperationOptions options) throws Exception {
    List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
    // Run!
    AbstractTransferOperation op = new UpOperation(testConfig, options);
    UpOperationResult opResult = (UpOperationResult) op.execute();
    // Ensure that the expected number of transactions has been completed to upload the files
    assertNotNull(opResult);
    assertTrue(opResult.getTransactionsCompleted() == expectedTransactions);
    // Get databases (for comparison)
    LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
    File localDatabaseDir = testConfig.getDatabaseDir();
    assertNotNull(localDatabaseDir.listFiles());
    assertTrue(localDatabaseDir.listFiles().length > 0);
    List<File> remoteDatabaseFiles = new ArrayList<>();
    for (int transaction = 1; transaction <= expectedTransactions; transaction++) {
        String databaseVersion = String.format("%010d", transaction);
        File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-" + databaseVersion);
        assertTrue(remoteDatabaseFile.exists());
        remoteDatabaseFiles.add(remoteDatabaseFile);
    }
    // Import remote databases into memory database
    DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
    MemoryDatabase remoteDatabase = new MemoryDatabase();
    for (File remoteDatabaseFile : remoteDatabaseFiles) {
        dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseXmlSerializer.DatabaseReadType.FULL);
    }
    // Open local SQL Database
    SqlDatabase localDatabase = new SqlDatabase(testConfig);
    // Compare!
    assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabase.getLastDatabaseVersion().getHeader());
    Map<PartialFileHistory.FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
    Collection<PartialFileHistory> remoteFileHistories = remoteDatabase.getFileHistories();
    assertEquals(localDatabase.getCurrentFileTree().size(), fileAmount);
    assertEquals(localFileHistories.size(), remoteDatabase.getFileHistories().size());
    List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
    List<FileVersion> localFileVersions = new ArrayList<FileVersion>();
    for (PartialFileHistory partialFileHistory : remoteFileHistories) {
        remoteFileVersions.add(partialFileHistory.getLastVersion());
        assertNotNull(localFileHistories.get(partialFileHistory.getFileHistoryId()));
    }
    for (PartialFileHistory partialFileHistory : localFileHistories.values()) {
        localFileVersions.add(partialFileHistory.getLastVersion());
    }
    assertTrue(CollectionUtil.containsExactly(localFileVersions, remoteFileVersions));
    compareFileVersionsAgainstOriginalFiles(originalFiles, localFileVersions);
    compareFileVersionsAgainstOriginalFiles(originalFiles, remoteFileVersions);
}
Also used : ArrayList(java.util.ArrayList) DatabaseXmlSerializer(org.syncany.database.dao.DatabaseXmlSerializer) UpOperationResult(org.syncany.operations.up.UpOperationResult) AbstractTransferOperation(org.syncany.operations.AbstractTransferOperation) UpOperation(org.syncany.operations.up.UpOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) File(java.io.File)

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