use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class TestConfigUtil method createTestUnreliableInitOperationOptions.
public static InitOperationOptions createTestUnreliableInitOperationOptions(String machineName, List<String> failingOperationPatterns) throws Exception {
InitOperationOptions initOperationOptions = createTestInitOperationOptions(machineName);
// createTestInitOperationOptions always returns LocalTransferSettings
File tempRpoDir = ((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath();
UnreliableLocalTransferSettings transferSettings = Plugins.get("unreliable_local", TransferPlugin.class).createEmptySettings();
transferSettings.setPath(tempRpoDir);
transferSettings.setFailingOperationPatterns(failingOperationPatterns);
initOperationOptions.getConfigTO().setTransferSettings(transferSettings);
return initOperationOptions;
}
use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class TransferSettingsTest method testDeserializeCorrectClass.
@Test
public void testDeserializeCorrectClass() throws Exception {
Serializer serializer = new Persister();
InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
// Always LocalTransferSettings
serializer.write(initOperationOptions.getConfigTO(), tmpFile);
ConfigTO confRestored = ConfigTO.load(tmpFile);
assertEquals(LocalTransferSettings.class, confRestored.getTransferSettings().getClass());
// Tear down
FileUtils.deleteDirectory(initOperationOptions.getLocalDir());
FileUtils.deleteDirectory(((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath());
}
use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class ConnectOperationTest method testConnectOperationFailureNoConnection.
@Test
public void testConnectOperationFailureNoConnection() 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("client-B", initOperationOptionsA));
File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
// <<< Point to non-existing repo
((LocalTransferSettings) connectionConfigToB.getTransferSettings()).setPath(new File("/does/not/exist"));
connectionConfigToB.setMachineName("client-B" + 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.NOK_TEST_FAILED, connectOperationResultB.getResultCode());
assertFalse(new File(localConnectDirB, Config.DIR_DATABASE).exists());
assertFalse(new File(localConnectDirB, Config.DIR_CACHE).exists());
assertFalse(new File(localConnectDirB, Config.FILE_CONFIG).exists());
assertFalse(new File(localConnectDirB, Config.DIR_LOG).exists());
assertFalse(new File(localConnectDirB, Config.FILE_REPO).exists());
// Tear down
TestFileUtil.deleteDirectory(repoDir);
TestFileUtil.deleteDirectory(localConnectDirB);
TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class InitOperationTest method testInitOperation.
@Test
public void testInitOperation() throws Exception {
InitOperationOptions operationOptions = TestConfigUtil.createTestInitOperationOptions("A");
InitOperation op = new InitOperation(operationOptions, null);
InitOperationResult res = op.execute();
File repoDir = ((LocalTransferSettings) operationOptions.getConfigTO().getTransferSettings()).getPath();
File localDir = new File(operationOptions.getLocalDir(), ".syncany");
// Test the repository
assertTrue((new File(repoDir, "databases").exists()));
assertTrue((new File(repoDir, "syncany").exists()));
assertTrue((new File(repoDir, "multichunks").exists()));
assertEquals((new File(repoDir, "master").exists()), TestConfigUtil.getCrypto());
// Test the local folder
assertTrue((new File(localDir, Config.DIR_DATABASE).exists()));
assertTrue((new File(localDir, Config.DIR_CACHE).exists()));
assertTrue((new File(localDir, Config.FILE_CONFIG).exists()));
assertTrue((new File(localDir, Config.DIR_LOG).exists()));
assertTrue((new File(localDir, Config.FILE_REPO).exists()));
assertEquals((new File(localDir, Config.FILE_MASTER).exists()), TestConfigUtil.getCrypto());
// Test the existance of generated link
String link = res.getGenLinkResult().getShareLink();
assertNotNull(link);
TestFileUtil.deleteDirectory(repoDir);
TestFileUtil.deleteDirectory(operationOptions.getLocalDir());
}
use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class InitOperationTest method testFaultyInitOperation.
@Test
public void testFaultyInitOperation() throws Exception {
// Create an unreliable connection
List<String> failingOperationsPattern = Lists.newArrayList("rel=1.*op=upload");
InitOperationOptions operationOptions = TestConfigUtil.createTestUnreliableInitOperationOptions("A", failingOperationsPattern);
InitOperation op = new InitOperation(operationOptions, null);
File repoDir = ((UnreliableLocalTransferSettings) operationOptions.getConfigTO().getTransferSettings()).getPath();
File localDir = new File(operationOptions.getLocalDir(), ".syncany");
try {
op.execute();
} catch (StorageException e) {
logger.log(Level.INFO, "This operation failed because of the unreliable connection.", e);
}
// The local directory should not exist, since the uploading of the repo file fails
// so the local directories should be removed
assertFalse(localDir.exists());
// Tear down
TestFileUtil.deleteDirectory(repoDir);
TestFileUtil.deleteDirectory(operationOptions.getLocalDir());
}
Aggregations