{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/73292288","id":73292288,"diff_hunk":"@@ -0,0 +1,140 @@\n+/*\n+ * Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com>\n+ */\n+package akka.stream.scaladsl\n+\n+import akka.actor.{ ActorRef, DeathPactException, PoisonPill, Terminated }\n+import akka.event.Logging\n+import akka.stream.stage.{ GraphStage, GraphStageLogic, InHandler, OutHandler }\n+import akka.stream.testkit._\n+import akka.stream.testkit.scaladsl.TestSink\n+import akka.stream._\n+import akka.testkit.{ TestActors, TestProbe }\n+\n+import scala.concurrent.duration._\n+\n+class FlowDeathPactSpec extends StreamSpec with ScriptedTest {\n+\n+  val settings = ActorMaterializerSettings(system)\n+    .withInputBuffer(initialSize = 2, maxSize = 16)\n+\n+  implicit val materializer = ActorMaterializer(settings)\n+\n+  \"A FlowDeathPact\" must {\n+\n+    \"complete when contrActor terminates\" in {\n+      val devil = system.actorOf(TestActors.echoActorProps)\n+\n+      val deathPact: FlowDeathPact[String] = FlowDeathPact.completeStage(devil)\n+      val probe = Source.maybe[String].via(deathPact).runWith(TestSink.probe)\n+\n+      probe.expectSubscription()\n+      probe.expectNoMsg(100.millis)\n+\n+      devil ! PoisonPill\n+      probe.expectComplete()\n+    }\n+\n+    \"fail with DeathPactException when contrActor terminates\" in {\n+      val devil = system.actorOf(TestActors.echoActorProps)\n+\n+      val deathPact: FlowDeathPact[String] = FlowDeathPact.failStage(devil)\n+      val probe = Source.maybe[String].via(deathPact).runWith(TestSink.probe)\n+\n+      probe.expectSubscription()\n+\n+      devil ! PoisonPill\n+      val ex = probe.expectError()\n+      ex.getClass should ===(classOf[DeathPactException])\n+    }\n+\n+    \"inform contrActor that FlowDeathPact was Signed\" in {\n+      val contrActor = TestProbe()\n+\n+      val deathPact: FlowDeathPact[String] = FlowDeathPact.failStage(contrActor.ref)\n+      val probe = Source.empty.via(deathPact).runWith(TestSink.probe)\n+\n+      contrActor.expectMsg(FlowDeathPact.Signed)\n+\n+      probe.expectSubscriptionAndComplete()\n+    }\n+\n+    \"inform contrActor that when stream Failed\" in {\n+      val contrActor = TestProbe()\n+\n+      val deathPact: FlowDeathPact[String] = FlowDeathPact.failStage(contrActor.ref)\n+      val cause = new Exception(\"BOOM!\")\n+      val probe = Source.failed(cause).via(deathPact).runWith(TestSink.probe)\n+\n+      contrActor.expectMsg(FlowDeathPact.Signed)\n+      val failed = contrActor.expectMsgType[FlowDeathPact.Failed]\n+      failed.cause should ===(cause)\n+\n+      probe.expectSubscription().request(1)\n+      probe.expectError(cause)\n+    }\n+\n+    \"inform contrActor that when stream Completed\" in {\n+      val contrActor = TestProbe()\n+\n+      val deathPact: FlowDeathPact[String] = FlowDeathPact.failStage(contrActor.ref)\n+      val probe = Source.empty.via(deathPact).runWith(TestSink.probe)\n+\n+      contrActor.expectMsg(FlowDeathPact.Signed)\n+      contrActor.expectMsg(FlowDeathPact.Completed)\n+      info(\"Stage sender: \" + contrActor.lastSender)\n+      probe.expectSubscriptionAndComplete()\n+    }\n+\n+  }\n+\n+}\n+\n+/** INTERNAL API */\n+/*private[akka]*/ final class FlowDeathPact[T](ref: ActorRef, onTerminated: GraphStageLogic ⇒ Unit)\n+  extends GraphStage[FlowShape[T, T]] {\n+\n+  val in = Inlet[T](\"FlowDeathPact.in\")\n+  val out = Outlet[T](\"FlowDeathPact.out\")\n+  override val shape = FlowShape(in, out)\n+\n+  override def createLogic(inheritedAttributes: Attributes) = new GraphStageLogic(shape) \n+    with InHandler with OutHandler {\n+\n+    override def preStart(): Unit = {\n+      getStageActor({\n+        case (_, Terminated(`ref`)) ⇒ onTerminated(this)\n+        case _                      ⇒ // ignore...\n+      })\n+      stageActor.watch(ref)\n+      ref.tell(FlowDeathPact.Signed, stageActor.ref)","path":"akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDeathPactSpec.scala","position":110,"original_position":110,"commit_id":"0211bdd80aa1dfa1c2517b09877489d5eb6ebde8","original_commit_id":"0211bdd80aa1dfa1c2517b09877489d5eb6ebde8","user":{"login":"drewhk","id":932285,"avatar_url":"https://avatars.githubusercontent.com/u/932285?v=3","gravatar_id":"","url":"https://api.github.com/users/drewhk","html_url":"https://github.com/drewhk","followers_url":"https://api.github.com/users/drewhk/followers","following_url":"https://api.github.com/users/drewhk/following{/other_user}","gists_url":"https://api.github.com/users/drewhk/gists{/gist_id}","starred_url":"https://api.github.com/users/drewhk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewhk/subscriptions","organizations_url":"https://api.github.com/users/drewhk/orgs","repos_url":"https://api.github.com/users/drewhk/repos","events_url":"https://api.github.com/users/drewhk/events{/privacy}","received_events_url":"https://api.github.com/users/drewhk/received_events","type":"User","site_admin":false},"body":"For that, the ActorRef is enough. Plus, the built-in watch mechanism is much more reliable and works over the wire. Hence I think it is much better to expose the stage ActorRef and let the other side watch it if it wants to.","created_at":"2016-08-03T07:30:38Z","updated_at":"2016-08-03T07:30:38Z","html_url":"https://github.com/akka/akka/pull/21076#discussion_r73292288","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/21076","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/73292288"},"html":{"href":"https://github.com/akka/akka/pull/21076#discussion_r73292288"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/21076"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/21076","id":79470124,"html_url":"https://github.com/akka/akka/pull/21076","diff_url":"https://github.com/akka/akka/pull/21076.diff","patch_url":"https://github.com/akka/akka/pull/21076.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/21076","number":21076,"state":"open","locked":false,"title":"FlowDeathPact","user":{"login":"ktoso","id":120979,"avatar_url":"https://avatars.githubusercontent.com/u/120979?v=3","gravatar_id":"","url":"https://api.github.com/users/ktoso","html_url":"https://github.com/ktoso","followers_url":"https://api.github.com/users/ktoso/followers","following_url":"https://api.github.com/users/ktoso/following{/other_user}","gists_url":"https://api.github.com/users/ktoso/gists{/gist_id}","starred_url":"https://api.github.com/users/ktoso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktoso/subscriptions","organizations_url":"https://api.github.com/users/ktoso/orgs","repos_url":"https://api.github.com/users/ktoso/repos","events_url":"https://api.github.com/users/ktoso/events{/privacy}","received_events_url":"https://api.github.com/users/ktoso/received_events","type":"User","site_admin":false},"body":"I implemented this as a response to the mailing list, but actually thought it might be very useful in general, WDYT?\r\n\r\n","created_at":"2016-07-30T22:49:42Z","updated_at":"2016-08-03T07:30:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d0b7a1438a5d5fba5dd0739237a68e8685bc5a7d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/21076/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/21076/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/21076/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/0211bdd80aa1dfa1c2517b09877489d5eb6ebde8","head":{"label":"ktoso:wip-flow-death-pact-ktoso","ref":"wip-flow-death-pact-ktoso","sha":"0211bdd80aa1dfa1c2517b09877489d5eb6ebde8","user":{"login":"ktoso","id":120979,"avatar_url":"https://avatars.githubusercontent.com/u/120979?v=3","gravatar_id":"","url":"https://api.github.com/users/ktoso","html_url":"https://github.com/ktoso","followers_url":"https://api.github.com/users/ktoso/followers","following_url":"https://api.github.com/users/ktoso/following{/other_user}","gists_url":"https://api.github.com/users/ktoso/gists{/gist_id}","starred_url":"https://api.github.com/users/ktoso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktoso/subscriptions","organizations_url":"https://api.github.com/users/ktoso/orgs","repos_url":"https://api.github.com/users/ktoso/repos","events_url":"https://api.github.com/users/ktoso/events{/privacy}","received_events_url":"https://api.github.com/users/ktoso/received_events","type":"User","site_admin":false},"repo":{"id":4462204,"name":"akka","full_name":"ktoso/akka","owner":{"login":"ktoso","id":120979,"avatar_url":"https://avatars.githubusercontent.com/u/120979?v=3","gravatar_id":"","url":"https://api.github.com/users/ktoso","html_url":"https://github.com/ktoso","followers_url":"https://api.github.com/users/ktoso/followers","following_url":"https://api.github.com/users/ktoso/following{/other_user}","gists_url":"https://api.github.com/users/ktoso/gists{/gist_id}","starred_url":"https://api.github.com/users/ktoso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktoso/subscriptions","organizations_url":"https://api.github.com/users/ktoso/orgs","repos_url":"https://api.github.com/users/ktoso/repos","events_url":"https://api.github.com/users/ktoso/events{/privacy}","received_events_url":"https://api.github.com/users/ktoso/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ktoso/akka","description":"Akka Project","fork":true,"url":"https://api.github.com/repos/ktoso/akka","forks_url":"https://api.github.com/repos/ktoso/akka/forks","keys_url":"https://api.github.com/repos/ktoso/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ktoso/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ktoso/akka/teams","hooks_url":"https://api.github.com/repos/ktoso/akka/hooks","issue_events_url":"https://api.github.com/repos/ktoso/akka/issues/events{/number}","events_url":"https://api.github.com/repos/ktoso/akka/events","assignees_url":"https://api.github.com/repos/ktoso/akka/assignees{/user}","branches_url":"https://api.github.com/repos/ktoso/akka/branches{/branch}","tags_url":"https://api.github.com/repos/ktoso/akka/tags","blobs_url":"https://api.github.com/repos/ktoso/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ktoso/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ktoso/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/ktoso/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ktoso/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/ktoso/akka/languages","stargazers_url":"https://api.github.com/repos/ktoso/akka/stargazers","contributors_url":"https://api.github.com/repos/ktoso/akka/contributors","subscribers_url":"https://api.github.com/repos/ktoso/akka/subscribers","subscription_url":"https://api.github.com/repos/ktoso/akka/subscription","commits_url":"https://api.github.com/repos/ktoso/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/ktoso/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/ktoso/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/ktoso/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/ktoso/akka/contents/{+path}","compare_url":"https://api.github.com/repos/ktoso/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ktoso/akka/merges","archive_url":"https://api.github.com/repos/ktoso/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ktoso/akka/downloads","issues_url":"https://api.github.com/repos/ktoso/akka/issues{/number}","pulls_url":"https://api.github.com/repos/ktoso/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/ktoso/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/ktoso/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ktoso/akka/labels{/name}","releases_url":"https://api.github.com/repos/ktoso/akka/releases{/id}","deployments_url":"https://api.github.com/repos/ktoso/akka/deployments","created_at":"2012-05-27T14:05:17Z","updated_at":"2016-08-02T17:31:20Z","pushed_at":"2016-08-02T13:58:46Z","git_url":"git://github.com/ktoso/akka.git","ssh_url":"git@github.com:ktoso/akka.git","clone_url":"https://github.com/ktoso/akka.git","svn_url":"https://github.com/ktoso/akka","homepage":"http://akka.io","size":193954,"stargazers_count":1,"watchers_count":1,"language":"Scala","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":1,"default_branch":"master"}},"base":{"label":"akka:master","ref":"master","sha":"65d96761641af848ef823ad858d2ca9175dc75b0","user":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"repo":{"id":130013,"name":"akka","full_name":"akka/akka","owner":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akka/akka","description":"Akka Project","fork":false,"url":"https://api.github.com/repos/akka/akka","forks_url":"https://api.github.com/repos/akka/akka/forks","keys_url":"https://api.github.com/repos/akka/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akka/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akka/akka/teams","hooks_url":"https://api.github.com/repos/akka/akka/hooks","issue_events_url":"https://api.github.com/repos/akka/akka/issues/events{/number}","events_url":"https://api.github.com/repos/akka/akka/events","assignees_url":"https://api.github.com/repos/akka/akka/assignees{/user}","branches_url":"https://api.github.com/repos/akka/akka/branches{/branch}","tags_url":"https://api.github.com/repos/akka/akka/tags","blobs_url":"https://api.github.com/repos/akka/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akka/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akka/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/akka/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akka/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/akka/akka/languages","stargazers_url":"https://api.github.com/repos/akka/akka/stargazers","contributors_url":"https://api.github.com/repos/akka/akka/contributors","subscribers_url":"https://api.github.com/repos/akka/akka/subscribers","subscription_url":"https://api.github.com/repos/akka/akka/subscription","commits_url":"https://api.github.com/repos/akka/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/akka/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/akka/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/akka/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/akka/akka/contents/{+path}","compare_url":"https://api.github.com/repos/akka/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akka/akka/merges","archive_url":"https://api.github.com/repos/akka/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akka/akka/downloads","issues_url":"https://api.github.com/repos/akka/akka/issues{/number}","pulls_url":"https://api.github.com/repos/akka/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/akka/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/akka/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akka/akka/labels{/name}","releases_url":"https://api.github.com/repos/akka/akka/releases{/id}","deployments_url":"https://api.github.com/repos/akka/akka/deployments","created_at":"2009-02-16T12:51:54Z","updated_at":"2016-08-03T02:52:44Z","pushed_at":"2016-08-03T07:17:14Z","git_url":"git://github.com/akka/akka.git","ssh_url":"git@github.com:akka/akka.git","clone_url":"https://github.com/akka/akka.git","svn_url":"https://github.com/akka/akka","homepage":"http://akka.io","size":227280,"stargazers_count":5842,"watchers_count":5842,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1847,"mirror_url":null,"open_issues_count":695,"forks":1847,"open_issues":695,"watchers":5842,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/21076"},"html":{"href":"https://github.com/akka/akka/pull/21076"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/21076"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/21076/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/21076/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/21076/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/0211bdd80aa1dfa1c2517b09877489d5eb6ebde8"}}}}
{"actor":{"display_login":"drewhk"}}