34
34
import io .netty .channel .EventLoopGroup ;
35
35
import java .nio .charset .StandardCharsets ;
36
36
import java .time .Duration ;
37
+ import java .time .Instant ;
38
+ import java .time .ZoneId ;
39
+ import java .time .format .DateTimeFormatter ;
37
40
import java .util .Collections ;
38
41
import java .util .LinkedHashMap ;
39
42
import java .util .List ;
@@ -251,6 +254,11 @@ void clusterRestart(boolean useLoadBalancer, boolean forceLeader) throws Interru
251
254
LOGGER .info ("Environment information:" );
252
255
System .out .println (TestUtils .jsonPrettyPrint (environment .toString ()));
253
256
257
+ LOGGER .info ("Producer information:" );
258
+ producers .forEach (p -> {
259
+ LOGGER .info ("Producer to '{}' (last exception: '{}')" , p .stream (), p .lastException );
260
+ });
261
+
254
262
LOGGER .info ("Closing producers" );
255
263
producers .forEach (
256
264
p -> {
@@ -293,6 +301,8 @@ private static class ProducerState implements AutoCloseable {
293
301
final AtomicBoolean stopped = new AtomicBoolean (false );
294
302
final AtomicInteger acceptedCount = new AtomicInteger ();
295
303
final AtomicReference <Runnable > postConfirmed = new AtomicReference <>(() -> {});
304
+ final AtomicReference <Throwable > lastException = new AtomicReference <>();
305
+ final AtomicReference <Instant > lastExceptionInstant = new AtomicReference <>();
296
306
297
307
private ProducerState (String stream , boolean dynamicBatch , Environment environment ) {
298
308
this .stream = stream ;
@@ -317,8 +327,9 @@ void start() {
317
327
this .limiter .acquire (1 );
318
328
this .producer .send (
319
329
producer .messageBuilder ().addData (BODY ).build (), confirmationHandler );
320
- } catch (Exception e ) {
321
-
330
+ } catch (Throwable e ) {
331
+ this .lastException .set (e );
332
+ this .lastExceptionInstant .set (Instant .now ());
322
333
}
323
334
}
324
335
});
@@ -342,6 +353,14 @@ String stream() {
342
353
return this .stream ;
343
354
}
344
355
356
+ String lastException () {
357
+ if (this .lastException .get () == null ) {
358
+ return "no exception" ;
359
+ } else {
360
+ return this .lastException .get ().getMessage () + " at " + DateTimeFormatter .ISO_LOCAL_TIME .format (lastExceptionInstant .get ());
361
+ }
362
+ }
363
+
345
364
@ Override
346
365
public void close () {
347
366
stopped .set (true );
0 commit comments