{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/54172975","id":54172975,"diff_hunk":"@@ -0,0 +1,112 @@\n+/**\n+  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE\n+  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file\n+  * to You under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the\n+  * License. You may obtain a copy of the License at\n+  *\n+  * http://www.apache.org/licenses/LICENSE-2.0\n+  *\n+  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on\n+  * an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the\n+  * specific language governing permissions and limitations under the License.\n+  */\n+package unit.kafka.admin\n+\n+import kafka.admin.ReassignPartitionsCommand\n+import kafka.server.{KafkaConfig, KafkaServer}\n+import kafka.utils.TestUtils._\n+import kafka.utils.ZkUtils._\n+import kafka.utils.{CoreUtils, Logging}\n+import kafka.zk.ZooKeeperTestHarness\n+import org.junit.{After, Before, Test}\n+import org.hamcrest.MatcherAssert._\n+import org.hamcrest.core.Is._\n+import scala.collection.Seq\n+\n+\n+class ReassignPartitionsTest extends ZooKeeperTestHarness with Logging {\n+  val partitionId = 0\n+  var servers: Seq[KafkaServer] = null\n+  val topicName = \"my-topic\"\n+\n+  @Before\n+  override def setUp() {\n+    super.setUp()\n+  }\n+\n+  def startBrokers(brokerIds: Seq[Int]) {\n+    servers = brokerIds.map(i => createBrokerConfig(i, zkConnect))\n+      .map(c => createServer(KafkaConfig.fromProps(c)))\n+  }\n+\n+  @After\n+  override def tearDown() {\n+    servers.foreach(_.shutdown())\n+    servers.foreach(server => CoreUtils.rm(server.config.logDirs))\n+    super.tearDown()\n+  }\n+\n+  @Test\n+  def shouldMoveSinglePartition {\n+    //Given a single replica on server 100\n+    startBrokers(Seq(100, 101))\n+    createTopic(zkUtils, topicName, Map(0 -> Seq(100)), servers = servers)\n+\n+    //When we move the replica on 100 to broker 101\n+    ReassignPartitionsCommand.executeAssignment(zkUtils, \"{\\\"version\\\":1,\\\"partitions\\\":[{\\\"topic\\\":\\\"my-topic\\\",\\\"partition\\\":0,\\\"replicas\\\":[101]}]}\")\n+    waitFor(ReassignPartitionsPath)\n+\n+    //Then the replica should be on 101\n+    assertThat(zkUtils.getPartitionAssignmentForTopics(Seq(topicName)).get(topicName).get(0), is(Seq(101)))\n+  }\n+\n+  @Test\n+  def shouldExpandCluster() {\n+    //Given partitions on 2 of 3 brokers\n+    val brokers: Array[Int] = Array(100, 101, 102)\n+    startBrokers(brokers)\n+    createTopic(zkUtils, topicName, Map(\n+      0 -> Seq(100, 101),\n+      1 -> Seq(100, 101),\n+      2 -> Seq(100, 101)\n+    ), servers = servers)\n+\n+    //When rebalancing\n+    val newAssignment = ReassignPartitionsCommand.generateAssignment(zkUtils, brokers, json(topicName))._1\n+    ReassignPartitionsCommand.executeAssignment(zkUtils, zkUtils.formatAsReassignmentJson(newAssignment))\n+    waitFor(ReassignPartitionsPath)\n+\n+    //Then the replicas should span all three brokers\n+    val actual = zkUtils.getPartitionAssignmentForTopics(Seq(topicName))(topicName)\n+    assertThat(actual.values.flatten.toSeq.distinct.sorted, is(Seq(100, 101, 102)))\n+  }\n+\n+  @Test\n+  def shouldShrinkCluster() {\n+    //Given partitions on 3 of 3 brokers\n+    val brokers: Array[Int] = Array(100, 101, 102)\n+    startBrokers(brokers)\n+    createTopic(zkUtils, topicName, Map(\n+      0 -> Seq(100, 101),\n+      1 -> Seq(101, 102),\n+      2 -> Seq(102, 100)\n+    ), servers = servers)\n+\n+    //When rebalancing\n+    val newAssignment = ReassignPartitionsCommand.generateAssignment(zkUtils, Array(100, 101), json(topicName))._1\n+    ReassignPartitionsCommand.executeAssignment(zkUtils, zkUtils.formatAsReassignmentJson(newAssignment))\n+    waitFor(ReassignPartitionsPath)\n+\n+    //Then replicas should only span the first two brokers\n+    val actual = zkUtils.getPartitionAssignmentForTopics(Seq(topicName))(topicName)\n+    assertThat(actual.values.flatten.toSeq.distinct.sorted, is(Seq(100, 101)))\n+  }\n+\n+  def waitFor(path: String) {\n+    waitUntilTrue(() => !zkUtils.pathExists(path), s\"Znode $zkUtils.ReassignPartitionsPath wasn't created\")\n+  }\n+\n+  def json(topic: String): String = {\n+    \"{\\\"topics\\\": [{\\\"topic\\\": \\\"\" + topic + \"\\\"}],\\\"version\\\":1}\"","path":"core/src/test/scala/unit/kafka/admin/ReassignPartitionsTest.scala","position":110,"original_position":110,"commit_id":"b1c01cbd6dd7c6d1fae7c2e39afa7f7260cef3e2","original_commit_id":"b1c01cbd6dd7c6d1fae7c2e39afa7f7260cef3e2","user":{"login":"benstopford","id":1297498,"avatar_url":"https://avatars.githubusercontent.com/u/1297498?v=3","gravatar_id":"","url":"https://api.github.com/users/benstopford","html_url":"https://github.com/benstopford","followers_url":"https://api.github.com/users/benstopford/followers","following_url":"https://api.github.com/users/benstopford/following{/other_user}","gists_url":"https://api.github.com/users/benstopford/gists{/gist_id}","starred_url":"https://api.github.com/users/benstopford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benstopford/subscriptions","organizations_url":"https://api.github.com/users/benstopford/orgs","repos_url":"https://api.github.com/users/benstopford/repos","events_url":"https://api.github.com/users/benstopford/events{/privacy}","received_events_url":"https://api.github.com/users/benstopford/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-02-25T22:04:38Z","updated_at":"2016-02-25T22:04:38Z","html_url":"https://github.com/apache/kafka/pull/956#discussion_r54172975","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/956","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/54172975"},"html":{"href":"https://github.com/apache/kafka/pull/956#discussion_r54172975"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/956"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/956","id":60412935,"html_url":"https://github.com/apache/kafka/pull/956","diff_url":"https://github.com/apache/kafka/pull/956.diff","patch_url":"https://github.com/apache/kafka/pull/956.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/956","number":956,"state":"open","locked":false,"title":"Kafka 3270 Added some Happy Path Tests for the Reassign Partitions Command","user":{"login":"benstopford","id":1297498,"avatar_url":"https://avatars.githubusercontent.com/u/1297498?v=3","gravatar_id":"","url":"https://api.github.com/users/benstopford","html_url":"https://github.com/benstopford","followers_url":"https://api.github.com/users/benstopford/followers","following_url":"https://api.github.com/users/benstopford/following{/other_user}","gists_url":"https://api.github.com/users/benstopford/gists{/gist_id}","starred_url":"https://api.github.com/users/benstopford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benstopford/subscriptions","organizations_url":"https://api.github.com/users/benstopford/orgs","repos_url":"https://api.github.com/users/benstopford/repos","events_url":"https://api.github.com/users/benstopford/events{/privacy}","received_events_url":"https://api.github.com/users/benstopford/received_events","type":"User","site_admin":false},"body":"with help from @enothereska  :)","created_at":"2016-02-23T21:29:10Z","updated_at":"2016-02-25T22:04:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9095d949badc7a58acf25c19d700d60daef7fd5b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/956/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/956/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/956/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/b1c01cbd6dd7c6d1fae7c2e39afa7f7260cef3e2","head":{"label":"benstopford:KAFKA-3270-ReassignPartitionsCommand-Tests","ref":"KAFKA-3270-ReassignPartitionsCommand-Tests","sha":"b1c01cbd6dd7c6d1fae7c2e39afa7f7260cef3e2","user":{"login":"benstopford","id":1297498,"avatar_url":"https://avatars.githubusercontent.com/u/1297498?v=3","gravatar_id":"","url":"https://api.github.com/users/benstopford","html_url":"https://github.com/benstopford","followers_url":"https://api.github.com/users/benstopford/followers","following_url":"https://api.github.com/users/benstopford/following{/other_user}","gists_url":"https://api.github.com/users/benstopford/gists{/gist_id}","starred_url":"https://api.github.com/users/benstopford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benstopford/subscriptions","organizations_url":"https://api.github.com/users/benstopford/orgs","repos_url":"https://api.github.com/users/benstopford/repos","events_url":"https://api.github.com/users/benstopford/events{/privacy}","received_events_url":"https://api.github.com/users/benstopford/received_events","type":"User","site_admin":false},"repo":{"id":40359697,"name":"kafka","full_name":"benstopford/kafka","owner":{"login":"benstopford","id":1297498,"avatar_url":"https://avatars.githubusercontent.com/u/1297498?v=3","gravatar_id":"","url":"https://api.github.com/users/benstopford","html_url":"https://github.com/benstopford","followers_url":"https://api.github.com/users/benstopford/followers","following_url":"https://api.github.com/users/benstopford/following{/other_user}","gists_url":"https://api.github.com/users/benstopford/gists{/gist_id}","starred_url":"https://api.github.com/users/benstopford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benstopford/subscriptions","organizations_url":"https://api.github.com/users/benstopford/orgs","repos_url":"https://api.github.com/users/benstopford/repos","events_url":"https://api.github.com/users/benstopford/events{/privacy}","received_events_url":"https://api.github.com/users/benstopford/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/benstopford/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/benstopford/kafka","forks_url":"https://api.github.com/repos/benstopford/kafka/forks","keys_url":"https://api.github.com/repos/benstopford/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/benstopford/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/benstopford/kafka/teams","hooks_url":"https://api.github.com/repos/benstopford/kafka/hooks","issue_events_url":"https://api.github.com/repos/benstopford/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/benstopford/kafka/events","assignees_url":"https://api.github.com/repos/benstopford/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/benstopford/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/benstopford/kafka/tags","blobs_url":"https://api.github.com/repos/benstopford/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/benstopford/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/benstopford/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/benstopford/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/benstopford/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/benstopford/kafka/languages","stargazers_url":"https://api.github.com/repos/benstopford/kafka/stargazers","contributors_url":"https://api.github.com/repos/benstopford/kafka/contributors","subscribers_url":"https://api.github.com/repos/benstopford/kafka/subscribers","subscription_url":"https://api.github.com/repos/benstopford/kafka/subscription","commits_url":"https://api.github.com/repos/benstopford/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/benstopford/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/benstopford/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/benstopford/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/benstopford/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/benstopford/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/benstopford/kafka/merges","archive_url":"https://api.github.com/repos/benstopford/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/benstopford/kafka/downloads","issues_url":"https://api.github.com/repos/benstopford/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/benstopford/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/benstopford/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/benstopford/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/benstopford/kafka/labels{/name}","releases_url":"https://api.github.com/repos/benstopford/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/benstopford/kafka/deployments","created_at":"2015-08-07T12:36:48Z","updated_at":"2016-01-25T13:54:01Z","pushed_at":"2016-02-24T07:43:29Z","git_url":"git://github.com/benstopford/kafka.git","ssh_url":"git@github.com:benstopford/kafka.git","clone_url":"https://github.com/benstopford/kafka.git","svn_url":"https://github.com/benstopford/kafka","homepage":null,"size":26526,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"trunk"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"f7d019ed408fa988129be9af3689bfa4878bc627","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":2211243,"name":"kafka","full_name":"apache/kafka","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/kafka","description":"Mirror of Apache Kafka","fork":false,"url":"https://api.github.com/repos/apache/kafka","forks_url":"https://api.github.com/repos/apache/kafka/forks","keys_url":"https://api.github.com/repos/apache/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/kafka/teams","hooks_url":"https://api.github.com/repos/apache/kafka/hooks","issue_events_url":"https://api.github.com/repos/apache/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/apache/kafka/events","assignees_url":"https://api.github.com/repos/apache/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/apache/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/apache/kafka/tags","blobs_url":"https://api.github.com/repos/apache/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/kafka/languages","stargazers_url":"https://api.github.com/repos/apache/kafka/stargazers","contributors_url":"https://api.github.com/repos/apache/kafka/contributors","subscribers_url":"https://api.github.com/repos/apache/kafka/subscribers","subscription_url":"https://api.github.com/repos/apache/kafka/subscription","commits_url":"https://api.github.com/repos/apache/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/apache/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/kafka/merges","archive_url":"https://api.github.com/repos/apache/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/kafka/downloads","issues_url":"https://api.github.com/repos/apache/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/apache/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/kafka/labels{/name}","releases_url":"https://api.github.com/repos/apache/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/apache/kafka/deployments","created_at":"2011-08-15T18:06:16Z","updated_at":"2016-02-25T16:38:50Z","pushed_at":"2016-02-25T21:59:31Z","git_url":"git://github.com/apache/kafka.git","ssh_url":"git@github.com:apache/kafka.git","clone_url":"https://github.com/apache/kafka.git","svn_url":"https://github.com/apache/kafka","homepage":null,"size":34849,"stargazers_count":2673,"watchers_count":2673,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1612,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":140,"forks":1612,"open_issues":140,"watchers":2673,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/956"},"html":{"href":"https://github.com/apache/kafka/pull/956"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/956"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/956/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/956/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/956/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/b1c01cbd6dd7c6d1fae7c2e39afa7f7260cef3e2"}}}}