kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: MINOR: Scala code readability improvements
Date Tue, 03 Jan 2017 11:08:40 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 6f09bcb59 -> 252e7e958


MINOR: Scala code readability improvements

Author: Himani Arora <1himani.arora@gmail.com>

Reviewers: Ismael Juma <ismael@juma.me.uk>

Closes #2297 from himani1/refactored_code


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/252e7e95
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/252e7e95
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/252e7e95

Branch: refs/heads/trunk
Commit: 252e7e958a2fabfa680d23a00e7f0ce7c74f6ad8
Parents: 6f09bcb
Author: Himani Arora <1himani.arora@gmail.com>
Authored: Tue Jan 3 11:07:43 2017 +0000
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Tue Jan 3 11:07:57 2017 +0000

----------------------------------------------------------------------
 .../scala/unit/kafka/admin/AclCommandTest.scala     |  2 +-
 .../kafka/admin/DescribeConsumerGroupTest.scala     | 16 +++++++---------
 .../unit/kafka/admin/ListConsumerGroupTest.scala    |  2 +-
 .../unit/kafka/admin/ReplicationQuotaUtils.scala    |  2 +-
 .../test/scala/unit/kafka/common/TopicTest.scala    |  4 ++--
 .../scala/unit/kafka/consumer/TopicFilterTest.scala | 10 +++++-----
 .../kafka/integration/KafkaServerTestHarness.scala  |  2 +-
 7 files changed, 18 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/252e7e95/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala b/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala
index 8ea6041..6d89d4f 100644
--- a/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala
+++ b/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala
@@ -45,7 +45,7 @@ class AclCommandTest extends ZooKeeperTestHarness with Logging {
   private val ResourceToOperations = Map[Set[Resource], (Set[Operation], Array[String])](
     TopicResources -> (Set(Read, Write, Describe, Delete), Array("--operation", "Read"
, "--operation", "Write", "--operation", "Describe", "--operation", "Delete")),
     Set(Resource.ClusterResource) -> (Set(Create, ClusterAction), Array("--operation",
"Create", "--operation", "ClusterAction")),
-    GroupResources -> (Set(Read, Describe).toSet[Operation], Array("--operation", "Read",
"--operation", "Describe"))
+    GroupResources -> (Set(Read, Describe), Array("--operation", "Read", "--operation",
"Describe"))
   )
 
   private val ProducerResourceToAcls = Map[Set[Resource], Set[Acl]](

http://git-wip-us.apache.org/repos/asf/kafka/blob/252e7e95/core/src/test/scala/unit/kafka/admin/DescribeConsumerGroupTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/admin/DescribeConsumerGroupTest.scala b/core/src/test/scala/unit/kafka/admin/DescribeConsumerGroupTest.scala
index b9c760d..a6ebbe3 100644
--- a/core/src/test/scala/unit/kafka/admin/DescribeConsumerGroupTest.scala
+++ b/core/src/test/scala/unit/kafka/admin/DescribeConsumerGroupTest.scala
@@ -35,7 +35,7 @@ class DescribeConsumerGroupTest extends KafkaServerTestHarness {
 
   val overridingProps = new Properties()
   val topic = "foo"
-  val topicFilter = new Whitelist(topic)
+  val topicFilter = Whitelist(topic)
   val group = "test.group"
   val props = new Properties
 
@@ -64,9 +64,7 @@ class DescribeConsumerGroupTest extends KafkaServerTestHarness {
     EasyMock.replay(consumerMock)
 
     // action/test
-    TestUtils.waitUntilTrue(() => {
-        !consumerGroupCommand.describeGroup()._2.isDefined
-      }, "Expected no rows in describe group results.")
+    TestUtils.waitUntilTrue(() => consumerGroupCommand.describeGroup()._2.isEmpty, "Expected
no rows in describe group results.")
 
     // cleanup
     consumerGroupCommand.close()
@@ -89,7 +87,7 @@ class DescribeConsumerGroupTest extends KafkaServerTestHarness {
     TestUtils.waitUntilTrue(() => {
         val (_, assignments) = consumerGroupCommand.describeGroup()
         assignments.isDefined &&
-        assignments.get.filter(_.group == group).size == 1 &&
+        assignments.get.count(_.group == group) == 1 &&
         assignments.get.filter(_.group == group).head.consumerId.exists(_.trim.nonEmpty)
       }, "Expected rows and a member id column in describe group results.")
 
@@ -116,7 +114,7 @@ class DescribeConsumerGroupTest extends KafkaServerTestHarness {
     TestUtils.waitUntilTrue(() => {
         val (_, assignments) = consumerGroupCommand.describeGroup()
         assignments.isDefined &&
-        assignments.get.filter(_.group == group).size == 1 &&
+        assignments.get.count(_.group == group) == 1 &&
         assignments.get.filter(_.group == group).head.consumerId.isDefined &&
         assignments.get.filter(_.group == group).head.consumerId.exists(_.trim.isEmpty) //
the member should be gone
       }, "Expected no active member in describe group results.")
@@ -142,9 +140,9 @@ class DescribeConsumerGroupTest extends KafkaServerTestHarness {
     TestUtils.waitUntilTrue(() => {
         val (_, assignments) = consumerGroupCommand.describeGroup()
         assignments.isDefined &&
-        assignments.get.filter(_.group == group).size == 2 &&
-        assignments.get.filter{ x => x.group == group && x.partition.isDefined}.size
== 1 &&
-        assignments.get.filter{ x => x.group == group && !x.partition.isDefined}.size
== 1
+        assignments.get.count(_.group == group) == 2 &&
+        assignments.get.count { x => x.group == group && x.partition.isDefined
} == 1 &&
+        assignments.get.count { x => x.group == group && !x.partition.isDefined
} == 1
       }, "Expected rows for consumers with no assigned partitions in describe group results.")
 
     // cleanup

http://git-wip-us.apache.org/repos/asf/kafka/blob/252e7e95/core/src/test/scala/unit/kafka/admin/ListConsumerGroupTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/admin/ListConsumerGroupTest.scala b/core/src/test/scala/unit/kafka/admin/ListConsumerGroupTest.scala
index f4494c7..8759cfd 100644
--- a/core/src/test/scala/unit/kafka/admin/ListConsumerGroupTest.scala
+++ b/core/src/test/scala/unit/kafka/admin/ListConsumerGroupTest.scala
@@ -35,7 +35,7 @@ class ListConsumerGroupTest extends KafkaServerTestHarness {
 
   val overridingProps = new Properties()
   val topic = "foo"
-  val topicFilter = new Whitelist(topic)
+  val topicFilter = Whitelist(topic)
   val group = "test.group"
   val props = new Properties
 

http://git-wip-us.apache.org/repos/asf/kafka/blob/252e7e95/core/src/test/scala/unit/kafka/admin/ReplicationQuotaUtils.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/admin/ReplicationQuotaUtils.scala b/core/src/test/scala/unit/kafka/admin/ReplicationQuotaUtils.scala
index fff4ea1..9608892 100644
--- a/core/src/test/scala/unit/kafka/admin/ReplicationQuotaUtils.scala
+++ b/core/src/test/scala/unit/kafka/admin/ReplicationQuotaUtils.scala
@@ -48,7 +48,7 @@ object ReplicationQuotaUtils {
       val topicConfig = AdminUtils.fetchEntityConfig(servers(0).zkUtils, ConfigType.Topic,
topic)
       val leader = topicConfig.getProperty(LogConfig.LeaderReplicationThrottledReplicasProp)
       val follower = topicConfig.getProperty(LogConfig.FollowerReplicationThrottledReplicasProp)
-      val topicConfigAvailable = (leader == throttledLeaders && follower == throttledFollowers)
+      val topicConfigAvailable = leader == throttledLeaders && follower == throttledFollowers
       brokerConfigAvailable && topicConfigAvailable
     }, "throttle limit/replicas was not set")
   }

http://git-wip-us.apache.org/repos/asf/kafka/blob/252e7e95/core/src/test/scala/unit/kafka/common/TopicTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/common/TopicTest.scala b/core/src/test/scala/unit/kafka/common/TopicTest.scala
index 39eb315..caab674 100644
--- a/core/src/test/scala/unit/kafka/common/TopicTest.scala
+++ b/core/src/test/scala/unit/kafka/common/TopicTest.scala
@@ -37,7 +37,7 @@ class TopicTest {
       invalidTopicNames += "Is" + weirdChar + "illegal"
     }
 
-    for (i <- 0 until invalidTopicNames.size) {
+    for (i <- invalidTopicNames.indices) {
       try {
         Topic.validate(invalidTopicNames(i))
         fail("Should throw InvalidTopicException.")
@@ -49,7 +49,7 @@ class TopicTest {
 
     val validTopicNames = new ArrayBuffer[String]()
     validTopicNames += ("valid", "TOPIC", "nAmEs", "ar6", "VaL1d", "_0-9_.", longName.drop(7))
-    for (i <- 0 until validTopicNames.size) {
+    for (i <- validTopicNames.indices) {
       try {
         Topic.validate(validTopicNames(i))
       }

http://git-wip-us.apache.org/repos/asf/kafka/blob/252e7e95/core/src/test/scala/unit/kafka/consumer/TopicFilterTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/consumer/TopicFilterTest.scala b/core/src/test/scala/unit/kafka/consumer/TopicFilterTest.scala
index 1e073aa..b1e1274 100644
--- a/core/src/test/scala/unit/kafka/consumer/TopicFilterTest.scala
+++ b/core/src/test/scala/unit/kafka/consumer/TopicFilterTest.scala
@@ -28,29 +28,29 @@ class TopicFilterTest extends JUnitSuite {
   @Test
   def testWhitelists() {
 
-    val topicFilter1 = new Whitelist("white1,white2")
+    val topicFilter1 = Whitelist("white1,white2")
     assertTrue(topicFilter1.isTopicAllowed("white2", excludeInternalTopics = true))
     assertTrue(topicFilter1.isTopicAllowed("white2", excludeInternalTopics = false))
     assertFalse(topicFilter1.isTopicAllowed("black1", excludeInternalTopics = true))
     assertFalse(topicFilter1.isTopicAllowed("black1", excludeInternalTopics = false))
 
-    val topicFilter2 = new Whitelist(".+")
+    val topicFilter2 = Whitelist(".+")
     assertTrue(topicFilter2.isTopicAllowed("alltopics", excludeInternalTopics = true))
     assertFalse(topicFilter2.isTopicAllowed(Topic.GroupMetadataTopicName, excludeInternalTopics
= true))
     assertTrue(topicFilter2.isTopicAllowed(Topic.GroupMetadataTopicName, excludeInternalTopics
= false))
 
-    val topicFilter3 = new Whitelist("white_listed-topic.+")
+    val topicFilter3 = Whitelist("white_listed-topic.+")
     assertTrue(topicFilter3.isTopicAllowed("white_listed-topic1", excludeInternalTopics =
true))
     assertFalse(topicFilter3.isTopicAllowed("black1", excludeInternalTopics = true))
 
-    val topicFilter4 = new Whitelist("test-(?!bad\\b)[\\w]+")
+    val topicFilter4 = Whitelist("test-(?!bad\\b)[\\w]+")
     assertTrue(topicFilter4.isTopicAllowed("test-good", excludeInternalTopics = true))
     assertFalse(topicFilter4.isTopicAllowed("test-bad", excludeInternalTopics = true))  
 
   }
 
   @Test
   def testBlacklists() {
-    val topicFilter1 = new Blacklist("black1")
+    val topicFilter1 = Blacklist("black1")
     assertTrue(topicFilter1.isTopicAllowed("white2", excludeInternalTopics = true))
     assertTrue(topicFilter1.isTopicAllowed("white2", excludeInternalTopics = false))
     assertFalse(topicFilter1.isTopicAllowed("black1", excludeInternalTopics = true))

http://git-wip-us.apache.org/repos/asf/kafka/blob/252e7e95/core/src/test/scala/unit/kafka/integration/KafkaServerTestHarness.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/integration/KafkaServerTestHarness.scala b/core/src/test/scala/unit/kafka/integration/KafkaServerTestHarness.scala
index 7059d17..f418b30 100755
--- a/core/src/test/scala/unit/kafka/integration/KafkaServerTestHarness.scala
+++ b/core/src/test/scala/unit/kafka/integration/KafkaServerTestHarness.scala
@@ -113,7 +113,7 @@ trait KafkaServerTestHarness extends ZooKeeperTestHarness {
    * Restart any dead brokers
    */
   def restartDeadBrokers() {
-    for(i <- 0 until servers.length if !alive(i)) {
+    for(i <- servers.indices if !alive(i)) {
       servers(i).startup()
       alive(i) = true
     }


Mime
View raw message