|
48 | 48 | import org.apache.kafka.clients.consumer.OffsetAndTimestamp; |
49 | 49 | import org.apache.kafka.clients.producer.Producer; |
50 | 50 | import org.apache.kafka.common.TopicPartition; |
| 51 | +import org.apache.kafka.common.errors.GroupAuthorizationException; |
51 | 52 | import org.junit.jupiter.api.DisplayName; |
52 | 53 | import org.junit.jupiter.api.Test; |
53 | 54 |
|
@@ -149,6 +150,35 @@ void testCorrectContainerForConsumerError() throws InterruptedException { |
149 | 150 | container.stop(); |
150 | 151 | } |
151 | 152 |
|
| 153 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
| 154 | + @Test |
| 155 | + void testConsumerExitWhenNotAuthorized() throws InterruptedException { |
| 156 | + ConsumerFactory consumerFactory = mock(ConsumerFactory.class); |
| 157 | + final Consumer consumer = mock(Consumer.class); |
| 158 | + willAnswer(invocation -> { |
| 159 | + Thread.sleep(100); |
| 160 | + throw new GroupAuthorizationException("grp"); |
| 161 | + }).given(consumer).poll(any()); |
| 162 | + CountDownLatch latch = new CountDownLatch(1); |
| 163 | + willAnswer(invocation -> { |
| 164 | + latch.countDown(); |
| 165 | + return null; |
| 166 | + }).given(consumer).close(); |
| 167 | + given(consumerFactory.createConsumer("grp", "", "-0", KafkaTestUtils.defaultPropertyOverrides())) |
| 168 | + .willReturn(consumer); |
| 169 | + ContainerProperties containerProperties = new ContainerProperties("foo"); |
| 170 | + containerProperties.setGroupId("grp"); |
| 171 | + containerProperties.setMessageListener((MessageListener) record -> { }); |
| 172 | + containerProperties.setMissingTopicsFatal(false); |
| 173 | + containerProperties.setShutdownTimeout(10); |
| 174 | + ConcurrentMessageListenerContainer container = new ConcurrentMessageListenerContainer<>(consumerFactory, |
| 175 | + containerProperties); |
| 176 | + container.start(); |
| 177 | + assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); |
| 178 | + verify(consumer).close(); |
| 179 | + container.stop(); |
| 180 | + } |
| 181 | + |
152 | 182 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
153 | 183 | @Test |
154 | 184 | @DisplayName("Seek on TL callback when idle") |
|
0 commit comments