{"action":"created","comment":{"url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/comments/125945566","pull_request_review_id":48385461,"id":125945566,"diff_hunk":"@@ -0,0 +1,300 @@\n+package servicetest\n+\n+import java.nio.charset.StandardCharsets\n+import java.nio.file.{Files, Paths, StandardOpenOption}\n+import java.time.LocalDateTime\n+import java.util.UUID\n+import java.util.concurrent.Executors\n+\n+import cakesolutions.kafka.KafkaConsumer\n+import com.whisk.docker.impl.dockerjava.DockerKitDockerJava\n+import com.whisk.docker.{\n+  ContainerLink,\n+  DockerCommandExecutor,\n+  DockerContainer,\n+  DockerContainerState,\n+  DockerReadyChecker,\n+  VolumeMapping\n+}\n+import kafka.admin.AdminUtils\n+import kafka.utils.ZkUtils\n+import org.apache.kafka.common.TopicPartition\n+import org.apache.kafka.common.protocol.Errors\n+import org.apache.kafka.common.serialization.StringDeserializer\n+import org.scalatest.concurrent.{Eventually, PatienceConfiguration, ScalaFutures}\n+import org.scalatest.time.{Seconds, Span}\n+import org.scalatest._\n+\n+import scala.concurrent.{ExecutionContext, Future}\n+import scala.concurrent.duration._\n+import scala.util.Try\n+\n+case class LogOutputAndWaitForLineThatContains(str: String, containerName: String) extends DockerReadyChecker {\n+\n+  val outputDir = Paths.get(\"target\", \"integration-test-logs\")\n+\n+  val outputFile = outputDir.resolve(s\"$containerName-${LocalDateTime.now().toString}.log\")\n+\n+  override def apply(container: DockerContainerState)(implicit docker: DockerCommandExecutor,\n+                                                      ec: ExecutionContext): Future[Boolean] = {\n+    println(s\"Waiting for container [$containerName] to become ready. Logs are being streamed to $outputFile.\")\n+\n+    for {\n+      id <- container.id\n+      _ <- docker.withLogStreamLinesRequirement(id, withErr = true) { line =>\n+        val lineWithLineEnding = if (line.endsWith(\"\\n\")) line else line + \"\\n\"\n+        Files.write(outputFile,\n+                    lineWithLineEnding.getBytes(StandardCharsets.UTF_8),\n+                    StandardOpenOption.CREATE,\n+                    StandardOpenOption.APPEND)\n+        val ready = line.contains(str)\n+        if (ready)\n+          println(s\"Container [$containerName] is ready\")\n+        ready\n+      }(docker, ec)\n+    } yield {\n+      true\n+    }\n+  }\n+}\n+\n+trait DockerIntegrationTest\n+    extends DockerKitDockerJava\n+    with ScalaFutures\n+    with TestSuite\n+    with BeforeAndAfterAll\n+    with Eventually {\n+\n+  override val StartContainersTimeout = 5.minutes\n+\n+  override implicit lazy val dockerExecutionContext: ExecutionContext = {\n+    // using Math.max to prevent unexpected zero length of docker containers\n+    ExecutionContext.fromExecutor(Executors.newFixedThreadPool(Math.max(1, dockerContainers.length * 4)))\n+  }\n+\n+  val hostIpAddress = {\n+    import sys.process._\n+    \"./get_ip_address.sh\".!!.trim\n+  }\n+\n+  // TODO currently no way to set the memory limit on docker containers. Need to make a PR to add support to docker-it-scala. I've checked that the spotify client supports it.\n+\n+  val aivenTopicNames = Seq(\n+    \"comms.triggered.v3\",\n+    \"comms.orchestrated.email.v3\",\n+    \"comms.orchestrated.sms.v2\",\n+    \"comms.composed.email.v2\",\n+    \"comms.composed.sms.v2\",\n+    \"comms.progressed.email.v2\",\n+    \"comms.progressed.sms.v2\",\n+    \"comms.link.clicked.v2\",\n+    \"comms.failed.v2\",\n+    \"comms.cancellation.requested.v2\",\n+    \"comms.failed.cancellation.v2\",\n+    \"comms.cancelled.v2\"\n+  )\n+\n+  val legacyTopicNames = aivenTopicNames ++ Seq(\n+      \"comms.triggered.v2\",\n+      \"comms.cancellation.requested\"\n+    )\n+\n+  val legacyZookeeper = DockerContainer(\"confluentinc/cp-zookeeper:3.1.1\", name = Some(\"legacyZookeeper\"))\n+    .withPorts(32181 -> Some(32181))\n+    .withEnv(\n+      \"ZOOKEEPER_CLIENT_PORT=32181\",\n+      \"ZOOKEEPER_TICK_TIME=2000\",\n+      \"KAFKA_HEAP_OPTS=-Xmx256M -Xms128M\"\n+    )\n+    .withReadyChecker(LogOutputAndWaitForLineThatContains(\"binding to port\", \"legacyZookeeper\"))\n+\n+  val legacyKafka = {\n+    // create each topic with 1 partition and replication factor 1\n+    val createTopicsString = legacyTopicNames.map(t => s\"$t:1:1\").mkString(\",\")\n+\n+    DockerContainer(\"wurstmeister/kafka:0.10.2.1\", name = Some(\"legacyKafka\"))\n+      .withPorts(29092 -> Some(29092))\n+      .withLinks(ContainerLink(legacyZookeeper, \"legacyZookeeper\"))\n+      .withEnv(\n+        \"KAFKA_BROKER_ID=1\",\n+        \"KAFKA_ZOOKEEPER_CONNECT=legacyZookeeper:32181\",\n+        \"KAFKA_PORT=29092\",\n+        \"KAFKA_ADVERTISED_PORT=29092\",\n+        s\"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://$hostIpAddress:29092\",\n+        \"KAFKA_HEAP_OPTS=-Xmx256M -Xms128M\",\n+        s\"KAFKA_CREATE_TOPICS=$createTopicsString\"\n+      )\n+      .withReadyChecker(LogOutputAndWaitForLineThatContains(\n+        \"\"\"Created topic \"comms.cancellation.requested\"\"\"\",","path":"src/servicetest/scala/servicetest/DockerIntegrationTest.scala","position":128,"original_position":128,"commit_id":"0fb461270f92f30d686763659a6ef0be06d12eb5","original_commit_id":"0fb461270f92f30d686763659a6ef0be06d12eb5","user":{"login":"cb372","id":106760,"avatar_url":"https://avatars2.githubusercontent.com/u/106760?v=3","gravatar_id":"","url":"https://api.github.com/users/cb372","html_url":"https://github.com/cb372","followers_url":"https://api.github.com/users/cb372/followers","following_url":"https://api.github.com/users/cb372/following{/other_user}","gists_url":"https://api.github.com/users/cb372/gists{/gist_id}","starred_url":"https://api.github.com/users/cb372/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cb372/subscriptions","organizations_url":"https://api.github.com/users/cb372/orgs","repos_url":"https://api.github.com/users/cb372/repos","events_url":"https://api.github.com/users/cb372/events{/privacy}","received_events_url":"https://api.github.com/users/cb372/received_events","type":"User","site_admin":false},"body":"This can be made slightly more robust in the face of adding more topics in the future. See https://github.com/ovotech/comms-audit-log/blob/master/src/servicetest/scala/servicetest/DockerIntegrationTest.scala#L136","created_at":"2017-07-06T16:11:51Z","updated_at":"2017-07-06T16:11:52Z","html_url":"https://github.com/ovotech/comms-delivery-service/pull/44#discussion_r125945566","pull_request_url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44","_links":{"self":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/comments/125945566"},"html":{"href":"https://github.com/ovotech/comms-delivery-service/pull/44#discussion_r125945566"},"pull_request":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44"}}},"pull_request":{"url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44","id":129215786,"html_url":"https://github.com/ovotech/comms-delivery-service/pull/44","diff_url":"https://github.com/ovotech/comms-delivery-service/pull/44.diff","patch_url":"https://github.com/ovotech/comms-delivery-service/pull/44.patch","issue_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/44","number":44,"state":"open","locked":false,"title":"Aiven Migration","user":{"login":"tommpy","id":7313608,"avatar_url":"https://avatars3.githubusercontent.com/u/7313608?v=3","gravatar_id":"","url":"https://api.github.com/users/tommpy","html_url":"https://github.com/tommpy","followers_url":"https://api.github.com/users/tommpy/followers","following_url":"https://api.github.com/users/tommpy/following{/other_user}","gists_url":"https://api.github.com/users/tommpy/gists{/gist_id}","starred_url":"https://api.github.com/users/tommpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tommpy/subscriptions","organizations_url":"https://api.github.com/users/tommpy/orgs","repos_url":"https://api.github.com/users/tommpy/repos","events_url":"https://api.github.com/users/tommpy/events{/privacy}","received_events_url":"https://api.github.com/users/tommpy/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-07-06T15:33:21Z","updated_at":"2017-07-06T16:11:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"74234123e23c1d1a3fc1c670915db0a96a57a09f","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44/commits","review_comments_url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44/comments","review_comment_url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/44/comments","statuses_url":"https://api.github.com/repos/ovotech/comms-delivery-service/statuses/0fb461270f92f30d686763659a6ef0be06d12eb5","head":{"label":"ovotech:deploy-to-uat","ref":"deploy-to-uat","sha":"0fb461270f92f30d686763659a6ef0be06d12eb5","user":{"login":"ovotech","id":3543199,"avatar_url":"https://avatars3.githubusercontent.com/u/3543199?v=3","gravatar_id":"","url":"https://api.github.com/users/ovotech","html_url":"https://github.com/ovotech","followers_url":"https://api.github.com/users/ovotech/followers","following_url":"https://api.github.com/users/ovotech/following{/other_user}","gists_url":"https://api.github.com/users/ovotech/gists{/gist_id}","starred_url":"https://api.github.com/users/ovotech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovotech/subscriptions","organizations_url":"https://api.github.com/users/ovotech/orgs","repos_url":"https://api.github.com/users/ovotech/repos","events_url":"https://api.github.com/users/ovotech/events{/privacy}","received_events_url":"https://api.github.com/users/ovotech/received_events","type":"Organization","site_admin":false},"repo":{"id":73913728,"name":"comms-delivery-service","full_name":"ovotech/comms-delivery-service","owner":{"login":"ovotech","id":3543199,"avatar_url":"https://avatars3.githubusercontent.com/u/3543199?v=3","gravatar_id":"","url":"https://api.github.com/users/ovotech","html_url":"https://github.com/ovotech","followers_url":"https://api.github.com/users/ovotech/followers","following_url":"https://api.github.com/users/ovotech/following{/other_user}","gists_url":"https://api.github.com/users/ovotech/gists{/gist_id}","starred_url":"https://api.github.com/users/ovotech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovotech/subscriptions","organizations_url":"https://api.github.com/users/ovotech/orgs","repos_url":"https://api.github.com/users/ovotech/repos","events_url":"https://api.github.com/users/ovotech/events{/privacy}","received_events_url":"https://api.github.com/users/ovotech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ovotech/comms-delivery-service","description":"Delivery of communications over various channels","fork":false,"url":"https://api.github.com/repos/ovotech/comms-delivery-service","forks_url":"https://api.github.com/repos/ovotech/comms-delivery-service/forks","keys_url":"https://api.github.com/repos/ovotech/comms-delivery-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ovotech/comms-delivery-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ovotech/comms-delivery-service/teams","hooks_url":"https://api.github.com/repos/ovotech/comms-delivery-service/hooks","issue_events_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/events{/number}","events_url":"https://api.github.com/repos/ovotech/comms-delivery-service/events","assignees_url":"https://api.github.com/repos/ovotech/comms-delivery-service/assignees{/user}","branches_url":"https://api.github.com/repos/ovotech/comms-delivery-service/branches{/branch}","tags_url":"https://api.github.com/repos/ovotech/comms-delivery-service/tags","blobs_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ovotech/comms-delivery-service/statuses/{sha}","languages_url":"https://api.github.com/repos/ovotech/comms-delivery-service/languages","stargazers_url":"https://api.github.com/repos/ovotech/comms-delivery-service/stargazers","contributors_url":"https://api.github.com/repos/ovotech/comms-delivery-service/contributors","subscribers_url":"https://api.github.com/repos/ovotech/comms-delivery-service/subscribers","subscription_url":"https://api.github.com/repos/ovotech/comms-delivery-service/subscription","commits_url":"https://api.github.com/repos/ovotech/comms-delivery-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/ovotech/comms-delivery-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/ovotech/comms-delivery-service/contents/{+path}","compare_url":"https://api.github.com/repos/ovotech/comms-delivery-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ovotech/comms-delivery-service/merges","archive_url":"https://api.github.com/repos/ovotech/comms-delivery-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ovotech/comms-delivery-service/downloads","issues_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues{/number}","pulls_url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls{/number}","milestones_url":"https://api.github.com/repos/ovotech/comms-delivery-service/milestones{/number}","notifications_url":"https://api.github.com/repos/ovotech/comms-delivery-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ovotech/comms-delivery-service/labels{/name}","releases_url":"https://api.github.com/repos/ovotech/comms-delivery-service/releases{/id}","deployments_url":"https://api.github.com/repos/ovotech/comms-delivery-service/deployments","created_at":"2016-11-16T11:29:48Z","updated_at":"2016-11-24T15:59:37Z","pushed_at":"2017-07-06T15:40:33Z","git_url":"git://github.com/ovotech/comms-delivery-service.git","ssh_url":"git@github.com:ovotech/comms-delivery-service.git","clone_url":"https://github.com/ovotech/comms-delivery-service.git","svn_url":"https://github.com/ovotech/comms-delivery-service","homepage":null,"size":304,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ovotech:master","ref":"master","sha":"7e0d85d2547625a51e860e65601015fe85fbbd91","user":{"login":"ovotech","id":3543199,"avatar_url":"https://avatars3.githubusercontent.com/u/3543199?v=3","gravatar_id":"","url":"https://api.github.com/users/ovotech","html_url":"https://github.com/ovotech","followers_url":"https://api.github.com/users/ovotech/followers","following_url":"https://api.github.com/users/ovotech/following{/other_user}","gists_url":"https://api.github.com/users/ovotech/gists{/gist_id}","starred_url":"https://api.github.com/users/ovotech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovotech/subscriptions","organizations_url":"https://api.github.com/users/ovotech/orgs","repos_url":"https://api.github.com/users/ovotech/repos","events_url":"https://api.github.com/users/ovotech/events{/privacy}","received_events_url":"https://api.github.com/users/ovotech/received_events","type":"Organization","site_admin":false},"repo":{"id":73913728,"name":"comms-delivery-service","full_name":"ovotech/comms-delivery-service","owner":{"login":"ovotech","id":3543199,"avatar_url":"https://avatars3.githubusercontent.com/u/3543199?v=3","gravatar_id":"","url":"https://api.github.com/users/ovotech","html_url":"https://github.com/ovotech","followers_url":"https://api.github.com/users/ovotech/followers","following_url":"https://api.github.com/users/ovotech/following{/other_user}","gists_url":"https://api.github.com/users/ovotech/gists{/gist_id}","starred_url":"https://api.github.com/users/ovotech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovotech/subscriptions","organizations_url":"https://api.github.com/users/ovotech/orgs","repos_url":"https://api.github.com/users/ovotech/repos","events_url":"https://api.github.com/users/ovotech/events{/privacy}","received_events_url":"https://api.github.com/users/ovotech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ovotech/comms-delivery-service","description":"Delivery of communications over various channels","fork":false,"url":"https://api.github.com/repos/ovotech/comms-delivery-service","forks_url":"https://api.github.com/repos/ovotech/comms-delivery-service/forks","keys_url":"https://api.github.com/repos/ovotech/comms-delivery-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ovotech/comms-delivery-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ovotech/comms-delivery-service/teams","hooks_url":"https://api.github.com/repos/ovotech/comms-delivery-service/hooks","issue_events_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/events{/number}","events_url":"https://api.github.com/repos/ovotech/comms-delivery-service/events","assignees_url":"https://api.github.com/repos/ovotech/comms-delivery-service/assignees{/user}","branches_url":"https://api.github.com/repos/ovotech/comms-delivery-service/branches{/branch}","tags_url":"https://api.github.com/repos/ovotech/comms-delivery-service/tags","blobs_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ovotech/comms-delivery-service/statuses/{sha}","languages_url":"https://api.github.com/repos/ovotech/comms-delivery-service/languages","stargazers_url":"https://api.github.com/repos/ovotech/comms-delivery-service/stargazers","contributors_url":"https://api.github.com/repos/ovotech/comms-delivery-service/contributors","subscribers_url":"https://api.github.com/repos/ovotech/comms-delivery-service/subscribers","subscription_url":"https://api.github.com/repos/ovotech/comms-delivery-service/subscription","commits_url":"https://api.github.com/repos/ovotech/comms-delivery-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/ovotech/comms-delivery-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/ovotech/comms-delivery-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/ovotech/comms-delivery-service/contents/{+path}","compare_url":"https://api.github.com/repos/ovotech/comms-delivery-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ovotech/comms-delivery-service/merges","archive_url":"https://api.github.com/repos/ovotech/comms-delivery-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ovotech/comms-delivery-service/downloads","issues_url":"https://api.github.com/repos/ovotech/comms-delivery-service/issues{/number}","pulls_url":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls{/number}","milestones_url":"https://api.github.com/repos/ovotech/comms-delivery-service/milestones{/number}","notifications_url":"https://api.github.com/repos/ovotech/comms-delivery-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ovotech/comms-delivery-service/labels{/name}","releases_url":"https://api.github.com/repos/ovotech/comms-delivery-service/releases{/id}","deployments_url":"https://api.github.com/repos/ovotech/comms-delivery-service/deployments","created_at":"2016-11-16T11:29:48Z","updated_at":"2016-11-24T15:59:37Z","pushed_at":"2017-07-06T15:40:33Z","git_url":"git://github.com/ovotech/comms-delivery-service.git","ssh_url":"git@github.com:ovotech/comms-delivery-service.git","clone_url":"https://github.com/ovotech/comms-delivery-service.git","svn_url":"https://github.com/ovotech/comms-delivery-service","homepage":null,"size":304,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44"},"html":{"href":"https://github.com/ovotech/comms-delivery-service/pull/44"},"issue":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/44"},"comments":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/issues/44/comments"},"review_comments":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44/comments"},"review_comment":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/pulls/44/commits"},"statuses":{"href":"https://api.github.com/repos/ovotech/comms-delivery-service/statuses/0fb461270f92f30d686763659a6ef0be06d12eb5"}}}}
{"actor":{"display_login":"cb372"}}