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