FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
testJob.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *********************************************************************/
22 /* include functions to test */
23 #include <testRun.h>
24 
25 /* scheduler includes */
26 #include <scheduler.h>
27 #include <job.h>
28 
29 #include <utils.h>
30 
35  return Prepare_Testing_Data(scheduler);
36 }
37 
38 /* ************************************************************************** */
39 /* ********** job function tests ******************************************** */
40 /* ************************************************************************** */
41 
55 {
56  scheduler_t* scheduler;
57  job_t* job;
58  arg_int* params;
59  int jq_pk;
60 
61  scheduler = scheduler_init(testdb, NULL);
62 
63  FO_ASSERT_PTR_NULL(scheduler->db_conn);
64  database_init(scheduler);
65  FO_ASSERT_PTR_NOT_NULL_FATAL(scheduler->db_conn);
66 
67  jq_pk = Prepare_Testing_Data_Job(scheduler);
68 
69  database_update_event(scheduler, NULL);
70 
71  job = g_tree_lookup(scheduler->job_list, &jq_pk);
72  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
73  job_verbose_event(scheduler, job);
74  FO_ASSERT_EQUAL(job->id, jq_pk);
75 
76  params = g_new0(arg_int, 1);
77  params->first = job;
78  params->second = jq_pk;
79  job_pause_event(scheduler, params);
80  FO_ASSERT_EQUAL(job->status, JB_PAUSED);
81 
82  params = g_new0(arg_int, 1);
83  params->first = job;
84  params->second = jq_pk;
85  job_restart_event(scheduler, params);
86  FO_ASSERT_EQUAL(job->status, JB_RESTART);
87 
88  params = g_new0(arg_int, 1);
89  params->first = job;
90  params->second = 1;
91  job_priority_event(scheduler, params);
92  FO_ASSERT_EQUAL(job->status, JB_RESTART);
93 
94  job_fail_event(scheduler, job);
95  FO_ASSERT_EQUAL(job->status, JB_FAILED);
96 
97  scheduler_update(scheduler);
98 
99  scheduler_destroy(scheduler);
100 }
101 
114 {
115  scheduler_t* scheduler;
116  job_t* job;
117  char* res = NULL;
118  uint32_t result = 0;
119  int jq_pk;
120 
121  scheduler = scheduler_init(testdb, NULL);
122  FO_ASSERT_PTR_NULL(scheduler->db_conn);
123  database_init(scheduler);
124  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
125 
126  jq_pk = Prepare_Testing_Data_Job(scheduler);
127 
128  database_update_event(scheduler, NULL);
129 
130  job = g_tree_lookup(scheduler->job_list, &jq_pk);
131  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
132 
133  res = job_next(job);
134  FO_ASSERT_STRING_EQUAL(res, "6");
135  job = next_job(scheduler->job_queue);
136  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
137  FO_ASSERT_EQUAL(job->id, 1);
138  job = peek_job(scheduler->job_queue);
139  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
140  FO_ASSERT_EQUAL(job->id, 1);
141  result = active_jobs(scheduler->job_list);
142  FO_ASSERT_EQUAL(result, 0);
143 
144  scheduler_destroy(scheduler);
145 }
146 
147 /* ************************************************************************** */
148 /* **** suite declaration *************************************************** */
149 /* ************************************************************************** */
150 
151 CU_TestInfo tests_job[] =
152 {
153  {"Test job_event", test_job_event },
154  {"Test job_fun", test_job_fun },
155  CU_TEST_INFO_NULL
156 };
PGconn * db_conn
The database connection.
Definition: scheduler.h:187
void job_verbose_event(scheduler_t *scheduler, job_t *job)
Definition: job.c:255
int Prepare_Testing_Data(scheduler_t *scheduler)
Definition: utils.c:32
void test_job_event()
Test for job events.
Definition: testJob.c:54
void job_pause_event(scheduler_t *scheduler, arg_int *params)
Event to pause a job.
Definition: job.c:323
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
Definition: scheduler.c:373
void database_init(scheduler_t *scheduler)
Definition: database.c:781
void database_update_event(scheduler_t *scheduler, void *unused)
Checks the job queue for any new entries.
Definition: database.c:852
GSequence * job_queue
heap of jobs that still need to be started
Definition: scheduler.h:184
int Prepare_Testing_Data_Job(scheduler_t *scheduler)
Definition: testJob.c:34
char * job_next(job_t *job)
Definition: job.c:621
void scheduler_update(scheduler_t *scheduler)
Update function called after every event.
Definition: scheduler.c:444
GTree * job_list
List of jobs that have been created.
Definition: scheduler.h:183
uint32_t active_jobs(GTree *job_list)
Gets the number of jobs that are not paused.
Definition: job.c:731
job_t * peek_job(GSequence *job_queue)
Gets the job that is at the top of the queue if there is one.
Definition: job.c:712
void job_restart_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:353
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
Definition: scheduler.c:260
job_t * next_job(GSequence *job_queue)
Gets the next job from the job queue.
Definition: job.c:692
void test_job_fun()
Test for job functions.
Definition: testJob.c:113
The job structure.
Definition: job.h:61
Definition: event.h:56
void job_priority_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:396
job_status status
The current status for the job.
Definition: job.h:72
void job_fail_event(scheduler_t *scheduler, job_t *job)
Events that causes a job to be marked a failed.
Definition: job.c:417
int32_t id
The identifier for this job.
Definition: job.h:84