@@ -63,20 +63,21 @@ void testWriteExceptionWhenKafkaUnavailable() throws Exception {
63
63
64
64
final SinkWriterMetricGroup metricGroup = createSinkWriterMetricGroup ();
65
65
66
- final KafkaWriter <Integer > writer =
66
+ try ( KafkaWriter <Integer > writer =
67
67
createWriterWithConfiguration (
68
- properties , DeliveryGuarantee .AT_LEAST_ONCE , metricGroup );
68
+ properties , DeliveryGuarantee .AT_LEAST_ONCE , metricGroup )) {
69
69
70
- writer .write (1 , SINK_WRITER_CONTEXT );
70
+ writer .write (1 , SINK_WRITER_CONTEXT );
71
71
72
- KAFKA_CONTAINER .stop ();
72
+ KAFKA_CONTAINER .stop ();
73
73
74
- try {
75
- writer .getCurrentProducer ().flush ();
76
- assertThatCode (() -> writer .write (1 , SINK_WRITER_CONTEXT ))
77
- .hasRootCauseExactlyInstanceOf (NetworkException .class );
78
- } finally {
79
- KAFKA_CONTAINER .start ();
74
+ try {
75
+ writer .getCurrentProducer ().flush ();
76
+ assertThatCode (() -> writer .write (1 , SINK_WRITER_CONTEXT ))
77
+ .hasRootCauseExactlyInstanceOf (NetworkException .class );
78
+ } finally {
79
+ KAFKA_CONTAINER .start ();
80
+ }
80
81
}
81
82
}
82
83
@@ -86,17 +87,18 @@ void testFlushExceptionWhenKafkaUnavailable() throws Exception {
86
87
87
88
final SinkWriterMetricGroup metricGroup = createSinkWriterMetricGroup ();
88
89
89
- final KafkaWriter <Integer > writer =
90
+ try ( KafkaWriter <Integer > writer =
90
91
createWriterWithConfiguration (
91
- properties , DeliveryGuarantee .AT_LEAST_ONCE , metricGroup );
92
- writer .write (1 , SINK_WRITER_CONTEXT );
93
-
94
- KAFKA_CONTAINER .stop ();
95
- try {
96
- assertThatCode (() -> writer .flush (false ))
97
- .hasRootCauseExactlyInstanceOf (NetworkException .class );
98
- } finally {
99
- KAFKA_CONTAINER .start ();
92
+ properties , DeliveryGuarantee .AT_LEAST_ONCE , metricGroup )) {
93
+ writer .write (1 , SINK_WRITER_CONTEXT );
94
+
95
+ KAFKA_CONTAINER .stop ();
96
+ try {
97
+ assertThatCode (() -> writer .flush (false ))
98
+ .hasRootCauseExactlyInstanceOf (NetworkException .class );
99
+ } finally {
100
+ KAFKA_CONTAINER .start ();
101
+ }
100
102
}
101
103
}
102
104
@@ -106,7 +108,7 @@ void testCloseExceptionWhenKafkaUnavailable() throws Exception {
106
108
107
109
final SinkWriterMetricGroup metricGroup = createSinkWriterMetricGroup ();
108
110
109
- final KafkaWriter <Integer > writer =
111
+ KafkaWriter <Integer > writer =
110
112
createWriterWithConfiguration (
111
113
properties , DeliveryGuarantee .AT_LEAST_ONCE , metricGroup );
112
114
@@ -119,6 +121,9 @@ void testCloseExceptionWhenKafkaUnavailable() throws Exception {
119
121
// closing producer resource throws exception first
120
122
assertThatCode (() -> writer .close ())
121
123
.hasRootCauseExactlyInstanceOf (NetworkException .class );
124
+ } catch (Exception e ) {
125
+ writer .close ();
126
+ throw e ;
122
127
} finally {
123
128
KAFKA_CONTAINER .start ();
124
129
}
@@ -130,26 +135,27 @@ void testMailboxExceptionWhenKafkaUnavailable() throws Exception {
130
135
SinkInitContext sinkInitContext =
131
136
new SinkInitContext (createSinkWriterMetricGroup (), timeService , null );
132
137
133
- final KafkaWriter <Integer > writer =
138
+ try ( KafkaWriter <Integer > writer =
134
139
createWriterWithConfiguration (
135
- properties , DeliveryGuarantee .AT_LEAST_ONCE , sinkInitContext );
140
+ properties , DeliveryGuarantee .AT_LEAST_ONCE , sinkInitContext )) {
136
141
137
- KAFKA_CONTAINER .stop ();
142
+ KAFKA_CONTAINER .stop ();
138
143
139
- writer .write (1 , SINK_WRITER_CONTEXT );
144
+ writer .write (1 , SINK_WRITER_CONTEXT );
140
145
141
- try {
142
- writer .getCurrentProducer ().flush ();
146
+ try {
147
+ writer .getCurrentProducer ().flush ();
143
148
144
- assertThatCode (
145
- () -> {
146
- while (sinkInitContext .getMailboxExecutor ().tryYield ()) {
147
- // execute all mails
148
- }
149
- })
150
- .hasRootCauseExactlyInstanceOf (TimeoutException .class );
151
- } finally {
152
- KAFKA_CONTAINER .start ();
149
+ assertThatCode (
150
+ () -> {
151
+ while (sinkInitContext .getMailboxExecutor ().tryYield ()) {
152
+ // execute all mails
153
+ }
154
+ })
155
+ .hasRootCauseExactlyInstanceOf (TimeoutException .class );
156
+ } finally {
157
+ KAFKA_CONTAINER .start ();
158
+ }
153
159
}
154
160
}
155
161
0 commit comments