} END_TEST

START_TEST(resuming_suspended_engine_processes_jobs) {
  ce_add_classification_job(ce, TAG_ID);
  ce_add_classification_job(ce, TAG_ID);
  assert_equal(2, ce_num_waiting_jobs(ce));
  int suspended = ce_suspend(ce);
  assert_true(suspended);
  ce_start(ce);
  ce_resume(ce);
  ce_stop(ce);
  assert_equal(0, ce_num_waiting_jobs(ce));
} END_TEST
} END_TEST

START_TEST(cancelling_a_job_sets_its_state_to_cancelled) {
  ClassificationJob *job = ce_add_classification_job(ce, TAG_ID);
  cjob_cancel(job);
  assert_equal(CJOB_STATE_CANCELLED, job->state);
} END_TEST
} END_TEST

START_TEST(retrieve_job_via_id) {
  ClassificationJob *job = ce_add_classification_job(ce, TAG_ID);
  assert_not_null(job);
  ClassificationJob *fetched_job = ce_fetch_classification_job(ce, job->id);
  assert_equal(job, fetched_job);
} END_TEST
} END_TEST

START_TEST (remove_classification_job_wont_removes_the_job_from_the_engines_job_index_if_job_is_not_complete) {
  ClassificationJob *job = ce_add_classification_job(ce, TAG_ID);

  int res = ce_remove_classification_job(ce, job, 0);
  assert_false(res);
  ClassificationJob *j2 = ce_fetch_classification_job(ce, job->id);
  assert_not_null(j2);
} END_TEST
} END_TEST

START_TEST (remove_classification_job_removes_the_job_from_the_engines_job_index_if_job_is_complete) {
  ClassificationJob *job = ce_add_classification_job(ce, TAG_ID);
  job->state = CJOB_STATE_COMPLETE;
  int res = ce_remove_classification_job(ce, job, 0);
  assert_true(res);
  ClassificationJob *j2 = ce_fetch_classification_job(ce, job->id);
  assert_null(j2);
} END_TEST
示例#6
0
文件: classify.c 项目: seangeo/winnow
static int classify_file(ClassificationEngine * engine, const char * tag) {
  ClassificationJob *job = ce_add_classification_job(engine, tag);
  ce_stop(engine);
  if (job->state != CJOB_STATE_COMPLETE) {
    char buffer[512];
    cjob_error_msg(job, buffer, 512);
    printf("Job not complete: %s\n", buffer);
    return EXIT_FAILURE;
  }
  
  return EXIT_SUCCESS;
}
} END_TEST

START_TEST(cancelling_a_job_removes_it_from_the_system_once_a_worker_gets_to_it) {
  ClassificationJob *job = ce_add_classification_job(ce, TAG_ID);
  char job_id[64];
  strncpy(job_id, job->id, 64);

  assert_equal(1, ce_num_waiting_jobs(ce));
  cjob_cancel(job);
  assert_equal(1, ce_num_waiting_jobs(ce));
  ce_start(ce);
  sleep(1);
  ce_stop(ce);
  assert_equal(0, ce_num_waiting_jobs(ce));
  assert_equal(0, ce_num_jobs_in_system(ce));

  ClassificationJob *j2 = ce_fetch_classification_job(ce, job_id);
  assert_null(j2);
} END_TEST
示例#8
0
文件: classify.c 项目: seangeo/winnow
static int classify_directory(ClassificationEngine * engine, const char * directory) {
  struct dirent **entries;  
  int num_entries = scandir(directory, &entries, select_atom_files, alphasort);
  
  if (num_entries > -1) {
    int i;    
    
    for (i = 0; i < num_entries; i++) {
      char buffer[MAXPATHLEN];
      snprintf(buffer, MAXPATHLEN, "file:%s/%s", directory, entries[i]->d_name);
      ce_add_classification_job(engine, buffer);
      free(entries[i]);
    }
    free(entries);
    ce_stop(engine);
    
    return EXIT_SUCCESS;
  }
  
  return EXIT_FAILURE;
}