Exemplo n.º 1
0
void SQLUtility::execSQLFile(const string &sqlFile,
                             const string &ansFile,
                             const string &initFile) {
    FilePath fp;

    // do precheck for sqlFile & ansFile
    if (hawq::test::startsWith(sqlFile, "/") ||
            hawq::test::startsWith(ansFile, "/"))
        ASSERT_TRUE(false) << "For sqlFile and ansFile, relative path to feature "
                           "test root dir is needed";
    string ansFileAbsPath = testRootPath + "/" + ansFile;
    if (!std::ifstream(ansFileAbsPath))
        ASSERT_TRUE(false) << ansFileAbsPath << " doesn't exist";
    fp = splitFilePath(ansFileAbsPath);
    // double check to avoid empty fileBaseName
    if (fp.fileBaseName.empty())
        ASSERT_TRUE(false) << ansFileAbsPath << " is invalid";

    // generate new sql file with set search_path added at the begining
    const string newSqlFile = generateSQLFile(sqlFile);

    // outFile is located in the same folder with ansFile
    string outFileAbsPath = fp.path + "/" + fp.fileBaseName + ".out";
    conn->setOutputFile(outFileAbsPath);
    EXPECT_EQ(0, conn->runSQLFile(newSqlFile).getLastStatus());
    conn->resetOutput();

    // initFile if any
    string initFileAbsPath;
    if (!initFile.empty()) {
        initFileAbsPath = testRootPath + "/" + initFile;
        if (!std::ifstream(initFileAbsPath))
            ASSERT_TRUE(false) << initFileAbsPath << " doesn't exist";
        fp = splitFilePath(initFileAbsPath);
        // double check to avoid empty fileBaseName
        if (fp.fileBaseName.empty())
            ASSERT_TRUE(false) << initFileAbsPath << " is invalid";
    } else {
        initFileAbsPath = "";
    }

    bool is_sql_ans_diff = conn->checkDiff(ansFileAbsPath, outFileAbsPath, true, initFileAbsPath);
    EXPECT_FALSE(is_sql_ans_diff);
    if (is_sql_ans_diff == false) {
        // no diff, continue to delete the generated sql file
        if (remove(newSqlFile.c_str()))
            ASSERT_TRUE(false) << "Error deleting file " << newSqlFile;
    } else {
        EXPECT_FALSE(true);
    }
}
Exemplo n.º 2
0
void FSEventsService::dispatch(EventType action, std::string path) {
  std::string directory, name;

  splitFilePath(directory, name, path);

  mQueue.enqueue(action, directory, name);
}
Exemplo n.º 3
0
std::string SQLUtility::getTestRootPath() const {
  int ret;
  pid_t pid;
  char pathbuf[PROC_PIDPATHINFO_MAXSIZE];

  pid = getpid();
  ret = proc_pidpath(pid, pathbuf, sizeof(pathbuf));
  if (ret <= 0)
    EXPECT_TRUE(false) << "PID " << pid << ": proc_pidpath () "
                       << strerror(errno);
  return splitFilePath(pathbuf).path;
}
Exemplo n.º 4
0
bool SQLUtility::execSQLFile(const string &sqlFile) {
    // do precheck for sqlFile
    if (hawq::test::startsWith(sqlFile, "/"))
        return false;

    // double check to avoid empty fileBaseName
    FilePath fp = splitFilePath(sqlFile);
    if (fp.fileBaseName.empty())
        return false;

    // outFile is located in the same folder with ansFile
    string outFileAbsPath = "/tmp/" + fp.fileBaseName + ".out";

    // generate new sql file with set search_path added at the begining
    const string newSqlFile = generateSQLFile(sqlFile);

    // run sql file and store its result in output file
    conn->setOutputFile(outFileAbsPath);
    return conn->runSQLFile(newSqlFile).getLastStatus() == 0 ? true : false;
}
Exemplo n.º 5
0
void FSEventsService::rename(std::vector<std::string> *paths) {
  auto *binNamesByPath = new std::map<std::string, std::vector<std::string> *>;

  for (auto pathIterator = paths->begin(); pathIterator != paths->end(); ++pathIterator) {
    std::string directory, name;
    splitFilePath(directory, name, *pathIterator);
    if (binNamesByPath->find(directory) == binNamesByPath->end()) {
      (*binNamesByPath)[directory] = new std::vector<std::string>;
    }
    (*binNamesByPath)[directory]->push_back(name);
  }

  for (auto binIterator = binNamesByPath->begin(); binIterator != binNamesByPath->end(); ++binIterator) {
    if (binIterator->second->size() == 2) {
      std::string sideA = (*binIterator->second)[0],
                  sideB = (*binIterator->second)[1];
      std::string fullSideA = binIterator->first + "/" + sideA,
                  fullSideB = binIterator->first + "/" + sideB;
      struct stat renameSideA, renameSideB;
      bool sideAExists = stat(fullSideA.c_str(), &renameSideA) == 0,
           sideBExists = stat(fullSideB.c_str(), &renameSideB) == 0;

      if (sideAExists && !sideBExists) {
        mQueue.enqueue(RENAMED, binIterator->first, sideB, sideA);
      } else if (!sideAExists && sideBExists) {
        mQueue.enqueue(RENAMED, binIterator->first, sideA, sideB);
      } else {
        demangle(fullSideA);
        demangle(fullSideB);
      }

    } else {
      for (auto pathIterator = binIterator->second->begin(); pathIterator != binIterator->second->end(); ++pathIterator) {
        demangle(binIterator->first + "/" + *pathIterator);
      }
    }
    delete binIterator->second;
    binIterator->second = NULL;
  }
  delete binNamesByPath;
}
Exemplo n.º 6
0
string SQLUtility::getTestRootPath() const {
    string result;
#ifdef __linux__
    char pathbuf[PATH_MAX];
    ssize_t count = readlink("/proc/self/exe", pathbuf, PATH_MAX);
    if (count <= 0)
        EXPECT_TRUE(false) << "readlink /proc/self/exe error: " << strerror(errno);
    result = string(pathbuf, count);
#elif __APPLE__
    int ret;
    pid_t pid;
    char pathbuf[PROC_PIDPATHINFO_MAXSIZE];

    pid = getpid();
    ret = proc_pidpath(pid, pathbuf, sizeof(pathbuf));
    if (ret <= 0)
        EXPECT_TRUE(false) << "PID " << pid << ": proc_pidpath () "
                           << strerror(errno);
    result = string(pathbuf);
#endif
    return splitFilePath(result).path;
}