sfali commented on code in PR #1195: URL: https://github.com/apache/incubator-pekko/pull/1195#discussion_r1528933086
########## actor-typed-tests/src/test/java/org/apache/pekko/actor/typed/eventstream/EventStreamSuperClassDocTest.java: ########## @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.pekko.actor.typed.eventstream; + +import org.apache.pekko.actor.testkit.typed.javadsl.ActorTestKit; +import org.apache.pekko.actor.typed.ActorSystem; +import org.apache.pekko.actor.typed.Behavior; +import org.apache.pekko.actor.typed.javadsl.AbstractBehavior; +import org.apache.pekko.actor.typed.javadsl.ActorContext; +import org.apache.pekko.actor.typed.javadsl.Behaviors; +import org.apache.pekko.actor.typed.javadsl.Receive; +import org.junit.Test; +import org.scalatestplus.junit.JUnitSuite; + +// #listen-to-super-class-imports +import org.apache.pekko.actor.DeadLetter; +import org.apache.pekko.actor.AllDeadLetters; +import org.apache.pekko.actor.Dropped; +import org.apache.pekko.actor.SuppressedDeadLetter; +import org.apache.pekko.actor.UnhandledMessage; +// #listen-to-super-class-imports + +public class EventStreamSuperClassDocTest extends JUnitSuite { + + @Test + public void listenToDeadLetters() { + // #subscribe-to-super-class + ActorSystem<Command> system = ActorSystem.create(AllDeadLettersListenerBehavior.create(), "AllDeadLettersListener"); + system.eventStream().tell(new EventStream.Subscribe<>(Command.class, system)); + // #subscribe-to-super-class + ActorTestKit.shutdown(system); + } + + // #listen-to-super-class + interface Command {} + + static final class AllDeadLettersWrapper implements Command { + private final AllDeadLetters allDeadLetters; + + public AllDeadLettersWrapper(AllDeadLetters deadLetter) { + this.allDeadLetters = deadLetter; + } + + public AllDeadLetters getAllDeadLetters() { + return allDeadLetters; + } + } + + static class AllDeadLettersListenerBehavior extends AbstractBehavior<Command> { + + public static Behavior<Command> create() { + return Behaviors.setup(AllDeadLettersListenerBehavior::new); + } + + public AllDeadLettersListenerBehavior(ActorContext<Command> context) { + super(context); + } + + @Override + public Receive<Command> createReceive() { + return newReceiveBuilder().onMessage(AllDeadLettersWrapper.class, msg -> { + final AllDeadLetters allDeadLetters = msg.allDeadLetters; + final Class<? extends AllDeadLetters> klass = msg.allDeadLetters.getClass(); + if (klass.isAssignableFrom(DeadLetter.class)) { Review Comment: Hmm, let me take a look. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
