akka.actor.Props Java Examples
The following examples show how to use
akka.actor.Props.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueueActorRouterProducer.java From usergrid with Apache License 2.0 | 8 votes |
@Override public void produceRouter(ActorSystem system, String role) { ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create( system ).withRole( "io" ); system.actorOf( ClusterSingletonManager.props( Props.create( GuiceActorProducer.class, QueueActorRouter.class ), PoisonPill.getInstance(), settings ), "queueActorRouter" ); ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create( system ).withRole( role ); system.actorOf( ClusterSingletonProxy.props( "/user/queueActorRouter", proxySettings ), "queueActorRouterProxy" ); }
Example #2
Source File: DispatcherActor.java From ditto with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("unused") private DispatcherActor(final ActorRef enforcerActor, final ActorRef pubSubMediator, final Flow<ImmutableDispatch, ImmutableDispatch, NotUsed> handler) { super(WithDittoHeaders.class); enforcementConfig = DittoConciergeConfig.of( DefaultScopedConfig.dittoScoped(getContext().getSystem().settings().config()) ).getEnforcementConfig(); this.handler = handler; final Props props = ThingsAggregatorActor.props(enforcerActor); thingsAggregatorActor = getContext().actorOf(props, ThingsAggregatorActor.ACTOR_NAME); initActor(getSelf(), pubSubMediator); }
Example #3
Source File: CoffeeHouseTest.java From oreilly-reactive-architecture-student with Apache License 2.0 | 6 votes |
@Test public void shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure() { new JavaTestKit(system) {{ createActor(CoffeeHouse.class, "resend-prepare-coffee", () -> new CoffeeHouse(Integer.MAX_VALUE) { @Override protected ActorRef createBarista() { return getRef(); } @Override protected ActorRef createWaiter() { //stubbing out the waiter actor to always throw exception return context().actorOf(Props.create(AbstractActor.class, () -> new AbstractActor() { @Override public Receive createReceive() { return receiveBuilder().matchAny(o -> { throw new Waiter.FrustratedException(new Coffee.Akkaccino(), system.deadLetters()); }).build(); } }), "waiter"); } }); ActorRef waiter = expectActor(this, "/user/resend-prepare-coffee/waiter"); waiter.tell("Blow up", ActorRef.noSender()); expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), system.deadLetters())); }}; }
Example #4
Source File: AppConfiguration.java From searchanalytics-bigdata with MIT License | 6 votes |
@Bean(autowire = Autowire.BY_NAME, name = "setupIndexMasterActor") // @Scope("prototype") @DependsOn(value = { "actorSystem" }) public ActorRef setupIndexMasterActor() { final ActorSystem system = applicationContext .getBean(ActorSystem.class); final SetupIndexService setupIndexService = applicationContext .getBean(SetupIndexService.class); final SampleDataGeneratorService sampleDataGeneratorService = applicationContext .getBean(SampleDataGeneratorService.class); final IndexProductDataService indexProductData = applicationContext .getBean(IndexProductDataService.class); return system.actorOf( Props.create(SetupIndexMasterActor.class, setupIndexService, sampleDataGeneratorService, indexProductData) .withDispatcher("setupIndexMasterActorDispatch"), "setupIndexMasterActor"); }
Example #5
Source File: BaseClientActorTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldReconnectIfSocketIsClosed() { new TestKit(actorSystem) {{ final ConnectionId randomConnectionId = TestConstants.createRandomConnectionId(); final Connection connection = TestConstants.createConnection(randomConnectionId, new Target[0]) .toBuilder() .uri("amqps://username:[email protected]:65536") // port 65536 does not even exist ;) .build(); final Props props = DummyClientActor.props(connection, getRef(), getRef(), getRef(), delegate); final ActorRef dummyClientActor = watch(actorSystem.actorOf(props)); whenOpeningConnection(dummyClientActor, OpenConnection.of(randomConnectionId, DittoHeaders.empty()), getRef()); expectMsgClass(Status.Failure.class); thenExpectCleanupResourcesCalled(); Mockito.clearInvocations(delegate); thenExpectCleanupResourcesCalledAfterTimeout( connectivityConfig.getClientConfig().getConnectingMinTimeout()); thenExpectNoConnectClientCalled(); }}; }
Example #6
Source File: JmsConnectionHandlingActorTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void handleJmsDisconnect() throws JMSException { new TestKit(actorSystem) {{ final Props props = JMSConnectionHandlingActor.props(connection, e -> {}, jmsConnectionFactory); final ActorRef connectionHandlingActor = watch(actorSystem.actorOf(props)); final TestProbe origin = TestProbe.apply(actorSystem); connectionHandlingActor.tell(new AmqpClientActor.JmsDisconnect(origin.ref(), mockConnection), getRef()); final ClientDisconnected disconnected = expectMsgClass(ClientDisconnected.class); assertThat(disconnected.getOrigin()).contains(origin.ref()); verify(mockConnection).close(); }}; }
Example #7
Source File: BaseMWService.java From sunbird-lms-service with MIT License | 6 votes |
protected static void initRouters() { ProjectLogger.log("RequestRouter mode: " + RequestRouter.getMode(), LoggerEnum.INFO.name()); if (!RouterMode.OFF.name().equalsIgnoreCase(RequestRouter.getMode())) { requestRouter = system.actorOf( FromConfig.getInstance() .props(Props.create(RequestRouter.class).withDispatcher("rr-dispatcher")), RequestRouter.class.getSimpleName()); } ProjectLogger.log( "BackgroundRequestRouter mode: " + BackgroundRequestRouter.getMode(), LoggerEnum.INFO.name()); if (!RouterMode.OFF.name().equalsIgnoreCase(BackgroundRequestRouter.getMode())) { bgRequestRouter = system.actorOf( FromConfig.getInstance() .props( Props.create(BackgroundRequestRouter.class).withDispatcher("brr-dispatcher")), BackgroundRequestRouter.class.getSimpleName()); } }
Example #8
Source File: HiveMqtt5ClientActorTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void testSubscribeFails() { new TestKit(actorSystem) {{ final MockHiveMqtt5ClientFactory clientFactory = mockHiveMqtt5ClientFactory .withTestProbe(getRef()) .withFailingSubscribe(); final Props props = HiveMqtt5ClientActor.props(connection, getRef(), clientFactory, mockConnectionActor.ref()); final ActorRef mqttClientActor = actorSystem.actorOf(props, "mqttClientActor-testSubscribeFails"); mqttClientActor.tell(OpenConnection.of(connectionId, DittoHeaders.empty()), getRef()); expectMsgClass(Status.Failure.class); mqttClientActor.tell(CloseConnection.of(connectionId, DittoHeaders.empty()), getRef()); expectMsg(DISCONNECTED_SUCCESS); }}; }
Example #9
Source File: CoffeeHouseTest.java From oreilly-reactive-architecture-student with Apache License 2.0 | 6 votes |
@Test public void shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure() { new JavaTestKit(system) {{ createActor(CoffeeHouse.class, "resend-prepare-coffee", () -> new CoffeeHouse(Integer.MAX_VALUE) { @Override protected ActorRef createBarista() { return getRef(); } @Override protected ActorRef createWaiter() { //stubbing out the waiter actor to always throw exception return context().actorOf(Props.create(AbstractActor.class, () -> new AbstractActor() { @Override public Receive createReceive() { return receiveBuilder().matchAny(o -> { throw new Waiter.FrustratedException(new Coffee.Akkaccino(), system.deadLetters()); }).build(); } }), "waiter"); } }); ActorRef waiter = expectActor(this, "/user/resend-prepare-coffee/waiter"); waiter.tell("Blow up", ActorRef.noSender()); expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), system.deadLetters())); }}; }
Example #10
Source File: JmsConnectionHandlingActorTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void handleFailureWhenCreatingConsumers() throws JMSException { new TestKit(actorSystem) {{ final IllegalStateException exception = new IllegalStateException("failureOnCreateConsumer"); doThrow(exception).when(mockSession).createConsumer(any()); final Props props = JMSConnectionHandlingActor.props(connection, e -> {}, jmsConnectionFactory); final ActorRef connectionHandlingActor = watch(actorSystem.actorOf(props)); final TestProbe origin = TestProbe.apply(actorSystem); connectionHandlingActor.tell(new AmqpClientActor.JmsConnect(origin.ref()), getRef()); final ConnectionFailure connectionFailure1 = expectMsgClass(ConnectionFailure.class); assertThat(connectionFailure1.getOrigin()).contains(origin.ref()); assertThat(connectionFailure1.getFailure().cause()).isSameAs(exception); }}; }
Example #11
Source File: SystemSettingsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Before public void setUp() { system = ActorSystem.create("system"); probe = new TestKit(system); PowerMockito.mockStatic(ServiceFactory.class); cassandraOperation = PowerMockito.mock(CassandraOperationImpl.class); when(ServiceFactory.getInstance()).thenReturn(cassandraOperation); props = Props.create(SystemSettingsActor.class); subject = system.actorOf(props); actorMessage = new Request(); PowerMockito.mockStatic(EsClientFactory.class); esUtil = PowerMockito.mock(ElasticSearchRestHighImpl.class); Response resp = new Response(); List<Map<String, Object>> list = new ArrayList<>(); list.add(getOrgData()); resp.put(JsonKey.RESPONSE, list); when(cassandraOperation.getRecordsByIndexedProperty( KEYSPACE_NAME, TABLE_NAME, JsonKey.FIELD, ROOT_ORG_ID)) .thenReturn(resp); when(cassandraOperation.getRecordsByIndexedProperty( KEYSPACE_NAME, TABLE_NAME, JsonKey.FIELD, KEYSPACE_NAME)) .thenReturn(new Response()); }
Example #12
Source File: AkkaActorSystemTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void shutsDownOnActorFailure() { final ActorSystem actorSystem = AkkaUtils.createLocalActorSystem(new Configuration()); try { final CompletableFuture<Terminated> terminationFuture = actorSystem.getWhenTerminated().toCompletableFuture(); final ActorRef actorRef = actorSystem.actorOf(Props.create(SimpleActor.class)); final FlinkException cause = new FlinkException("Flink test exception"); actorRef.tell(Fail.exceptionally(cause), ActorRef.noSender()); // make sure that the ActorSystem shuts down terminationFuture.join(); } finally { AkkaUtils.terminateActorSystem(actorSystem).join(); } }
Example #13
Source File: ClusterSingleton.java From ts-reaktive with MIT License | 6 votes |
/** * Starts and returns the an {@link ActorRef} to the {@link ClusterSingletonManager} (and backoff supervisor) * that manage this actor singleton. * * Note that you can't send this ActorRef messages that should go to your actor: use {@link StartProxy} for that. * * @param constructor Constructor to pass to Props in order to actually create the actor */ public ActorRef start(ActorSystem system, Supplier<T> constructor) { Config config = system.settings().config().getConfig("ts-reaktive.actors.singleton"); Props backoffSupervisorProps = BackoffSupervisor.props( Backoff.onStop( Props.create(type, () -> constructor.get()), "actor", FiniteDuration.create(config.getDuration("min-backoff", SECONDS), SECONDS), FiniteDuration.create(config.getDuration("max-backoff", SECONDS), SECONDS), 0.2 ).withSupervisorStrategy(new OneForOneStrategy( DeciderBuilder .matchAny(e -> { log.info("{}: Stopping and awaiting restart.", name, e); return stop(); }) .build() )) ); return system.actorOf( ClusterSingletonManager.props(backoffSupervisorProps, PoisonPill.getInstance(), ClusterSingletonManagerSettings.create(system) ), name); }
Example #14
Source File: PingWorkerTest.java From parallec with Apache License 2.0 | 6 votes |
@Test public void testTcpWorkerBadMsgType() { logger.info("IN testTcpWorkerBadMsgType"); ActorRef asyncWorker = null; try { int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(PingWorker.class, actorMaxOperationTimeoutSec, getPingMetaSample(), "www.google.com")); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, new Integer(0), new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #15
Source File: WorkFlowExecutionControllerTest.java From flux with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { Thread.sleep(1000); workFlowExecutionController = new WorkFlowExecutionController(eventsDAO, stateMachinesDAO, statesDAO, auditDAO, executionNodeTaskDispatcher, redriverRegistry, metricsClient, clientElbPersistenceService); when(stateMachinesDAO.findById(anyString())).thenReturn(TestUtils.getStandardTestMachineWithId()); when(clientElbPersistenceService.findByIdClientElb(anyString())).thenReturn("http://localhost:9997"); actorSystem = ActorSystem.create("testActorSystem",ConfigFactory.load("testAkkaActorSystem")); mockActor = TestActorRef.create(actorSystem, Props.create(MockActorRef.class)); when(routerRegistry.getRouter(anyString())).thenReturn(mockActor); objectMapper = new ObjectMapper(); }
Example #16
Source File: AmqpClientActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void testExceptionDuringJMSConnectionCreation() { new TestKit(actorSystem) {{ final Props props = AmqpClientActor.propsForTests(connection, getRef(), getRef(), (theConnection, exceptionListener) -> { throw JMS_EXCEPTION; }); final ActorRef connectionActor = actorSystem.actorOf(props); connectionActor.tell(OpenConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef()); expectMsg(new Status.Failure(SESSION_EXCEPTION)); }}; }
Example #17
Source File: ConnectionPersistenceOperationsActorIT.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override protected ActorRef startEntityActor(final ActorSystem system, final ActorRef pubSubMediator, final ConnectionId id) { // essentially never restart final TestProbe conciergeForwarderProbe = new TestProbe(system, "conciergeForwarder"); final ConnectivityCommandInterceptor dummyInterceptor = (command, connectionSupplier) -> {}; final ClientActorPropsFactory entityActorFactory = DefaultClientActorPropsFactory.getInstance(); final Props props = ConnectionSupervisorActor.props(nopSub(), conciergeForwarderProbe.ref(), entityActorFactory, dummyInterceptor, pubSubMediator); return system.actorOf(props, String.valueOf(id)); }
Example #18
Source File: CoffeeHouseApp.java From oreilly-reactive-architecture-student with Apache License 2.0 | 5 votes |
private static Props printerProps(ActorRef coffeeHouse) { return Props.create(AbstractLoggingActor.class, () -> new AbstractLoggingActor() { @Override public Receive createReceive() { return receiveBuilder().matchAny(o -> log().info(o.toString())).build(); } { coffeeHouse.tell("Brew Coffee", self()); } }); }
Example #19
Source File: ShardRegionFactory.java From ditto with Eclipse Public License 2.0 | 5 votes |
/** * Returns a new Sharding Region for the Search Updater. * * @param numberOfShards the number of shards to use. * @param thingUpdaterProps the Props of the ThingUpdater actor. * @return the Sharding Region. * @throws NullPointerException if {@code thingUpdaterProps} is {@code null}. */ @Nonnull public ActorRef getSearchUpdaterShardRegion(final int numberOfShards, @Nonnull final Props thingUpdaterProps, final String clusterRole) { checkNotNull(thingUpdaterProps, "Props of ThingUpdater"); final ClusterSharding clusterSharding = ClusterSharding.get(actorSystem); final ClusterShardingSettings shardingSettings = ClusterShardingSettings.create(actorSystem).withRole(clusterRole); final ShardRegionExtractor shardRegionExtractor = ShardRegionExtractor.of(numberOfShards, actorSystem); return clusterSharding.start(UPDATER_SHARD_REGION, thingUpdaterProps, shardingSettings, shardRegionExtractor); }
Example #20
Source File: Application.java From java-11-examples with Apache License 2.0 | 5 votes |
public void init() { LOG.info("Application init ..."); sshClusterManager = new SshClusterManagerImpl(); sshClusterManagerActor = actorSystem.actorOf( Props.create(SshClusterManagerActor.class, sshClusterManager), Utils.CLUSTER_MANAGER_NAME); sshLocalManager = new SshLocalManagerImpl(sshSessionFactory); sshLocalManagerActor = actorSystem.actorOf( Props.create(SshLocalManagerActor.class, sshLocalManager), Utils.LOCAL_MANAGER_NAME); sshClientService = new SshClientServiceImpl(actorSystem, sshClusterManager); LOG.info("Application done."); }
Example #21
Source File: RequestActorBuilder.java From servicecomb-saga-actuator with Apache License 2.0 | 5 votes |
private ActorRef leafActor(RequestActorContext context, Map<String, SagaTask> tasks) { Props leaf = RequestActor.props(context, tasks.get( NoOpSagaRequest.SAGA_END_REQUEST.task()), NoOpSagaRequest.SAGA_END_REQUEST); ActorRef actor = actorSystem.actorOf(leaf); context.addActor(NoOpSagaRequest.SAGA_END_REQUEST.id(), actor); return actor; }
Example #22
Source File: UdpWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testUdpWorkerNormalCheckComplete() { ActorRef asyncWorker = null; logger.info("IN testUdpWorkerNormalCheckComplete"); try { // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(UdpWorker.class, actorMaxOperationTimeoutSec, getUdpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #23
Source File: HelloWorld.java From tools-journey with Apache License 2.0 | 5 votes |
@Override public void preStart() { // create the greeter actor final ActorRef greeter = getContext().actorOf(Props.create(Greeter.class), "greeter"); // tell it to perform the greeting greeter.tell(Greeter.Msg.GREET, self()); }
Example #24
Source File: AbstractPubSubFactory.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public DistributedSub startDistributedSub() { final String subSupervisorName = factoryId + "-sub-supervisor"; final Props subSupervisorProps = SubSupervisor.props(messageClass, topicExtractor, ddata); final ActorRef subSupervisor = actorRefFactory.actorOf(subSupervisorProps, subSupervisorName); return DistributedSub.of(ddataConfig, subSupervisor); }
Example #25
Source File: AbstractMqttClientActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void testRetrieveConnectionMetrics() { new TestKit(actorSystem) {{ final Source mqttSource = ConnectivityModelFactory.newSourceBuilder() .authorizationContext(AUTHORIZATION_CONTEXT) .index(2) .consumerCount(1) .address("topic1") .address("topic2") .qos(1) .build(); final Connection connectionWithAdditionalSources = connection.toBuilder() .sources(singletonList(mqttSource)).build(); final String modifyThing = TestConstants.modifyThing(); final Props props = createClientActorWithMessages(connectionWithAdditionalSources, getRef(), singletonList(mqttMessage(SOURCE_ADDRESS, modifyThing))); final ActorRef underTest = actorSystem.actorOf(props); final TestProbe controlProbe = TestProbe.apply(actorSystem); underTest.tell(OpenConnection.of(connection.getId(), DittoHeaders.empty()), controlProbe.ref()); LOGGER.info("Waiting for connected..."); controlProbe.expectMsg(CONNECTED_SUCCESS); expectMsgClass(ModifyThing.class); underTest.tell(RetrieveConnectionMetrics.of(connectionId, DittoHeaders.empty()), getRef()); final RetrieveConnectionMetricsResponse metricsResponse = expectMsgClass(RetrieveConnectionMetricsResponse.class); LOGGER.info("metrics: {}", metricsResponse); }}; }
Example #26
Source File: Server1Main.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
public static void main(String[] args) throws InterruptedException { // Override the configuration of the port // when specified as program argument System.setProperty("akka.remote.netty.tcp.port", "5557"); // Create an Akka system ActorSystem system = ActorSystem.create("ClusterSystem"); // Create an actor that handles cluster domain events ActorRef subscriber = system.actorOf(Props.create(Subscriber.class), "subscriptor"); }
Example #27
Source File: TcpWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
/** * fake a NPE of logger; do not forget to reset it or other tests will fail. */ @Test public void testTcpWorkerException() { logger.info("IN testTcpWorkerException"); ActorRef asyncWorker = null; try { TcpWorker.setLogger(null); // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.CANCEL, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } TcpWorker.setLogger(LoggerFactory.getLogger(TcpWorker.class)); }
Example #28
Source File: SshWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testSshWorkerDupAndCancel() { ActorRef asyncWorker = null; try { // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(SshWorker.class, actorMaxOperationTimeoutSec, SshProviderMockTest.sshMetaPassword, hostIpSample)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); // test dup asyncWorker.tell(RequestWorkerMsgType.PROCESS_REQUEST, asyncWorker); // test cancel asyncWorker.tell(RequestWorkerMsgType.CANCEL, asyncWorker); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #29
Source File: AkkaSource.java From bahir-flink with Apache License 2.0 | 5 votes |
@Override public void run(SourceFunction.SourceContext<Object> ctx) throws Exception { LOG.info("Starting the Receiver actor {}", actorName); receiverActor = receiverActorSystem.actorOf( Props.create(classForActor, ctx, urlOfPublisher, autoAck), actorName); LOG.info("Started the Receiver actor {} successfully", actorName); Await.result(receiverActorSystem.whenTerminated(), Duration.Inf()); }
Example #30
Source File: AbstractMqttClientActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void testPublishToReplyTarget() { connection = connection.toBuilder() .setSources(TestConstants.Sources.SOURCES_WITH_AUTH_CONTEXT) .build(); new TestKit(actorSystem) {{ final TestProbe controlProbe = TestProbe.apply(actorSystem); final Props props = createClientActor(getRef(), getConnection(false)); final ActorRef underTest = actorSystem.actorOf(props); underTest.tell(OpenConnection.of(connectionId, DittoHeaders.empty()), controlProbe.ref()); controlProbe.expectMsg(CONNECTED_SUCCESS); final DittoHeaders dittoHeaders = DittoHeaders.newBuilder() .replyTarget(0) .build(); final DeleteThingResponse deleteThingResponse = DeleteThingResponse.of(ThingId.of("thing", "id"), dittoHeaders); LOGGER.info("Sending DeleteThingResponse: {}", deleteThingResponse); final Object outboundSignal = OutboundSignalFactory.newOutboundSignal(deleteThingResponse, Collections.emptyList()); underTest.tell(outboundSignal, getRef()); final M receivedMessage = expectMsgClass(getMessageClass()); assertThat(extractTopic(receivedMessage)).isEqualTo("replyTarget/thing:id"); underTest.tell(CloseConnection.of(connectionId, DittoHeaders.empty()), controlProbe.ref()); controlProbe.expectMsg(DISCONNECTED_SUCCESS); }}; }