Skip to content

Commit

Permalink
MINOR: Optimize assertions in unit tests (#9955)
Browse files Browse the repository at this point in the history
Reviewers: David Jacot <djacot@confluent.io>
  • Loading branch information
dengziming committed Jan 24, 2021
1 parent 6f8ca66 commit f4c2030
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public void testGenerateClientId() {
Set<String> ids = new HashSet<>();
for (int i = 0; i < 10; i++) {
String id = KafkaAdminClient.generateClientId(newConfMap(AdminClientConfig.CLIENT_ID_CONFIG, ""));
assertTrue(!ids.contains(id), "Got duplicate id " + id);
assertFalse(ids.contains(id), "Got duplicate id " + id);
ids.add(id);
}
assertEquals("myCustomId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testManualCompletion() throws Exception {

Future<RecordMetadata> md3 = producer.send(record1);
Future<RecordMetadata> md4 = producer.send(record2);
assertTrue(!md3.isDone() && !md4.isDone(), "Requests should not be completed.");
assertFalse(md3.isDone() && !md4.isDone(), "Requests should not be completed.");
producer.flush();
assertTrue(md3.isDone() && md4.isDone(), "Requests should be completed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ class DynamicBrokerReconfigurationTest extends ZooKeeperTestHarness with SaslSet
val configPrefix = listenerPrefix(SecureExternal)
val brokerConfigs = describeConfig(adminClients.head, servers).entries.asScala
// the following are values before updated
assertTrue(!brokerConfigs.exists(_.name == TestMetricsReporter.PollingIntervalProp), "Initial value of polling interval")
assertTrue(!brokerConfigs.exists(_.name == configPrefix + KafkaConfig.SslTruststoreTypeProp), "Initial value of ssl truststore type")
assertFalse(brokerConfigs.exists(_.name == TestMetricsReporter.PollingIntervalProp), "Initial value of polling interval")
assertFalse(brokerConfigs.exists(_.name == configPrefix + KafkaConfig.SslTruststoreTypeProp), "Initial value of ssl truststore type")
assertNull(brokerConfigs.find(_.name == configPrefix+KafkaConfig.SslKeystorePasswordProp).get.value, "Initial value of ssl keystore password")

// setup ssl properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ class ControllerChannelManagerTest {
val deserializedRequest = LeaderAndIsrRequest.parse(byteBuffer, expectedLeaderAndIsrVersion)

if (interBrokerProtocolVersion >= KAFKA_2_8_IV1) {
assertTrue(!request.topicIds().get("foo").equals(Uuid.ZERO_UUID))
assertTrue(!deserializedRequest.topicIds().get("foo").equals(Uuid.ZERO_UUID))
assertFalse(request.topicIds().get("foo").equals(Uuid.ZERO_UUID))
assertFalse(deserializedRequest.topicIds().get("foo").equals(Uuid.ZERO_UUID))
} else if (interBrokerProtocolVersion >= KAFKA_2_2_IV0) {
assertTrue(!request.topicIds().get("foo").equals(Uuid.ZERO_UUID))
assertFalse(request.topicIds().get("foo").equals(Uuid.ZERO_UUID))
assertTrue(deserializedRequest.topicIds().get("foo").equals(Uuid.ZERO_UUID))
} else {
assertTrue(request.topicIds().get("foo") == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ class GroupCoordinatorTest {
Some(protocolType)
)
assertEquals(Set(leaderRejoinGroupResult.memberId), getGroup(groupId).allMembers)
assertNotEquals(null, getGroup(groupId).leaderOrNull)
assertNotNull(getGroup(groupId).leaderOrNull)
assertEquals(3, getGroup(groupId).generationId)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/unit/kafka/log/LogManagerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class LogManagerTest {
val log = logManager.getLog(new TopicPartition(name, 0))
assertEquals(None, log, "No log should be found.")
val logFile = new File(logDir, name + "-0")
assertTrue(!logFile.exists)
assertFalse(logFile.exists)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/unit/kafka/log/LogTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2991,7 +2991,7 @@ class LogTest {

// Check the topic ID remains in memory and was copied correctly.
assertEquals(id, log.topicId)
assertTrue(!log.partitionMetadataFile.isEmpty)
assertFalse(log.partitionMetadataFile.isEmpty)
assertEquals(id, log.partitionMetadataFile.get.read().topicId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ class SimpleAclAuthorizerTest extends ZooKeeperTestHarness {
//test remove all acls for resource
simpleAclAuthorizer.removeAcls(resource)
TestUtils.waitAndVerifyAcls(Set.empty[Acl], simpleAclAuthorizer, resource)
assertTrue(!zkClient.resourceExists(resource.toPattern))
assertFalse(zkClient.resourceExists(resource.toPattern))

//test removing last acl also deletes ZooKeeper path
acls = changeAclAndVerify(Set.empty[Acl], Set(acl1), Set.empty[Acl])
changeAclAndVerify(acls, Set.empty[Acl], acls)
assertTrue(!zkClient.resourceExists(resource.toPattern))
assertFalse(zkClient.resourceExists(resource.toPattern))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ class AclAuthorizerTest extends ZooKeeperTestHarness with BaseAuthorizerTest {
//test remove all acls for resource
removeAcls(aclAuthorizer, Set.empty, resource)
TestUtils.waitAndVerifyAcls(Set.empty[AccessControlEntry], aclAuthorizer, resource)
assertTrue(!zkClient.resourceExists(resource))
assertFalse(zkClient.resourceExists(resource))

//test removing last acl also deletes ZooKeeper path
acls = changeAclAndVerify(Set.empty, Set(acl1), Set.empty)
changeAclAndVerify(acls, Set.empty, acls)
assertTrue(!zkClient.resourceExists(resource))
assertFalse(zkClient.resourceExists(resource))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class DelegationTokenManagerTest extends ZooKeeperTestHarness {
assertEquals(CreateTokenResult(issueTime, issueTime + renewTimeMsDefault, issueTime + maxLifeTimeMsDefault, tokenId, password, Errors.NONE), createTokenResult)

val token = tokenManager.getToken(tokenId)
assertTrue(!token.isEmpty )
assertFalse(token.isEmpty )
assertTrue(password sameElements token.get.hmac)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/unit/kafka/utils/SchedulerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class SchedulerTest {
topicPartition, producerStateManager, new LogDirFailureChannel(10))
assertTrue(scheduler.taskRunning(log.producerExpireCheck))
log.close()
assertTrue(!(scheduler.taskRunning(log.producerExpireCheck)))
assertFalse(scheduler.taskRunning(log.producerExpireCheck))
}

/**
Expand Down

0 comments on commit f4c2030

Please sign in to comment.