7
7
import static org .hamcrest .Matchers .in ;
8
8
import static org .hamcrest .Matchers .is ;
9
9
import static org .hamcrest .Matchers .not ;
10
+ import static org .hamcrest .Matchers .startsWith ;
10
11
11
12
import hudson .FilePath ;
12
13
import hudson .Launcher ;
23
24
import hudson .slaves .RetentionStrategy ;
24
25
import hudson .util .ClockDifference ;
25
26
import hudson .util .DescribableList ;
27
+ import hudson .util .LogTaskListener ;
28
+ import hudson .util .RingBufferLogHandler ;
29
+ import java .io .File ;
26
30
import java .io .IOException ;
27
31
import java .nio .charset .Charset ;
28
32
import java .util .Collection ;
29
33
import java .util .List ;
30
34
import java .util .Set ;
31
35
import java .util .concurrent .Future ;
36
+ import java .util .logging .Level ;
32
37
import java .util .logging .LogRecord ;
38
+ import java .util .logging .Logger ;
33
39
import javax .servlet .ServletException ;
34
40
import org .junit .After ;
35
41
import org .junit .Before ;
@@ -152,7 +158,7 @@ public void testGetLabelsForNode_IsNull() throws Exception {
152
158
153
159
@ Test (expected = IOException .class )
154
160
public void testRequestComputerPlatformDetails_ChannelThrows () throws Exception {
155
- Computer throwingComputer = new NullingComputer (computer .getNode (), new IOException ());
161
+ Computer throwingComputer = new NullingComputer (computer .getNode (), new IOException ("Oops" ));
156
162
nodeLabelCache .requestComputerPlatformDetails (throwingComputer , throwingComputer .getChannel ());
157
163
}
158
164
@@ -166,6 +172,111 @@ public void testRequestComputerPlatformDetails_ChannelThrowsOnNullChannel() thro
166
172
nodeLabelCache .requestComputerPlatformDetails (computer , null );
167
173
}
168
174
175
+ @ Test
176
+ public void testPreOnline_ChannelLogsDetailCollectionIgnoredOnInternalException () throws Exception {
177
+ // Setup a recorder for agent log
178
+ RingBufferLogHandler agentLogHandler = new RingBufferLogHandler (10 );
179
+ Logger agentLogger = Logger .getLogger (NodeLabelCacheTest .class .getName ());
180
+ agentLogger .addHandler (agentLogHandler );
181
+ TaskListener agentListener = new LogTaskListener (agentLogger , Level .INFO );
182
+
183
+ nodeLabelCache .preOnline (computer , null , new FilePath (new File ("." )), agentListener );
184
+
185
+ assertThat (
186
+ agentLogHandler .getView ().get (0 ).getMessage (),
187
+ startsWith ("Ignored platform detail collection failure for 'unnamed agent' during preOnline phase." ));
188
+ }
189
+
190
+ @ Test
191
+ public void testPreOnline_ChannelLogsDetailCollectionIgnoredOnInternalExceptionForNullComputer () throws Exception {
192
+ // Setup a recorder for agent log
193
+ RingBufferLogHandler agentLogHandler = new RingBufferLogHandler (10 );
194
+ Logger agentLogger = Logger .getLogger (NodeLabelCacheTest .class .getName ());
195
+ agentLogger .addHandler (agentLogHandler );
196
+ TaskListener agentListener = new LogTaskListener (agentLogger , Level .INFO );
197
+
198
+ nodeLabelCache .preOnline (null , null , new FilePath (new File ("." )), agentListener );
199
+
200
+ assertThat (
201
+ agentLogHandler .getView ().get (0 ).getMessage (),
202
+ startsWith ("Ignored platform detail collection failure for 'unnamed agent' during preOnline phase." ));
203
+ }
204
+
205
+ @ Test
206
+ public void testPreOnline_ChannelLogsDetailCollectionIgnoredOnInternalExceptionForComputer () throws Exception {
207
+ // Setup a recorder for agent log
208
+ RingBufferLogHandler agentLogHandler = new RingBufferLogHandler (10 );
209
+ Logger agentLogger = Logger .getLogger (NodeLabelCacheTest .class .getName ());
210
+ agentLogger .addHandler (agentLogHandler );
211
+ TaskListener agentListener = new LogTaskListener (agentLogger , Level .INFO );
212
+
213
+ Computer minimal = new MinimalComputer (computer .getNode ());
214
+ String name = minimal .getName ();
215
+ nodeLabelCache .preOnline (minimal , null , new FilePath (new File ("." )), agentListener );
216
+
217
+ assertThat (
218
+ agentLogHandler .getView ().get (0 ).getMessage (),
219
+ startsWith ("Ignored platform detail collection failure for '" + name + "' during preOnline phase." ));
220
+ }
221
+
222
+ /** A minimal Computer class for preOnline test. */
223
+ private class MinimalComputer extends Computer {
224
+ public MinimalComputer (Node node ) {
225
+ super (node );
226
+ }
227
+
228
+ @ Override
229
+ public Node getNode () {
230
+ return super .getNode ();
231
+ }
232
+
233
+ @ Override
234
+ public String getName () {
235
+ return "computer-test" ;
236
+ }
237
+
238
+ @ Override
239
+ public VirtualChannel getChannel () {
240
+ return null ;
241
+ }
242
+
243
+ @ Override
244
+ public Charset getDefaultCharset () {
245
+ throw new UnsupportedOperationException ("Unsupported" );
246
+ }
247
+
248
+ @ Override
249
+ public List <LogRecord > getLogRecords () throws IOException , InterruptedException {
250
+ throw new UnsupportedOperationException ("Unsupported" );
251
+ }
252
+
253
+ @ Override
254
+ @ RequirePOST
255
+ public void doLaunchSlaveAgent (StaplerRequest sr , StaplerResponse sr1 ) throws IOException , ServletException {
256
+ throw new UnsupportedOperationException ("Unsupported" );
257
+ }
258
+
259
+ @ Override
260
+ protected Future <?> _connect (boolean bln ) {
261
+ throw new UnsupportedOperationException ("Unsupported" );
262
+ }
263
+
264
+ @ Override
265
+ public Boolean isUnix () {
266
+ throw new UnsupportedOperationException ("Unsupported" );
267
+ }
268
+
269
+ @ Override
270
+ public boolean isConnecting () {
271
+ throw new UnsupportedOperationException ("Unsupported" );
272
+ }
273
+
274
+ @ Override
275
+ public RetentionStrategy <?> getRetentionStrategy () {
276
+ throw new UnsupportedOperationException ("Unsupported" );
277
+ }
278
+ }
279
+
169
280
/** Class that intentionally returns nulls for test purposes. */
170
281
private class NullingComputer extends Computer {
171
282
0 commit comments