-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MINOR: Various cleanups in clients tests #15877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,16 +73,17 @@ | |
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| public class MetadataTest { | ||
|
|
||
| private long refreshBackoffMs = 100; | ||
| private long refreshBackoffMaxMs = 1000; | ||
| private long metadataExpireMs = 1000; | ||
| private final long refreshBackoffMs = 100; | ||
| private final long refreshBackoffMaxMs = 1000; | ||
| private final long metadataExpireMs = 1000; | ||
| private Metadata metadata = new Metadata(refreshBackoffMs, refreshBackoffMaxMs, | ||
| metadataExpireMs, new LogContext(), new ClusterResourceListeners()); | ||
|
|
||
|
|
@@ -1210,8 +1211,7 @@ else if (partition.equals(internalPart)) | |
| metadata.update(versionAndBuilder.requestVersion, | ||
| RequestTestUtils.metadataUpdateWith(clusterId, numNodes, errorCounts, topicPartitionCounts, tp -> null, metadataSupplier, ApiKeys.METADATA.latestVersion(), topicIds), | ||
| false, time.milliseconds()); | ||
| List<Node> nodes = new ArrayList<>(); | ||
| nodes.addAll(metadata.fetch().nodes()); | ||
| List<Node> nodes = new ArrayList<>(metadata.fetch().nodes()); | ||
| Node controller = metadata.fetch().controller(); | ||
| assertEquals(numNodes, nodes.size()); | ||
| assertFalse(metadata.updateRequested()); | ||
|
|
@@ -1323,7 +1323,7 @@ public void testConcurrentUpdateAndFetchForSnapshotAndCluster() throws Interrupt | |
| } else { // Thread to read metadata snapshot, once its updated | ||
| try { | ||
| if (!atleastMetadataUpdatedOnceLatch.await(5, TimeUnit.MINUTES)) { | ||
| assertFalse(true, "Test had to wait more than 5 minutes, something went wrong."); | ||
| fail("Test had to wait more than 5 minutes, something went wrong."); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
|
|
@@ -1335,7 +1335,7 @@ public void testConcurrentUpdateAndFetchForSnapshotAndCluster() throws Interrupt | |
| }); | ||
| } | ||
| if (!allThreadsDoneLatch.await(5, TimeUnit.MINUTES)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using assertTrue(allThreadsDoneLatch.await(5, TimeUnit.MINUTES), "Test had to wait more than 5 minutes, something went wrong.");
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's even better! |
||
| assertFalse(true, "Test had to wait more than 5 minutes, something went wrong."); | ||
| fail("Test had to wait more than 5 minutes, something went wrong."); | ||
| } | ||
|
|
||
| // Validate new snapshot is upto-date. And has higher partition counts, nodes & leader epoch than earlier. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,12 +192,12 @@ public class KafkaConsumerTest { | |
| private final String memberId = "memberId"; | ||
| private final String leaderId = "leaderId"; | ||
| private final Optional<String> groupInstanceId = Optional.of("mock-instance"); | ||
| private Map<String, Uuid> topicIds = Stream.of( | ||
| private final Map<String, Uuid> topicIds = Stream.of( | ||
| new AbstractMap.SimpleEntry<>(topic, topicId), | ||
| new AbstractMap.SimpleEntry<>(topic2, topicId2), | ||
| new AbstractMap.SimpleEntry<>(topic3, topicId3)) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
| private Map<Uuid, String> topicNames = Stream.of( | ||
| private final Map<Uuid, String> topicNames = Stream.of( | ||
| new AbstractMap.SimpleEntry<>(topicId, topic), | ||
| new AbstractMap.SimpleEntry<>(topicId2, topic2), | ||
| new AbstractMap.SimpleEntry<>(topicId3, topic3)) | ||
|
|
@@ -1840,28 +1840,28 @@ public void testOperationsBySubscribingConsumerWithDefaultGroupId(GroupProtocol | |
| // OK, expected | ||
| } | ||
|
|
||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, (String) null)) { | ||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, null)) { | ||
| consumer.subscribe(Collections.singleton(topic)); | ||
| fail("Expected an InvalidGroupIdException"); | ||
| } catch (InvalidGroupIdException e) { | ||
| // OK, expected | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're cleaning up this, maybe just
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was able to simplify a few of these. Thanks! |
||
|
|
||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, (String) null)) { | ||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, null)) { | ||
| consumer.committed(Collections.singleton(tp0)).get(tp0); | ||
| fail("Expected an InvalidGroupIdException"); | ||
| } catch (InvalidGroupIdException e) { | ||
| // OK, expected | ||
| } | ||
|
|
||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, (String) null)) { | ||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, null)) { | ||
| consumer.commitAsync(); | ||
| fail("Expected an InvalidGroupIdException"); | ||
| } catch (InvalidGroupIdException e) { | ||
| // OK, expected | ||
| } | ||
|
|
||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, (String) null)) { | ||
| try (KafkaConsumer<byte[], byte[]> consumer = newConsumer(groupProtocol, null)) { | ||
| consumer.commitSync(); | ||
| fail("Expected an InvalidGroupIdException"); | ||
| } catch (InvalidGroupIdException e) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using
assertDoesNotThrow? For example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit unusual to chain assert calls but I'll accept it