Ejemplo n.º 1
0
  public static Config createTestLocalConfig(String machineName, TransferSettings connection)
      throws Exception {
    File tempLocalDir =
        TestFileUtil.createTempDirectoryInSystemTemp(
            createUniqueName("client-" + machineName, connection));
    tempLocalDir.mkdirs();

    RepoTO repoTO = createRepoTO();

    // Create config TO
    ConfigTO configTO = new ConfigTO();
    configTO.setMachineName(machineName + CipherUtil.createRandomAlphabeticString(20));

    // Get Masterkey
    SaltedSecretKey masterKey = getMasterKey();
    configTO.setMasterKey(masterKey);

    LocalConnection localConnection = (LocalConnection) connection;
    // Create connection TO
    Map<String, String> localConnectionSettings = new HashMap<String, String>();
    localConnectionSettings.put("path", localConnection.getRepositoryPath().getAbsolutePath());

    ConnectionTO connectionTO = new ConnectionTO();

    if (connection instanceof UnreliableLocalConnection) { // Dirty hack
      UnreliableLocalConnection unreliableConnection = (UnreliableLocalConnection) connection;
      String failingPatterns =
          StringUtil.join(unreliableConnection.getFailingOperationPatterns(), ",");

      localConnectionSettings.put("patterns", failingPatterns);

      connectionTO.setType("unreliable_local");
      connectionTO.setSettings(localConnectionSettings);
    } else {
      connectionTO.setType("local");
      connectionTO.setSettings(localConnectionSettings);
    }

    configTO.setConnectionTO(connectionTO);

    // Create
    Config config = new Config(tempLocalDir, configTO, repoTO);

    config.setConnection(connection);
    config.getAppDir().mkdirs();
    config.getCacheDir().mkdirs();
    config.getDatabaseDir().mkdirs();
    config.getLogDir().mkdirs();
    config.getStateDir().mkdirs();

    // Write to config folder (required for some tests)
    new Persister().write(configTO, new File(config.getAppDir() + "/" + Config.FILE_CONFIG));
    new Persister().write(repoTO, new File(config.getAppDir() + "/" + Config.FILE_REPO));

    return config;
  }
Ejemplo n.º 2
0
  public static InitOperationOptions createTestInitOperationOptions(String machineName)
      throws Exception {
    File tempLocalDir =
        TestFileUtil.createTempDirectoryInSystemTemp(
            createUniqueName("client-" + machineName, machineName));
    File tempRepoDir =
        TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("repo", machineName));
    tempLocalDir.mkdirs();
    tempRepoDir.mkdirs();

    RepoTO repoTO = createRepoTO();

    // Create config TO
    ConfigTO configTO = new ConfigTO();
    configTO.setMachineName(machineName + Math.abs(new Random().nextInt()));

    // Get Masterkey
    SaltedSecretKey masterKey = getMasterKey();
    configTO.setMasterKey(masterKey);

    // Create connection TO
    Map<String, String> localConnectionSettings = new HashMap<String, String>();
    localConnectionSettings.put("path", tempRepoDir.getAbsolutePath());

    ConnectionTO connectionTO = new ConnectionTO();
    connectionTO.setType("local");
    connectionTO.setSettings(localConnectionSettings);

    configTO.setConnectionTO(connectionTO);

    InitOperationOptions operationOptions = new InitOperationOptions();

    operationOptions.setLocalDir(tempLocalDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setRepoTO(repoTO);

    operationOptions.setEncryptionEnabled(cryptoEnabled);
    operationOptions.setCipherSpecs(CipherSpecs.getDefaultCipherSpecs());
    operationOptions.setPassword(cryptoEnabled ? "some password" : null);

    return operationOptions;
  }