1 package org.ogf.saga.job.run;
2
3 import java.text.DateFormat;
4 import java.text.ParseException;
5 import java.text.SimpleDateFormat;
6 import java.util.Date;
7 import java.util.Locale;
8
9 import org.apache.log4j.Logger;
10 import org.junit.Test;
11 import org.ogf.saga.job.Job;
12 import org.ogf.saga.job.JobDescription;
13 import org.ogf.saga.job.base.JobBaseTest;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public abstract class InfoTest extends JobBaseTest {
30 private Logger logger = Logger.getLogger(this.getClass());
31 private static final String FORMAT_DATETOSTRING = "EEE MMM dd HH:mm:ss z yyyy";
32
33 protected InfoTest(String jobprotocol) throws Exception {
34 super(jobprotocol);
35 }
36
37
38
39
40 @Test
41 public void test_exitcode() throws Exception {
42
43
44 JobDescription desc = createSimpleJob();
45
46
47 Job job = runJob(desc);
48 logger.info(job.getAttribute(Job.JOBID));
49
50
51 job.waitFor();
52 logger.info("Job finished.");
53
54
55 assertEquals(
56 String.valueOf(0),
57 job.getAttribute(Job.EXITCODE));
58 }
59
60
61
62
63 @Test
64 public void test_created() throws Exception {
65
66 Date now = new Date(new Date().getTime()/1000*1000);
67
68
69 JobDescription desc = createSimpleJob();
70
71
72 Job job = runJob(desc);
73 logger.info(job.getAttribute(Job.JOBID));
74
75
76 job.waitFor();
77 logger.info("Job finished.");
78
79
80 try {
81 Date creationTime = parse(job.getAttribute(Job.CREATED));
82 assertFalse(creationTime.before(now));
83 } catch (ParseException e) {
84 fail(e.getMessage());
85 }
86
87 }
88
89
90
91
92 @Test
93 public void test_dates() throws Exception {
94
95 Date now = new Date(new Date().getTime()/1000*1000);
96
97
98 JobDescription desc = createSimpleJob();
99
100
101 Job job = runJob(desc);
102 logger.info(job.getAttribute(Job.JOBID));
103
104
105 job.waitFor();
106 logger.info("Job finished.");
107
108
109 try {
110 Date startTime = parse(job.getAttribute(Job.STARTED));
111 Date endTime = parse(job.getAttribute(Job.FINISHED));
112
113 assertFalse(startTime.after(endTime));
114 } catch (ParseException e) {
115 fail(e.getMessage());
116 }
117
118 }
119
120
121
122
123 @Test
124 public void test_execution_hosts() throws Exception {
125
126
127 JobDescription desc = createSimpleJob();
128
129
130 Job job = runJob(desc);
131 logger.info(job.getAttribute(Job.JOBID));
132
133
134 job.waitFor();
135 logger.info("Job finished.");
136
137
138 String executionHosts[] = job.getVectorAttribute(Job.EXECUTIONHOSTS);
139 assertFalse(executionHosts == null);
140 assertTrue(executionHosts.length > 0);
141 for (int i=0; i<executionHosts.length; i++) {
142 assertNotNull(executionHosts[i]);
143 assertFalse(executionHosts[i].equals(""));
144 }
145 }
146
147
148 private Date parse(String date) throws ParseException {
149
150
151
152 DateFormat df = new SimpleDateFormat(FORMAT_DATETOSTRING, Locale.US);
153 return df.parse(date);
154
155 }
156 }