public static void assertFileListEqualsExcludeLockedAndNoRead(
      File expectedFilesRoot, File actualFilesRoot) throws ArrayComparisonFailure, Exception {
    Map<String, File> expectedFiles =
        TestFileUtil.getLocalFilesExcludeLockedAndNoRead(expectedFilesRoot);
    Map<String, File> actualFiles =
        TestFileUtil.getLocalFilesExcludeLockedAndNoRead(actualFilesRoot);

    assertFileListEquals("File list does not match", expectedFiles, actualFiles);
  }
Exemplo n.º 2
0
  public static void deleteTestLocalConfigAndData(Config config) {
    TestFileUtil.deleteDirectory(config.getLocalDir());
    TestFileUtil.deleteDirectory(config.getCacheDir());
    TestFileUtil.deleteDirectory(config.getDatabaseDir());

    if (config.getAppDir() != null) {
      TestFileUtil.deleteDirectory(config.getAppDir());
    }

    // TODO [low] workaround: delete empty parent folder of getAppDir() --> ROOT/app/.. --> ROOT/
    config.getLocalDir().getParentFile().delete(); // if empty!

    deleteTestLocalConnection(config);
  }
  protected void setUp() {
    super.setUp();
    testUtil = new TestUtil();
    fileUtil = new TestFileUtil();
    utils = new Utils(fileUtil, new Shell.Factory(), new Streams(), new Threads(), new Str());

    baseDir = new File(fileUtil.testDir(), "MRTest");
    dataDir = new File(baseDir, "data");
    fileUtil.deleteTree(baseDir);
    if (baseDir.exists()) {
      warn("residual files");
    }

    mysqldResource = new MysqldResource(baseDir, dataDir, null, System.out, System.err, utils);
    mysqldResource.setKillDelay(testUtil.testKillDelay());
  }
Exemplo n.º 4
0
 private File addPasswordFile() throws IOException {
   passwordFile = TestFileUtil.createTempFile("password.properties");
   passwordFile.deleteOnExit();
   final String nonAdmin = "jez=ThmbShxAtJepX80c2JY1FzOEmUk=\n"; // in plain text: badger
   final String admin1 = "admin1=W6ph5Mm5Pz8GgiULbPgzG37mj9g=\n"; // in plain text: password
   FileUtils.writeStringToFile(passwordFile, nonAdmin + admin1);
   return passwordFile;
 }
 public void testDestroyShell() {
   /** TODO: improve this test */
   startMysql("DestroyMe");
   assertTrue(mysqldResource.isRunning());
   mysqldResource.destroyShell();
   if (mysqldResource.isRunning()) {
     new MysqldResource(fileUtil.nullFile()).shutdown();
   }
 }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
  public static Map<String, String> createTestLocalConnectionSettings() throws Exception {
    Map<String, String> pluginSettings = new HashMap<String, String>();

    File tempRepoDir =
        TestFileUtil.createTempDirectoryInSystemTemp(
            createUniqueName("repo", new Random().nextFloat()));
    pluginSettings.put("path", tempRepoDir.getAbsolutePath());

    return pluginSettings;
  }
Exemplo n.º 8
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;
  }
Exemplo n.º 9
0
  public static FileVersion createFileVersion(String path) {
    FileVersion fileVersion = new FileVersion();

    fileVersion.setChecksum(new FileChecksum(TestFileUtil.createRandomArray(20)));
    fileVersion.setLastModified(new Date());
    fileVersion.setPath(path);
    fileVersion.setStatus(FileStatus.NEW);
    fileVersion.setType(FileType.FILE);
    fileVersion.setUpdated(new Date());
    fileVersion.setVersion(1L);

    return fileVersion;
  }
Exemplo n.º 10
0
  @Before
  public void setUp() throws Exception {
    tempFolder =
        TestFileUtil.createTempFolder("tempCommandLineTestFolder-" + System.currentTimeMillis());
    toDelete.add(tempFolder);

    subFolder = new File(tempFolder, "subFolder");
    subFolder.mkdirs();
    File file = new File("./originalCommand");
    file.createNewFile();
    file.setExecutable(true);
    toDelete.add(file);
  }
 protected void tearDown() {
   utils.threads().pause(50);
   try {
     if (mysqldResource.isRunning()) {
       mysqldResource.setKillDelay(testUtil.testKillDelay());
       mysqldResource.shutdown();
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   fileUtil.deleteTree(baseDir);
   super.tearDown();
 }
Exemplo n.º 12
0
  public static UnreliableLocalConnection createTestUnreliableLocalConnectionWithoutInit(
      UnreliableLocalPlugin unreliableLocalPlugin, List<String> failingOperationPatterns)
      throws Exception {
    UnreliableLocalConnection unreliableLocalConnection =
        (UnreliableLocalConnection) unreliableLocalPlugin.createSettings();

    File tempRepoDir =
        TestFileUtil.createTempDirectoryInSystemTemp(
            createUniqueName("repo", new Random().nextFloat()));

    unreliableLocalConnection.setRepositoryPath(tempRepoDir);
    unreliableLocalConnection.setFailingOperationPatterns(failingOperationPatterns);
    return unreliableLocalConnection;
  }
Exemplo n.º 13
0
  public static TransferSettings createTestLocalConnection() throws Exception {
    TransferPlugin plugin = Plugins.get("local", TransferPlugin.class);
    TransferSettings conn = plugin.createSettings();

    File tempRepoDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("repo", conn));

    Map<String, String> pluginSettings = new HashMap<String, String>();
    pluginSettings.put("path", tempRepoDir.getAbsolutePath());

    conn.init(pluginSettings);

    plugin.createTransferManager(conn).init(true);

    return conn;
  }
Exemplo n.º 14
0
 private GoConfigFileHelper(String xml, GoConfigDao goConfigDao) {
   new SystemEnvironment().setProperty(SystemEnvironment.ENFORCE_SERVERID_MUTABILITY, "N");
   this.originalXml = xml;
   assignFileDao(goConfigDao);
   try {
     File dir = TestFileUtil.createTempFolder("server-config-dir");
     this.configFile = new File(dir, "cruise-config.xml");
     configFile.deleteOnExit();
     sysEnv = new SystemEnvironment();
     sysEnv.setProperty(SystemEnvironment.CONFIG_FILE_PROPERTY, configFile.getAbsolutePath());
     initializeConfigFile();
   } catch (IOException e) {
     throw bomb("Error creating config file", e);
   }
 }
  private static boolean conflictingFileExists(String originalFile, Map<String, File> actualFiles) {
    String fileNameWithoutExtention = TestFileUtil.getBasename(originalFile);
    Pattern conflictFilePattern = Pattern.compile(fileNameWithoutExtention + ".*conflicted.*");

    boolean conflictingFileFound = false;

    for (Map.Entry<String, File> actualFileEntry : actualFiles.entrySet()) {
      File actualFile = actualFileEntry.getValue();
      Matcher matcher = conflictFilePattern.matcher(actualFile.getName());

      if (matcher.matches()) {
        conflictingFileFound = true;
        break;
      }
    }

    return conflictingFileFound;
  }
  public static void assertFileEquals(
      File expectedFile, File actualFile, FileChange... allowedChanges)
      throws ArrayComparisonFailure, Exception {
    if (expectedFile == null && actualFile == null) {
      return;
    }

    assertNotNull(
        "Files are not equal: Actual file is " + actualFile + ", expected file is null.",
        expectedFile);
    assertNotNull(
        "Files are not equal: Expected file is " + expectedFile + ", actual file is null.",
        actualFile);

    Path root = Paths.get(actualFile.getAbsolutePath()).getRoot();
    FileVersionComparator fileVersionComparator = new FileVersionComparator(root.toFile(), "SHA1");

    if (!FileUtil.exists(expectedFile)) {
      fail("Files are not equal: Expected file " + expectedFile + " does not exist.");
    }

    if (!FileUtil.exists(actualFile)) {
      fail("Files are not equal: Actual file " + actualFile + " does not exist.");
    }

    if (FileUtil.isSymlink(actualFile) && FileUtil.isSymlink(expectedFile)) {
      return;
    }

    if (actualFile.isDirectory() != expectedFile.isDirectory()) {
      fail(
          "Files are not equal: Comparing a directory with a file (actual is dir = "
              + actualFile.isDirectory()
              + ", expected is dir = "
              + expectedFile.isDirectory()
              + ")");
    }

    if (actualFile.isDirectory() && expectedFile.isDirectory()) {
      return;
    }

    if (actualFile.length() != expectedFile.length()) {
      fail(
          "Files are not equal: Actual file size ("
              + actualFile
              + " = "
              + actualFile.length()
              + ") does not match expected file size ("
              + expectedFile
              + " = "
              + expectedFile.length()
              + ")");
    }

    byte[] expectedFileChecksum = TestFileUtil.createChecksum(expectedFile);
    byte[] actualFileChecksum = TestFileUtil.createChecksum(actualFile);

    assertArrayEquals(
        "Files are not equal: Actual file checksum ("
            + StringUtil.toHex(actualFileChecksum)
            + ") and expected file checksum ("
            + StringUtil.toHex(expectedFileChecksum)
            + ") do not match.",
        expectedFileChecksum,
        actualFileChecksum);

    FileProperties actualFileProperties =
        fileVersionComparator.captureFileProperties(actualFile, null, true);
    FileProperties expectedFileProperties =
        fileVersionComparator.captureFileProperties(expectedFile, null, true);

    FileVersionComparison fileVersionComparison =
        fileVersionComparator.compare(expectedFileProperties, actualFileProperties, true);

    List<FileChange> allowedChangesList = new ArrayList<FileChange>(Arrays.asList(allowedChanges));
    allowedChangesList.add(FileChange.CHANGED_PATH);

    if (!CollectionUtil.containsOnly(fileVersionComparison.getFileChanges(), allowedChangesList)) {
      fail(
          "Files are not equal: Actual file differs from expected file: "
              + fileVersionComparison.getFileChanges());
    }
  }
Exemplo n.º 17
0
 private static void deleteTestLocalConnection(Config config) {
   LocalConnection connection = (LocalConnection) config.getConnection();
   TestFileUtil.deleteDirectory(connection.getRepositoryPath());
 }
 public void testGetMysqldLinux() {
   setSytemPropertiesToLinux();
   checkMysqldFile();
   assertTrue(fileUtil.madeExecutable(mysqldResource.getMysqldFilePointer()));
 }