| 814 |
mhunt |
1 |
package com.erggroup.buildtool.utf;
|
|
|
2 |
|
|
|
3 |
import com.erggroup.buildtool.daemon.BuildDaemon;
|
|
|
4 |
|
|
|
5 |
import com.erggroup.buildtool.daemon.BuildThread;
|
|
|
6 |
import com.erggroup.buildtool.daemon.MasterThread;
|
|
|
7 |
import com.erggroup.buildtool.daemon.SlaveThread;
|
|
|
8 |
import com.erggroup.buildtool.ripple.MutableString;
|
|
|
9 |
import com.erggroup.buildtool.ripple.ReleaseManager;
|
|
|
10 |
|
|
|
11 |
import com.erggroup.buildtool.ripple.RippleEngine;
|
|
|
12 |
|
|
|
13 |
import java.io.File;
|
|
|
14 |
import java.io.FileReader;
|
|
|
15 |
import java.io.FileWriter;
|
|
|
16 |
import java.io.IOException;
|
|
|
17 |
|
|
|
18 |
import org.apache.log4j.Logger;
|
|
|
19 |
import org.apache.log4j.xml.DOMConfigurator;
|
|
|
20 |
|
|
|
21 |
import org.junit.AfterClass;
|
|
|
22 |
import org.junit.BeforeClass;
|
|
|
23 |
import org.junit.After;
|
|
|
24 |
import org.junit.Before;
|
|
|
25 |
import org.junit.Test;
|
|
|
26 |
import org.junit.runner.JUnitCore;
|
|
|
27 |
import static org.junit.Assert.*;
|
|
|
28 |
|
|
|
29 |
/**container of Build Daemon test methods
|
|
|
30 |
*/
|
|
|
31 |
public class DaemonBuildTestCase
|
|
|
32 |
{
|
|
|
33 |
private static final Logger mLogger = Logger.getLogger(DaemonBuildTestCase.class);
|
|
|
34 |
|
|
|
35 |
public DaemonBuildTestCase()
|
|
|
36 |
{
|
|
|
37 |
mLogger.debug("DaemonBuildTestCase");
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
/**Test Case main line
|
|
|
41 |
*/
|
|
|
42 |
public static void main(String[] args)
|
|
|
43 |
{
|
|
|
44 |
DOMConfigurator.configure("utf.xml");
|
|
|
45 |
mLogger.debug("main");
|
|
|
46 |
JUnitCore.main( "com.erggroup.buildtool.utf.DaemonBuildTestCase" );
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**set up performed prior to any test method
|
|
|
50 |
*/
|
|
|
51 |
@BeforeClass
|
|
|
52 |
public static void TestCaseSetUp()
|
|
|
53 |
{
|
|
|
54 |
mLogger.debug("TestCaseSetUp");
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**tear down performed after test methods
|
|
|
58 |
*/
|
|
|
59 |
@AfterClass
|
|
|
60 |
public static void TestCaseTearDown()
|
|
|
61 |
{
|
|
|
62 |
mLogger.debug("TestCaseTearDown");
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**set up performed prior to each test method
|
|
|
66 |
*/
|
|
|
67 |
@Before
|
|
|
68 |
public void TestSetUp()
|
|
|
69 |
{
|
|
|
70 |
mLogger.debug("TestSetUp");
|
|
|
71 |
ReleaseManager.mUseDatabase = false;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/**tear down performed after each test method
|
|
|
75 |
*/
|
|
|
76 |
@After
|
|
|
77 |
public void TestTearDown()
|
|
|
78 |
{
|
|
|
79 |
mLogger.debug("TestTearDown");
|
|
|
80 |
ReleaseManager.mUseDatabase = true;
|
|
|
81 |
ReleaseManager.mPersistedRunLevelCollection.removeAllElements();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**test method designed primarily to test the sequence diagram spawn thread
|
|
|
85 |
* also tests thread control out of necessity:
|
|
|
86 |
* 1 constructs a BuildDaemon object, passing a connectionString of "unit test spawn thread"
|
|
|
87 |
* this utilises the following unit test hooks in the codebase:
|
|
|
88 |
* - BuildDaemon::BuildDaemon connectionString of "unit test spawn thread" exits while forever loop
|
|
|
89 |
* - BuildDaemon constructor, isActive and cleanUp made public for unit test use
|
|
|
90 |
* - ReleaseManager::queryReleaseConfig instantiates 2 ReleaseConfig objects
|
|
|
91 |
* with rcon_id's of 1 and 2, daemon_modes of 'M' and 'S' respectively, and gbebuildfilters of "unit test spawn thread"
|
|
|
92 |
* - MasterThread::run gbebuildfilter of "unit test spawn thread" limits method to sleep in while forever loop
|
|
|
93 |
* - SlaveThread::run gbebuildfilter of "unit test spawn thread" limits method to sleep in while forever loop
|
|
|
94 |
* 2 checks the number of threads in the thread group is 3 (mainline thread + MasterThread + SlaveThread)
|
|
|
95 |
* 3 checks isActive on the BuildDaemon object returns true when passed an rcon_id of 1
|
|
|
96 |
* 4 checks isActive on the BuildDaemon object returns true when passed an rcon_id of 2
|
|
|
97 |
* 5 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 3
|
|
|
98 |
* 6 calls cleanUp on the BuildDaemon object
|
|
|
99 |
* 7 checks the number of threads in the thread group is 1 (mainline thread)
|
|
|
100 |
* 8 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 1
|
|
|
101 |
* 9 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 2
|
|
|
102 |
* 10 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 3
|
|
|
103 |
*/
|
|
|
104 |
@Test
|
|
|
105 |
public void TestSpawnThread()
|
|
|
106 |
{
|
|
|
107 |
mLogger.debug("TestSpawnThread");
|
|
|
108 |
BuildDaemon buildDaemon =
|
|
|
109 |
new BuildDaemon("unit test spawn thread", "not used", "not used");
|
|
|
110 |
assertTrue(BuildThread.mThreadGroup.activeCount() == 2 );
|
|
|
111 |
assertTrue(buildDaemon.isActive(1));
|
|
|
112 |
assertTrue(buildDaemon.isActive(2));
|
|
|
113 |
assertFalse(buildDaemon.isActive(3));
|
|
|
114 |
buildDaemon.cleanUp();
|
|
|
115 |
assertTrue(BuildThread.mThreadGroup.activeCount() == 0);
|
|
|
116 |
assertFalse(buildDaemon.isActive(1));
|
|
|
117 |
assertFalse(buildDaemon.isActive(2));
|
|
|
118 |
assertFalse(buildDaemon.isActive(3));
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**test method designed to test the sequence diagram coordinate slave thread:
|
|
|
122 |
* 1 constructs a ReleaseManager object, passing a connectionString of "unit test coordinate slave threads"
|
|
|
123 |
* 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test coordinate slave threads"
|
|
|
124 |
* this utilises the following unit test hooks in the codebase:
|
|
|
125 |
* - MasterThread constructor made public for unit test use
|
|
|
126 |
* - MasterThread::run gbebuildfilter of "unit test coordinate slave threads" limits method to the sequence diagram
|
|
|
127 |
* interrupts the thread if, on one pass, at least one RunLevel object does not have a run level DB_WAITING
|
|
|
128 |
* exits the while forever loop if, on one pass, all RunLevel objects have a run level DB_WAITING
|
|
|
129 |
* - ReleaseManager::queryRunLevel connectionString of "unit test coordinate slave threads" instantiates 2 RunLevel objects
|
|
|
130 |
* initially with run levels of waiting and idle
|
|
|
131 |
* subsequently with run levels both waiting
|
|
|
132 |
* 3 calls run on the MasterThread object
|
|
|
133 |
* 4 checks its thread has been interrupted
|
|
|
134 |
*/
|
|
|
135 |
@Test
|
|
|
136 |
public void TestCoordinateSlaveThreads()
|
|
|
137 |
{
|
|
|
138 |
mLogger.debug("TestCoordinateSlaveThreads");
|
|
|
139 |
ReleaseManager releaseManager = new ReleaseManager("unit test coordinate slave threads", "not used", "not used");
|
|
|
140 |
MasterThread masterThread = new MasterThread(1, 1, "unit test coordinate slave threads");
|
| 864 |
mhunt |
141 |
assertFalse(Thread.interrupted());
|
| 814 |
mhunt |
142 |
masterThread.run();
|
|
|
143 |
// interrupted checks and importantly clears the interrupted status of this thread for subsequent tests
|
| 864 |
mhunt |
144 |
assertTrue(Thread.interrupted());
|
|
|
145 |
assertFalse(Thread.interrupted());
|
| 814 |
mhunt |
146 |
}
|
|
|
147 |
|
|
|
148 |
/**test method designed to test the sequence diagram generate build files
|
|
|
149 |
* note does not test the RippleEngine:
|
|
|
150 |
* 1 constructs a ReleaseManager object, passing a connectionString of "unit test generate build files"
|
|
|
151 |
* 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test generate build files"
|
|
|
152 |
* this utilises the following unit test hooks in the codebase:
|
|
|
153 |
* - MasterThread constructor made public for unit test use
|
|
|
154 |
* - MasterThread::run gbebuildfilter of "unit test generate build files" limits method to the sequence diagram
|
|
|
155 |
* exits the while forever loop
|
|
|
156 |
* - ReleaseManager::queryReleaseConfig instantiates 2 ReleaseConfig objects
|
|
|
157 |
* with rcon_id's of 1 and 2, daemon_modes of 'M' and 'S' respectively, and gbebuildfilters of "unit test spawn thread"
|
|
|
158 |
* - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
|
|
|
159 |
* 3 calls run on the MasterThread object
|
|
|
160 |
* 4 checks the first persisted run level is DB_ACTIVE
|
|
|
161 |
* 5 checks the second persisted run level is DB_ACTIVE
|
|
|
162 |
* 6 checks no further run levels were persisted
|
|
|
163 |
*/
|
|
|
164 |
@Test
|
|
|
165 |
public void TestGenerateBuildFiles()
|
|
|
166 |
{
|
|
|
167 |
mLogger.debug("TestGenerateBuildFiles");
|
|
|
168 |
ReleaseManager releaseManager = new ReleaseManager("unit test generate build files", "not used", "not used");
|
|
|
169 |
MasterThread masterThread = new MasterThread(1, 1, "unit test generate build files");
|
|
|
170 |
masterThread.run();
|
|
|
171 |
Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
|
|
|
172 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_ACTIVE );
|
|
|
173 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
|
|
|
174 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_ACTIVE );
|
|
|
175 |
boolean caughtOOB = false;
|
|
|
176 |
|
|
|
177 |
try
|
|
|
178 |
{
|
|
|
179 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
|
|
|
180 |
}
|
|
|
181 |
catch( ArrayIndexOutOfBoundsException e )
|
|
|
182 |
{
|
|
|
183 |
caughtOOB = true;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
assertTrue(caughtOOB);
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/**test method designed to test the sequence diagram consume build files
|
|
|
190 |
* 1 constructs a ReleaseManager object, passing a connectionString of "unit test consume build files"
|
|
|
191 |
* 2 constructs a SlaveThread object, passing a gbebuildfilter of "unit test consume build files"
|
|
|
192 |
* this utilises the following unit test hooks in the codebase:
|
|
|
193 |
* - SlaveThread constructor made public for unit test use
|
|
|
194 |
* - SlaveThread::run gbebuildfilter of "unit test consume build files" limits method to the sequence diagram
|
|
|
195 |
* interrupts the thread if, on one pass, the current build file string is empty
|
|
|
196 |
* exits the while forever loop
|
|
|
197 |
* - ReleaseManager::queryRunLevel
|
|
|
198 |
* initially returns an empty current build file string
|
|
|
199 |
* subsequently returns a "unit test build file content" current build file string
|
|
|
200 |
* 3 calls run on the SlaveThread object
|
|
|
201 |
*/
|
|
|
202 |
@Test
|
|
|
203 |
public void TestConsumeBuildFiles()
|
|
|
204 |
{
|
|
|
205 |
mLogger.debug("TestConsumeBuildFiles");
|
|
|
206 |
ReleaseManager releaseManager = new ReleaseManager("unit test consume build files", "not used", "not used");
|
|
|
207 |
SlaveThread slaveThread = new SlaveThread(1, 1, "unit test consume build files");
|
| 864 |
mhunt |
208 |
assertFalse(Thread.interrupted());
|
| 814 |
mhunt |
209 |
slaveThread.run();
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/**test method designed to test the sequence diagram allowed to proceed
|
|
|
213 |
* 1 constructs a ReleaseManager object, passing a connectionString of "unit test allowed to proceed"
|
|
|
214 |
* 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test allowed to proceed"
|
|
|
215 |
* this utilises the following unit test hooks in the codebase:
|
|
|
216 |
* - MasterThread constructor made public for unit test use
|
|
|
217 |
* - MasterThread::run gbebuildfilter of "unit test allowed to proceed" limits method to the sequence diagram
|
|
|
218 |
* exits the while forever loop
|
|
|
219 |
* - ReleaseManager::queryReleaseConfig, queryRunLevelSchedule, queryDirectedRunLevel methods return true
|
|
|
220 |
* - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
|
|
|
221 |
* 3 calls run on the MasterThread object
|
|
|
222 |
* 4 checks the first persisted run level is DB_IDLE
|
| 816 |
mhunt |
223 |
* 5 checks the third persisted run level is DB_WAITING
|
|
|
224 |
* 6 checks no further run levels were persisted
|
| 814 |
mhunt |
225 |
*/
|
|
|
226 |
@Test
|
|
|
227 |
public void TestAllowedToProceed()
|
|
|
228 |
{
|
|
|
229 |
mLogger.debug("TestAllowedToProceed");
|
|
|
230 |
ReleaseManager releaseManager = new ReleaseManager("unit test allowed to proceed", "not used", "not used");
|
|
|
231 |
MasterThread masterThread = new MasterThread(1, 1, "unit test allowed to proceed");
|
|
|
232 |
masterThread.run();
|
|
|
233 |
Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
|
|
|
234 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
|
|
|
235 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
|
|
|
236 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_WAITING );
|
|
|
237 |
boolean caughtOOB = false;
|
|
|
238 |
|
|
|
239 |
try
|
|
|
240 |
{
|
|
|
241 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 3 );
|
|
|
242 |
}
|
|
|
243 |
catch( ArrayIndexOutOfBoundsException e )
|
|
|
244 |
{
|
|
|
245 |
caughtOOB = true;
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
assertTrue(caughtOOB);
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
/**test method designed to test the sequence diagram not allowed to proceed
|
|
|
252 |
* 1 constructs a ReleaseManager object, passing a connectionString of "unit test not allowed to proceed"
|
|
|
253 |
* 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test not allowed to proceed"
|
|
|
254 |
* this utilises the following unit test hooks in the codebase:
|
|
|
255 |
* - MasterThread constructor made public for unit test use
|
|
|
256 |
* - MasterThread::run gbebuildfilter of "unit test not allowed to proceed" limits method to the sequence diagram
|
|
|
257 |
* exits the while forever loop
|
|
|
258 |
* - ReleaseManager::queryReleaseConfig method returns true
|
|
|
259 |
* - ReleaseManager::queryRunLevelSchedule method returns false
|
|
|
260 |
* - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
|
|
|
261 |
* 3 calls run on the MasterThread object
|
|
|
262 |
* 4 checks the first persisted run level is DB_IDLE
|
| 816 |
mhunt |
263 |
* 5 checks the third persisted run level is DB_PAUSED
|
|
|
264 |
* 6 checks no further run levels were persisted
|
| 814 |
mhunt |
265 |
* nb cannot check only one thread is running,
|
|
|
266 |
* a Timer thread, though having run to completion, may still be "active"
|
|
|
267 |
*/
|
|
|
268 |
@Test
|
|
|
269 |
public void TestNotAllowedToProceed()
|
|
|
270 |
{
|
|
|
271 |
mLogger.debug("TestNotAllowedToProceed");
|
|
|
272 |
ReleaseManager releaseManager = new ReleaseManager("unit test not allowed to proceed", "not used", "not used");
|
|
|
273 |
MasterThread masterThread = new MasterThread(1, 1, "unit test not allowed to proceed");
|
|
|
274 |
masterThread.run();
|
|
|
275 |
Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
|
|
|
276 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
|
|
|
277 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
|
|
|
278 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_PAUSED );
|
|
|
279 |
boolean caughtOOB = false;
|
|
|
280 |
|
|
|
281 |
try
|
|
|
282 |
{
|
|
|
283 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 3 );
|
|
|
284 |
}
|
|
|
285 |
catch( ArrayIndexOutOfBoundsException e )
|
|
|
286 |
{
|
|
|
287 |
caughtOOB = true;
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
assertTrue(caughtOOB);
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
/**test method designed to test the sequence diagram exit
|
|
|
294 |
* 1 constructs a ReleaseManager object, passing a connectionString of "unit test exit"
|
|
|
295 |
* 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test exit"
|
|
|
296 |
* this utilises the following unit test hooks in the codebase:
|
|
|
297 |
* - MasterThread constructor made public for unit test use
|
|
|
298 |
* - MasterThread::run gbebuildfilter of "unit test exit" limits method to the sequence diagram
|
|
|
299 |
* - ReleaseManager::queryReleaseConfig method returns false
|
|
|
300 |
* - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
|
|
|
301 |
* 3 calls run on the MasterThread object
|
|
|
302 |
* 4 checks the first persisted run level is DB_IDLE
|
|
|
303 |
* 5 checks no further run levels were persisted
|
|
|
304 |
*/
|
|
|
305 |
@Test
|
|
|
306 |
public void TestExit()
|
|
|
307 |
{
|
|
|
308 |
mLogger.debug("TestExit");
|
|
|
309 |
ReleaseManager releaseManager = new ReleaseManager("unit test exit", "not used", "not used");
|
|
|
310 |
MasterThread masterThread = new MasterThread(1, 1, "unit test exit");
|
|
|
311 |
masterThread.run();
|
|
|
312 |
Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
|
|
|
313 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
|
|
|
314 |
|
|
|
315 |
boolean caughtOOB = false;
|
|
|
316 |
|
|
|
317 |
try
|
|
|
318 |
{
|
|
|
319 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
|
|
|
320 |
}
|
|
|
321 |
catch( ArrayIndexOutOfBoundsException e )
|
|
|
322 |
{
|
|
|
323 |
caughtOOB = true;
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
assertTrue(caughtOOB);
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
/**test method designed to test the sequence diagram check environment
|
|
|
330 |
* 1 constructs a ReleaseManager object, passing a connectionString of "unit check environment"
|
|
|
331 |
* 2 constructs a MasterThread object, passing a gbebuildfilter of "unit check environment"
|
|
|
332 |
* this utilises the following unit test hooks in the codebase:
|
|
|
333 |
* - MasterThread constructor made public for unit test use
|
|
|
334 |
* - MasterThread::run gbebuildfilter of "unit test check environment" limits method to the sequence diagram
|
|
|
335 |
* exits the while forever loop
|
|
|
336 |
* - MasterThread::housekeep method does not call deleteDirectory
|
|
|
337 |
* - MasterThread::hasSufficientDiskSpace initially returns false, then true
|
|
|
338 |
* - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
|
|
|
339 |
* 3 calls run on the MasterThread object
|
|
|
340 |
* 4 checks the first persisted run level is DB_CANNOT_CONTINUE
|
|
|
341 |
* 5 checks the next persisted run level is DB_ACTIVE
|
|
|
342 |
* 6 checks no further run levels were persisted
|
|
|
343 |
*/
|
|
|
344 |
@Test
|
|
|
345 |
public void TestCheckEnvironment()
|
|
|
346 |
{
|
|
|
347 |
mLogger.debug("TestCheckEnvironment");
|
|
|
348 |
ReleaseManager releaseManager = new ReleaseManager("unit test check environment", "not used", "not used");
|
|
|
349 |
MasterThread masterThread = new MasterThread(1, 1, "unit test check environment");
|
|
|
350 |
masterThread.run();
|
|
|
351 |
Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
|
|
|
352 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_CANNOT_CONTINUE );
|
|
|
353 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
|
|
|
354 |
assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_ACTIVE );
|
|
|
355 |
boolean caughtOOB = false;
|
|
|
356 |
|
|
|
357 |
try
|
|
|
358 |
{
|
|
|
359 |
persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
|
|
|
360 |
}
|
|
|
361 |
catch( ArrayIndexOutOfBoundsException e )
|
|
|
362 |
{
|
|
|
363 |
caughtOOB = true;
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
assertTrue(caughtOOB);
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
/**test method designed to test the ripple engine
|
|
|
370 |
* 1 constructs a ReleaseManager object with connection string "iteration1"
|
|
|
371 |
* 2 constructs a RippleEngine object
|
|
|
372 |
* 3 calls planRelease on the RippleEngine object
|
|
|
373 |
* 4 calls getFirstBuildFileContent
|
|
|
374 |
* 5 checks it returns true
|
|
|
375 |
* 6 writes the content to "daemon1.xml"
|
|
|
376 |
* 7 checks the content matches the content in "expecteddaemon1.xml"
|
|
|
377 |
* 8 calls getNextBuildFileContent
|
|
|
378 |
* 9 checks it returns false
|
|
|
379 |
* 10 constructs a ReleaseManager object with connection string "iteration2"
|
|
|
380 |
* 11 calls planRelease on the RippleEngine object
|
|
|
381 |
* 12 calls getFirstBuildFileContent
|
|
|
382 |
* 13 checks it returns true
|
|
|
383 |
* 14 writes the content to "daemon2.xml"
|
|
|
384 |
* 15 checks the content matches the content in "expecteddaemon2.xml"
|
|
|
385 |
* 16 calls getNextBuildFileContent
|
|
|
386 |
* 17 checks it returns false
|
|
|
387 |
* 18 steps 10 to 17 are repeated for iteration3,4,5 and 6
|
|
|
388 |
* 19 constructs a ReleaseManager object with connection string "iteration7"
|
|
|
389 |
* 20 calls planRelease on the RippleEngine object
|
|
|
390 |
* 21 calls getFirstBuildFileContent
|
|
|
391 |
* 22 checks it returns true (a benign build file content)
|
|
|
392 |
*/
|
|
|
393 |
@Test
|
|
|
394 |
public void TestPlanRelease()
|
|
|
395 |
{
|
|
|
396 |
mLogger.debug("TestPlanRelease");
|
|
|
397 |
ReleaseManager releaseManager =
|
|
|
398 |
new ReleaseManager("iteration1", "not used", "not used");
|
|
|
399 |
|
|
|
400 |
RippleEngine rippleEngine = new RippleEngine(releaseManager, 11111, true);
|
|
|
401 |
// this is all the MasterThread does
|
|
|
402 |
try
|
|
|
403 |
{
|
|
|
404 |
rippleEngine.planRelease();
|
|
|
405 |
}
|
|
|
406 |
catch(Exception e)
|
|
|
407 |
{
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
String ExpectedBuildFileContent = new String();
|
|
|
411 |
MutableString buildFileContent = new MutableString();
|
|
|
412 |
boolean moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
|
|
|
413 |
assertTrue(moreBuildFiles);
|
|
|
414 |
|
|
|
415 |
// persist the generated build file content to daemon1.xml for visibility
|
|
|
416 |
File cwd = new File( "." );
|
|
|
417 |
String buildFileName = new String("daemon1.xml");
|
|
|
418 |
try
|
|
|
419 |
{
|
|
|
420 |
File buildFile = new File(cwd, buildFileName);
|
|
|
421 |
FileWriter buildFileWriter = new FileWriter(buildFile);
|
|
|
422 |
buildFileWriter.write(buildFileContent.value);
|
|
|
423 |
buildFileWriter.close();
|
|
|
424 |
File expectedBuildFile = new File(cwd, "expecteddaemon1.xml");
|
|
|
425 |
FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
|
|
|
426 |
char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
|
|
|
427 |
expectedBuildFileReader.read(expectedBuildFileContent);
|
|
|
428 |
expectedBuildFileReader.close();
|
|
|
429 |
String temp = new String(expectedBuildFileContent);
|
|
|
430 |
ExpectedBuildFileContent = temp;
|
|
|
431 |
}
|
|
|
432 |
catch( IOException e )
|
|
|
433 |
{
|
|
|
434 |
System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
|
|
|
438 |
moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
|
|
|
439 |
assertFalse(moreBuildFiles);
|
|
|
440 |
|
|
|
441 |
releaseManager =
|
|
|
442 |
new ReleaseManager("iteration2", "not used", "not used");
|
|
|
443 |
|
|
|
444 |
// this is all the MasterThread does
|
|
|
445 |
try
|
|
|
446 |
{
|
|
|
447 |
rippleEngine.planRelease();
|
|
|
448 |
}
|
|
|
449 |
catch(Exception e)
|
|
|
450 |
{
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
|
|
|
454 |
assertTrue(moreBuildFiles);
|
|
|
455 |
|
|
|
456 |
// persist the generated build file content to daemon1.xml for visibility
|
|
|
457 |
buildFileName = new String("daemon2.xml");
|
|
|
458 |
try
|
|
|
459 |
{
|
|
|
460 |
File buildFile = new File(cwd, buildFileName);
|
|
|
461 |
FileWriter buildFileWriter = new FileWriter(buildFile);
|
|
|
462 |
buildFileWriter.write(buildFileContent.value);
|
|
|
463 |
buildFileWriter.close();
|
|
|
464 |
File expectedBuildFile = new File(cwd, "expecteddaemon2.xml");
|
|
|
465 |
FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
|
|
|
466 |
char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
|
|
|
467 |
expectedBuildFileReader.read(expectedBuildFileContent);
|
|
|
468 |
expectedBuildFileReader.close();
|
|
|
469 |
String temp = new String(expectedBuildFileContent);
|
|
|
470 |
ExpectedBuildFileContent = temp;
|
|
|
471 |
}
|
|
|
472 |
catch( IOException e )
|
|
|
473 |
{
|
|
|
474 |
System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
|
|
|
478 |
moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
|
|
|
479 |
assertFalse(moreBuildFiles);
|
|
|
480 |
|
|
|
481 |
releaseManager =
|
|
|
482 |
new ReleaseManager("iteration3", "not used", "not used");
|
|
|
483 |
|
|
|
484 |
// this is all the MasterThread does
|
|
|
485 |
try
|
|
|
486 |
{
|
|
|
487 |
rippleEngine.planRelease();
|
|
|
488 |
}
|
|
|
489 |
catch(Exception e)
|
|
|
490 |
{
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
|
|
|
494 |
assertTrue(moreBuildFiles);
|
|
|
495 |
|
|
|
496 |
// persist the generated build file content to daemon1.xml for visibility
|
|
|
497 |
buildFileName = new String("daemon3.xml");
|
|
|
498 |
try
|
|
|
499 |
{
|
|
|
500 |
File buildFile = new File(cwd, buildFileName);
|
|
|
501 |
FileWriter buildFileWriter = new FileWriter(buildFile);
|
|
|
502 |
buildFileWriter.write(buildFileContent.value);
|
|
|
503 |
buildFileWriter.close();
|
|
|
504 |
File expectedBuildFile = new File(cwd, "expecteddaemon3.xml");
|
|
|
505 |
FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
|
|
|
506 |
char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
|
|
|
507 |
expectedBuildFileReader.read(expectedBuildFileContent);
|
|
|
508 |
expectedBuildFileReader.close();
|
|
|
509 |
String temp = new String(expectedBuildFileContent);
|
|
|
510 |
ExpectedBuildFileContent = temp;
|
|
|
511 |
}
|
|
|
512 |
catch( IOException e )
|
|
|
513 |
{
|
|
|
514 |
System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
|
|
|
515 |
}
|
|
|
516 |
|
|
|
517 |
assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
|
|
|
518 |
moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
|
|
|
519 |
assertFalse(moreBuildFiles);
|
|
|
520 |
|
|
|
521 |
releaseManager =
|
|
|
522 |
new ReleaseManager("iteration4", "not used", "not used");
|
|
|
523 |
|
|
|
524 |
// this is all the MasterThread does
|
|
|
525 |
try
|
|
|
526 |
{
|
|
|
527 |
rippleEngine.planRelease();
|
|
|
528 |
}
|
|
|
529 |
catch(Exception e)
|
|
|
530 |
{
|
|
|
531 |
}
|
|
|
532 |
|
|
|
533 |
moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
|
|
|
534 |
assertTrue(moreBuildFiles);
|
|
|
535 |
|
|
|
536 |
// persist the generated build file content to daemon1.xml for visibility
|
|
|
537 |
buildFileName = new String("daemon4.xml");
|
|
|
538 |
try
|
|
|
539 |
{
|
|
|
540 |
File buildFile = new File(cwd, buildFileName);
|
|
|
541 |
FileWriter buildFileWriter = new FileWriter(buildFile);
|
|
|
542 |
buildFileWriter.write(buildFileContent.value);
|
|
|
543 |
buildFileWriter.close();
|
|
|
544 |
File expectedBuildFile = new File(cwd, "expecteddaemon4.xml");
|
|
|
545 |
FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
|
|
|
546 |
char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
|
|
|
547 |
expectedBuildFileReader.read(expectedBuildFileContent);
|
|
|
548 |
expectedBuildFileReader.close();
|
|
|
549 |
String temp = new String(expectedBuildFileContent);
|
|
|
550 |
ExpectedBuildFileContent = temp;
|
|
|
551 |
}
|
|
|
552 |
catch( IOException e )
|
|
|
553 |
{
|
|
|
554 |
System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
|
|
|
558 |
moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
|
|
|
559 |
assertFalse(moreBuildFiles);
|
|
|
560 |
|
|
|
561 |
releaseManager =
|
|
|
562 |
new ReleaseManager("iteration5", "not used", "not used");
|
|
|
563 |
|
|
|
564 |
// this is all the MasterThread does
|
|
|
565 |
try
|
|
|
566 |
{
|
|
|
567 |
rippleEngine.planRelease();
|
|
|
568 |
}
|
|
|
569 |
catch(Exception e)
|
|
|
570 |
{
|
|
|
571 |
}
|
|
|
572 |
|
|
|
573 |
moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
|
|
|
574 |
assertTrue(moreBuildFiles);
|
|
|
575 |
|
|
|
576 |
// persist the generated build file content to daemon1.xml for visibility
|
|
|
577 |
buildFileName = new String("daemon5.xml");
|
|
|
578 |
try
|
|
|
579 |
{
|
|
|
580 |
File buildFile = new File(cwd, buildFileName);
|
|
|
581 |
FileWriter buildFileWriter = new FileWriter(buildFile);
|
|
|
582 |
buildFileWriter.write(buildFileContent.value);
|
|
|
583 |
buildFileWriter.close();
|
|
|
584 |
File expectedBuildFile = new File(cwd, "expecteddaemon5.xml");
|
|
|
585 |
FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
|
|
|
586 |
char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
|
|
|
587 |
expectedBuildFileReader.read(expectedBuildFileContent);
|
|
|
588 |
expectedBuildFileReader.close();
|
|
|
589 |
String temp = new String(expectedBuildFileContent);
|
|
|
590 |
ExpectedBuildFileContent = temp;
|
|
|
591 |
}
|
|
|
592 |
catch( IOException e )
|
|
|
593 |
{
|
|
|
594 |
System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
|
|
|
598 |
moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
|
|
|
599 |
assertFalse(moreBuildFiles);
|
|
|
600 |
|
|
|
601 |
releaseManager =
|
|
|
602 |
new ReleaseManager("iteration6", "not used", "not used");
|
|
|
603 |
|
|
|
604 |
// this is all the MasterThread does
|
|
|
605 |
try
|
|
|
606 |
{
|
|
|
607 |
rippleEngine.planRelease();
|
|
|
608 |
}
|
|
|
609 |
catch(Exception e)
|
|
|
610 |
{
|
|
|
611 |
}
|
|
|
612 |
|
|
|
613 |
moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
|
|
|
614 |
assertTrue(moreBuildFiles);
|
|
|
615 |
|
|
|
616 |
// persist the generated build file content to daemon1.xml for visibility
|
|
|
617 |
buildFileName = new String("daemon6.xml");
|
|
|
618 |
try
|
|
|
619 |
{
|
|
|
620 |
File buildFile = new File(cwd, buildFileName);
|
|
|
621 |
FileWriter buildFileWriter = new FileWriter(buildFile);
|
|
|
622 |
buildFileWriter.write(buildFileContent.value);
|
|
|
623 |
buildFileWriter.close();
|
|
|
624 |
File expectedBuildFile = new File(cwd, "expecteddaemon6.xml");
|
|
|
625 |
FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
|
|
|
626 |
char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
|
|
|
627 |
expectedBuildFileReader.read(expectedBuildFileContent);
|
|
|
628 |
expectedBuildFileReader.close();
|
|
|
629 |
String temp = new String(expectedBuildFileContent);
|
|
|
630 |
ExpectedBuildFileContent = temp;
|
|
|
631 |
}
|
|
|
632 |
catch( IOException e )
|
|
|
633 |
{
|
|
|
634 |
System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
|
|
|
635 |
}
|
|
|
636 |
|
|
|
637 |
assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
|
|
|
638 |
moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
|
|
|
639 |
assertFalse(moreBuildFiles);
|
|
|
640 |
|
|
|
641 |
releaseManager =
|
|
|
642 |
new ReleaseManager("iteration7", "not used", "not used");
|
|
|
643 |
|
|
|
644 |
// this is all the MasterThread does
|
|
|
645 |
try
|
|
|
646 |
{
|
|
|
647 |
rippleEngine.planRelease();
|
|
|
648 |
}
|
|
|
649 |
catch(Exception e)
|
|
|
650 |
{
|
|
|
651 |
}
|
|
|
652 |
|
|
|
653 |
moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
|
|
|
654 |
assertTrue(moreBuildFiles);
|
|
|
655 |
}
|
|
|
656 |
}
|