You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "eloots (via GitHub)" <gi...@apache.org> on 2023/09/21 14:48:24 UTC

[GitHub] [incubator-pekko] eloots opened a new pull request, #667: Add a first test applying Scala 3 Union types

eloots opened a new pull request, #667:
URL: https://github.com/apache/incubator-pekko/pull/667

   Linked to #660 
   
   I've been looking at various tests in project `actor-typed-tests` and chose to add a test that is a refactoring of the `InteractionPatternsSpec.scala` test specification as this test applies a message adapter to handle responses from other actors. Other tests to which this could be applied are:
   
   ```
   actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/eventstream/EventStreamSpec.scala
   actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/scaladsl/ActorThreadSpec.scala
   actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/scaladsl/MessageAdapterSpec.scala
   actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/delivery/TestProducerWithAsk.scala
   actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/delivery/TestProducerWorkPulling.scala
   actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/delivery/TestProducer.scala
   actor-typed-tests/src/test/scala/docs/org/apache/pekko/typed/TailChopping.scala
   actor-typed-tests/src/test/scala/docs/org/apache/pekko/typed/InteractionPatternsSpec.scala
   actor-typed-tests/src/test/scala/docs/org/apache/pekko/typed/Aggregator.scala
   ```
   
   Before I would tackle any of the above, I'd like to get feedback first.
   
   What was changed:
   
   - Use InteractionPatternsSpec as an example for applying Scala 3's Union types to symplify actor code
     - Remove `WrappedBackendResponse` response message wrapper & `backendResponseMapper` message adapter
     - Use the union of the actor's public protocol (the `Translate` message (the only member of the `Command` ADT) and the possible responses from the backend (messages `JobStarted`, `JobProgress`, and `JobCompleted`): `private type CommandAndResponse = Command | Backend.Response`
     - Instead of utilising the message adaptor `ActorRef` in the `replyTo` field of the message sent to the backend, `context.self` is used instead
     - The internal (extended) `Behavior[CommandAndResponse]` is narrowed to `Behavior[Command]` at creation time
     - The two stage pattern matching on the response is replaced with a direct pattern match on the different possible reponse messages
   
   The diffs between the original and the new version:
   
   ```bash
   136d139
   <         private final case class WrappedBackendResponse(response: Backend.Response) extends Command
   137a141,142
   >         private type CommandAndResponse = Command | Backend.Response
   >
   139,141c144
   <           Behaviors.setup[Command] { context =>
   <             val backendResponseMapper: ActorRef[Backend.Response] =
   <               context.messageAdapter(rsp => WrappedBackendResponse(rsp))
   ---
   >           Behaviors.setup[CommandAndResponse] { context =>
   143,144c146,147
   <             def active(inProgress: Map[Int, ActorRef[URI]], count: Int): Behavior[Command] = {
   <               Behaviors.receiveMessage[Command] {
   ---
   >             def active(inProgress: Map[Int, ActorRef[URI]], count: Int): Behavior[CommandAndResponse] = {
   >               Behaviors.receiveMessage[CommandAndResponse] {
   147c150
   <                   backend ! Backend.StartTranslationJob(taskId, site, backendResponseMapper)
   ---
   >                   backend ! Backend.StartTranslationJob(taskId, site, context.self)
   150,162c153,162
   <                 case wrapped: WrappedBackendResponse =>
   <                   wrapped.response match {
   <                     case Backend.JobStarted(taskId) =>
   <                       context.log.info("Started {}", taskId)
   <                       Behaviors.same
   <                     case Backend.JobProgress(taskId, progress) =>
   <                       context.log.info2("Progress {}: {}", taskId, progress)
   <                       Behaviors.same
   <                     case Backend.JobCompleted(taskId, result) =>
   <                       context.log.info2("Completed {}: {}", taskId, result)
   <                       inProgress(taskId) ! result
   <                       active(inProgress - taskId, count)
   <                   }
   ---
   >                 case Backend.JobStarted(taskId) =>
   >                   context.log.info("Started {}", taskId)
   >                   Behaviors.same
   >                 case Backend.JobProgress(taskId, progress) =>
   >                   context.log.info2("Progress {}: {}", taskId, progress)
   >                   Behaviors.same
   >                 case Backend.JobCompleted(taskId, result) =>
   >                   context.log.info2("Completed {}: {}", taskId, result)
   >                   inProgress(taskId) ! result
   >                   active(inProgress - taskId, count)
   167c167
   <           }
   ---
   >           }.narrow
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] pjfanning merged pull request #667: Add a first test applying Scala 3 Union types

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] He-Pin commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1733286892

   @eloots Thank you. Would you like to add a document for it? or we merge this pr first and you can add it later? And your blog post would be a nice addition to show how to use the typed with Scala'3 Union Type.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] pjfanning commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1730040072

   It won't be in docs automatically. We'll need doc changes but in another PR. The idea of a Scala 3 tab won't work because the tabs are configured globally for the project. My preference would be to add a new Scala3 union type `.md` file and link to it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] eloots commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "eloots (via GitHub)" <gi...@apache.org>.
eloots commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1730044271

   @He-Pin 
   If you want to read some more about this: I wrote a blog post in two parts. I forgot to link them in the original issue. You can find them [here](https://blog.lunatech.com/posts/2020-02-12-using-dotty-union-types-with-akka-typed) and [here](https://blog.lunatech.com/posts/2020-02-19-using-dotty-union-types-with-akka-typed-part-II). Hope you enjoy the read!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] He-Pin commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1734835776

   @eloots The doc in `docs` project and just a simple markdown, after you change it ,you can use `paradoxBrowse` command to check if that's what you want:)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] eloots commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "eloots (via GitHub)" <gi...@apache.org>.
eloots commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1734818127

   @He-Pin
   
   > Would you like to add a document for it?
   
   Absolutely! I would like to update the [Interaction patterns](https://pekko.apache.org/docs/pekko/current/typed/interaction-patterns.html#fire-and-forget)  section and specifically the section about [Adapted Response](https://pekko.apache.org/docs/pekko/current/typed/interaction-patterns.html#adapted-response).
   
   Is there any documentation about how to update the documentation 🙂?
   
   It would be nice to add a new illustration about the changed concept of receiving responses using Union types, but I don’t know if the source of the current illustrations is available. If the new illustration could have the same look and feel that would be ideal.
   
   I can add links to the blogposts for sure.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] pjfanning commented on a diff in pull request #667: Add a first test applying Scala 3 Union types

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#discussion_r1333295506


##########
actor-typed-tests/src/test/scala-3/docs/org/apache/pekko/typed/InteractionPatterns3Spec.scala:
##########
@@ -0,0 +1,660 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>

Review Comment:
   That's fine. It is correct to keep the headers in this case then.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] eloots commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "eloots (via GitHub)" <gi...@apache.org>.
eloots commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1735590438

   Simple markdown. I can do that ;-) 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] pjfanning commented on a diff in pull request #667: Add a first test applying Scala 3 Union types

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#discussion_r1333275230


##########
actor-typed-tests/src/test/scala-3/docs/org/apache/pekko/typed/InteractionPatterns3Spec.scala:
##########
@@ -0,0 +1,660 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>

Review Comment:
   Is this code based on Lightbend code or is it your own? If it is your own, could you use a standard Apache header?
   
   An example - https://github.com/apache/incubator-pekko/blob/main/project/AddMetaInfLicenseFiles.scala#L1-L16
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] He-Pin commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1729932029

   @eloots It's flasky just ignore it for now, it's not related with your current PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] eloots commented on a diff in pull request #667: Add a first test applying Scala 3 Union types

Posted by "eloots (via GitHub)" <gi...@apache.org>.
eloots commented on code in PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#discussion_r1333291695


##########
actor-typed-tests/src/test/scala-3/docs/org/apache/pekko/typed/InteractionPatterns3Spec.scala:
##########
@@ -0,0 +1,660 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>

Review Comment:
   As the new file is a modified version of file [InteractionPatternsSpec.scala](https://github.com/apache/incubator-pekko/blob/main/actor-typed-tests/src/test/scala/docs/org/apache/pekko/typed/InteractionPatternsSpec.scala) in the Pekko repo, the header is a verbatim copy of the header in that file.
   
   I assume the Lightbend copyright header is there for a reason, unless it was left there in error. In the former case it should be kept in the new file, otherwise it should be removed in both files. Please advise.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] He-Pin commented on a diff in pull request #667: Add a first test applying Scala 3 Union types

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#discussion_r1333295238


##########
actor-typed-tests/src/test/scala-3/docs/org/apache/pekko/typed/InteractionPatterns3Spec.scala:
##########
@@ -0,0 +1,660 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>

Review Comment:
   If it's totol new, you can let the `headerCreate` sbt task to create the header.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] He-Pin commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1729944847

   @eloots I will need more time to understand your great mind, I will do this on this weekend.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] eloots commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "eloots (via GitHub)" <gi...@apache.org>.
eloots commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1730032541

   Just wondering; if this gets merged, does this end up in the documentation automatically?
   I raised the idea in the linked issue to add this in the docs in separate code tabs (a Scala 3 one next to the existing Scala one).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


[GitHub] [incubator-pekko] eloots commented on pull request #667: Add a first test applying Scala 3 Union types

Posted by "eloots (via GitHub)" <gi...@apache.org>.
eloots commented on PR #667:
URL: https://github.com/apache/incubator-pekko/pull/667#issuecomment-1729914693

   Just wondering as I'm new around here. How does the link validation work or pass? I see that some PR's pass this validation but this PR doesn't even though I think it doesn't change anything wrt. links.
   Also, how are the tests run (Pull Request / Check / Tests (pull_request)). I think the failing tests are failing because of the test I added. Just curious about how this works.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org