Skip to content

Commit

Permalink
mock admin when needed only
Browse files Browse the repository at this point in the history
  • Loading branch information
bachmanity1 committed Aug 8, 2023
1 parent 8a1ce9d commit 2c7d2e3
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -70,6 +70,7 @@
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -115,12 +116,11 @@ public class KafkaBasedLogTest {
private final Time time = new MockTime();
private MockedKafkaBasedLog store;

@Mock
private TopicAdmin admin = null;
@Mock
private Consumer<TopicAdmin> initializer;
@Mock
private KafkaProducer<String, String> producer;
private TopicAdmin admin;
private final Supplier<TopicAdmin> topicAdminSupplier = () -> admin;
private MockConsumer<String, String> consumer;

Expand Down Expand Up @@ -445,6 +445,7 @@ public void testReadEndOffsetsUsingAdmin() {
Map<TopicPartition, Long> endOffsets = new HashMap<>();
endOffsets.put(TP0, 0L);
endOffsets.put(TP1, 0L);
admin = mock(TopicAdmin.class);
when(admin.retryEndOffsets(eq(tps), any(), anyLong())).thenReturn(endOffsets);
when(admin.endOffsets(eq(tps))).thenReturn(endOffsets);

Expand All @@ -455,6 +456,7 @@ public void testReadEndOffsetsUsingAdmin() {
@Test
public void testReadEndOffsetsUsingAdminThatFailsWithUnsupported() {
Set<TopicPartition> tps = new HashSet<>(Arrays.asList(TP0, TP1));
admin = mock(TopicAdmin.class);
// Getting end offsets using the admin client should fail with unsupported version
when(admin.retryEndOffsets(eq(tps), any(), anyLong())).thenThrow(new UnsupportedVersionException("too old"));

Expand All @@ -474,6 +476,7 @@ public void testReadEndOffsetsUsingAdminThatFailsWithRetriable() {
Map<TopicPartition, Long> endOffsets = new HashMap<>();
endOffsets.put(TP0, 0L);
endOffsets.put(TP1, 0L);
admin = mock(TopicAdmin.class);
// Getting end offsets upon startup should work fine
when(admin.retryEndOffsets(eq(tps), any(), anyLong())).thenReturn(endOffsets);
// Getting end offsets using the admin client should fail with leader not available
Expand Down

0 comments on commit 2c7d2e3

Please sign in to comment.