Java Code Examples for akka.testkit.TestProbe#expectMsgClass()

The following examples show how to use akka.testkit.TestProbe#expectMsgClass() . 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: AmqpClientActorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testConnectionHandling() {
    new TestKit(actorSystem) {{
        final TestProbe aggregator = new TestProbe(actorSystem);

        final Props props =
                AmqpClientActor.propsForTests(connection, getRef(), getRef(),
                        (connection1, exceptionListener) -> mockConnection);
        final ActorRef amqpClientActor = actorSystem.actorOf(props);
        watch(amqpClientActor);

        amqpClientActor.tell(OpenConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef());
        expectMsg(CONNECTED_SUCCESS);

        amqpClientActor.tell(RetrieveConnectionStatus.of(CONNECTION_ID, DittoHeaders.empty()), aggregator.ref());
        aggregator.expectMsgClass(ResourceStatus.class);

        amqpClientActor.tell(CloseConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef());
        expectMsg(DISCONNECTED_SUCCESS);

        amqpClientActor.tell(RetrieveConnectionStatus.of(CONNECTION_ID, DittoHeaders.empty()), aggregator.ref());
        aggregator.expectMsgClass(ResourceStatus.class);
    }};
}
 
Example 2
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 3
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 4
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 5
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 6
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 7
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 8
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 9
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 10
Source File: SetupDocumentTypeWorkerActorTest.java    From searchanalytics-bigdata with MIT License 5 votes vote down vote up
@Test
public void handleIndexDocumentTypeMessageVO() {
	final Props props = Props.create(SetupDocumentTypeWorkerActor.class,
			null, null);
	final TestActorRef<SetupDocumentTypeWorkerActor> ref = TestActorRef
			.create(system, props);
	final SetupDocumentTypeWorkerActor actor = ref.underlyingActor();
	// Mock the behavior of child/worker actors.
	TestProbe testProbeDataGeneratorWorker = TestProbe.apply(system);
	actor.setDataGeneratorWorkerRouter(testProbeDataGeneratorWorker.ref());
	ElasticSearchIndexConfig config = ElasticSearchIndexConfig.COM_WEBSITE;
	IndexDocumentType documentType = IndexDocumentType.PRODUCT;
	String indexName = "trialindexName";
	IndexDocumentTypeMessageVO indexDocumentTypeMessageVO = new IndexDocumentTypeMessageVO()
			.config(config).documentType(documentType)
			.newIndexName(indexName);
	TestProbe testProbeOriginalSender = TestProbe.apply(system);
	// Actor state check
	assertEquals(null, actor.getIndexDocumentType());
	ref.tell(indexDocumentTypeMessageVO, testProbeOriginalSender.ref());
	testProbeDataGeneratorWorker
			.expectMsgClass(IndexDocumentTypeMessageVO.class);
	TestActor.Message message = testProbeDataGeneratorWorker.lastMessage();
	IndexDocumentTypeMessageVO resultMsg = (IndexDocumentTypeMessageVO) message
			.msg();
	assertEquals(config, resultMsg.getConfig());
	assertEquals(documentType, resultMsg.getIndexDocumentType());
	assertEquals(indexName, resultMsg.getNewIndexName());
	assertEquals(documentType, actor.getIndexDocumentType());
}
 
Example 11
Source File: KafkaClientActorTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testPublishToTopic() {
    new TestKit(actorSystem) {{

        final TestProbe probe = new TestProbe(getSystem());
        final Props props = getKafkaClientActorProps(probe.ref(), connection);
        final ActorRef kafkaClientActor = actorSystem.actorOf(props);

        kafkaClientActor.tell(OpenConnection.of(connectionId, DittoHeaders.empty()), getRef());
        expectMsg(CONNECTED_SUCCESS);

        final ThingModifiedEvent thingModifiedEvent = TestConstants.thingModified(Collections.emptyList());
        final String expectedJson = TestConstants.signalToDittoProtocolJsonString(thingModifiedEvent);

        LOGGER.info("Sending thing modified message: {}", thingModifiedEvent);
        final OutboundSignal.Mapped mappedSignal = Mockito.mock(OutboundSignal.Mapped.class);
        when(mappedSignal.getTargets()).thenReturn(singletonList(TARGET));
        when(mappedSignal.getSource()).thenReturn(thingModifiedEvent);
        kafkaClientActor.tell(mappedSignal, getRef());

        final OutboundSignal.Mapped message =
                probe.expectMsgClass(OutboundSignal.Mapped.class);
        assertThat(message.getExternalMessage().getTextPayload()).contains(expectedJson);

        kafkaClientActor.tell(CloseConnection.of(connectionId, DittoHeaders.empty()), getRef());
        expectMsg(DISCONNECTED_SUCCESS);

        expectPublisherReceivedShutdownSignal(probe);
    }};
}
 
Example 12
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 13
Source File: SetupDocumentTypeWorkerActorTest.java    From searchanalytics-bigdata with MIT License 5 votes vote down vote up
@Test
public void sendExceptionToParent() {
	final Props props = Props.create(SetupDocumentTypeWorkerActor.class,
			null, null);
	final TestActorRef<SetupDocumentTypeWorkerActor> ref = TestActorRef
			.create(system, props);
	final SetupDocumentTypeWorkerActor actor = ref.underlyingActor();
	// Mock the behavior of child/worker actors.
	TestProbe testProbeDocumentGeneratorWorker = TestProbe.apply(system);
	TestProbe testProbeIndexDataWorker = TestProbe.apply(system);
	// No data generator
	actor.setDataGeneratorWorkerRouter(null);
	actor.setDocumentGeneratorWorkerRouter(testProbeDocumentGeneratorWorker
			.ref());
	actor.setIndexDocumentWorkerRouter(testProbeIndexDataWorker.ref());
	ElasticSearchIndexConfig config = ElasticSearchIndexConfig.COM_WEBSITE;
	IndexDocumentType documentType = IndexDocumentType.PRODUCT;
	String indexName = "trialindexName";
	// no document type
	IndexDocumentTypeMessageVO indexDocumentTypeMessageVO = new IndexDocumentTypeMessageVO()
			.config(config).newIndexName(indexName)
			.documentType(documentType);
	assertEquals(0, actor.getTotalDocumentsToIndex());
	assertEquals(0, actor.getTotalDocumentsToIndexDone());
	assertEquals(null, actor.getIndexDocumentType());
	// parent Exception, NPE in data generator
	TestProbe testProbeParentActor = TestProbe.apply(system);
	String parentString = testProbeParentActor.ref().path().toString();
	actor.setParentActorPathString(parentString);
	ref.tell(indexDocumentTypeMessageVO, null);
	testProbeParentActor
			.expectMsgClass(DocumentTypeIndexingException.class);
	TestActor.Message testProbeParentActorMessage = testProbeParentActor
			.lastMessage();
	DocumentTypeIndexingException testProbeParentActorMessageType = (DocumentTypeIndexingException) testProbeParentActorMessage
			.msg();
	// doc type is not yet set
	assertEquals(documentType,
			testProbeParentActorMessageType.getIndexDocumentType());
}
 
Example 14
Source File: AbstractConsumerActorTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private void testInboundMessage(final Map.Entry<String, Object> header,
        final int forwardedToConcierge,
        final int respondedToCaller,
        final Consumer<Signal<?>> verifySignal,
        final Consumer<OutboundSignal.Mapped> verifyResponse,
        final PayloadMapping payloadMapping
) {

    new TestKit(actorSystem) {{
        final TestProbe sender = TestProbe.apply(actorSystem);
        final TestProbe concierge = TestProbe.apply(actorSystem);
        final TestProbe clientActor = TestProbe.apply(actorSystem);

        final ActorRef mappingActor = setupMessageMappingProcessorActor(clientActor.ref(), concierge.ref());

        final ActorRef underTest = actorSystem.actorOf(getConsumerActorProps(mappingActor, payloadMapping));

        underTest.tell(getInboundMessage(header), sender.ref());

        if (forwardedToConcierge >= 0) {
            for (int i = 0; i < forwardedToConcierge; i++) {
                final ModifyThing modifyThing = concierge.expectMsgClass(ModifyThing.class);
                assertThat((CharSequence) modifyThing.getThingEntityId()).isEqualTo(TestConstants.Things.THING_ID);
                verifySignal.accept(modifyThing);
            }
        } else {
            concierge.expectNoMessage(ONE_SECOND);
        }

        if (respondedToCaller >= 0) {
            for (int i = 0; i < respondedToCaller; i++) {
                final PublishMappedMessage publishMappedMessage =
                        clientActor.expectMsgClass(PublishMappedMessage.class);
                verifyResponse.accept(publishMappedMessage.getOutboundSignal());
            }
        } else {
            clientActor.expectNoMessage(ONE_SECOND);
        }
    }};
}
 
Example 15
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 16
Source File: BaseAkkaTestCase.java    From oreilly-reactive-architecture-student with Apache License 2.0 5 votes vote down vote up
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
Example 17
Source File: ConnectionPersistenceActorTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void manageConnectionWith2Clients() throws Exception {
    startSecondActorSystemAndJoinCluster();
    new TestKit(actorSystem) {{
        final TestProbe probe = TestProbe.apply(actorSystem);
        final ActorRef underTest =
                TestConstants.createConnectionSupervisorActor(connectionId, actorSystem, pubSubMediator,
                        conciergeForwarder,
                        (connection, concierge, connectionActor) -> MockClientActor.props(probe.ref()));
        watch(underTest);

        // create closed connection
        underTest.tell(createClosedConnectionWith2Clients, getRef());
        expectMsgClass(CreateConnectionResponse.class);

        // open connection: only local client actor is asked for a response.
        underTest.tell(openConnection, getRef());
        probe.expectMsg(openConnection);
        expectMsgClass(OpenConnectionResponse.class);

        // forward signal once
        underTest.tell(thingModified, getRef());
        final Object outboundSignal = probe.expectMsgClass(Object.class);
        assertThat(outboundSignal).isInstanceOf(OutboundSignal.class);
        // probe.expectMsg(OutboundSignal.class); // does not work for some reason

        // close connection: at least 1 client actor gets the command; the other may or may not be started.
        underTest.tell(closeConnection, getRef());
        probe.expectMsg(closeConnection);
        expectMsg(closeConnectionResponse);

        // delete connection
        underTest.tell(deleteConnection, getRef());
        expectMsg(deleteConnectionResponse);
        expectTerminated(underTest);
    }};
}
 
Example 18
Source File: MessageMappingProcessorActorTest.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testSignalEnrichment() {
    // GIVEN: test probe actor started with configured values
    final TestProbe conciergeForwarderProbe = TestProbe.apply("mockConciergeForwarderProbe", actorSystem);
    setUpConciergeForwarder(conciergeForwarderProbe.ref());

    new TestKit(actorSystem) {{
        // GIVEN: MessageMappingProcessor started with a test probe as the configured enrichment provider
        final ActorRef underTest = createMessageMappingProcessorActor(this);

        // WHEN: a signal is received with 2 targets, one with enrichment and one without
        final JsonFieldSelector extraFields = JsonFieldSelector.newInstance("attributes/x", "attributes/y");
        final AuthorizationSubject targetAuthSubject = AuthorizationSubject.newInstance("target:auth-subject");
        final AuthorizationSubject targetAuthSubjectWithoutIssuer = AuthorizationSubject.newInstance("auth-subject");
        final Target targetWithEnrichment = ConnectivityModelFactory.newTargetBuilder()
                .address("target/address")
                .authorizationContext(AuthorizationContext.newInstance(DittoAuthorizationContextType.UNSPECIFIED,
                        targetAuthSubject))
                .topics(ConnectivityModelFactory.newFilteredTopicBuilder(Topic.TWIN_EVENTS)
                        .withExtraFields(extraFields)
                        .build())
                .build();
        final Target targetWithoutEnrichment = ConnectivityModelFactory.newTargetBuilder(targetWithEnrichment)
                .topics(Topic.TWIN_EVENTS)
                .build();
        final Signal<?> signal = TestConstants.thingModified(Collections.emptyList());
        final OutboundSignal outboundSignal = OutboundSignalFactory.newOutboundSignal(signal,
                Arrays.asList(targetWithEnrichment, targetWithoutEnrichment));
        underTest.tell(outboundSignal, getRef());

        // THEN: a mapped signal without enrichment arrives first
        expectPublishedMappedMessage(expectMsgClass(PublishMappedMessage.class), signal, targetWithoutEnrichment);

        // THEN: Receive a RetrieveThing command from the facade.
        final RetrieveThing retrieveThing = conciergeForwarderProbe.expectMsgClass(RetrieveThing.class);
        assertThat(retrieveThing.getSelectedFields()).contains(extraFields);
        assertThat(retrieveThing.getDittoHeaders().getAuthorizationContext()).containsExactly(targetAuthSubject, targetAuthSubjectWithoutIssuer);

        final JsonObject extra = JsonObject.newBuilder().set("/attributes/x", 5).build();
        conciergeForwarderProbe.reply(
                RetrieveThingResponse.of(retrieveThing.getEntityId(), extra, retrieveThing.getDittoHeaders()));

        // THEN: Receive an outbound signal with extra fields.
        expectPublishedMappedMessage(expectMsgClass(PublishMappedMessage.class), signal, targetWithEnrichment,
                mapped -> assertThat(mapped.getAdaptable().getPayload().getExtra()).contains(extra));
    }};
}
 
Example 19
Source File: DataGeneratorWorkerActorTest.java    From searchanalytics-bigdata with MIT License 4 votes vote down vote up
@Test
public void testProductGroupDataGeneration() {
	final Props props = Props.create(DataGeneratorWorkerActor.class,
			sampleDataGeneratorService);
	final TestActorRef<DataGeneratorWorkerActor> ref = TestActorRef.create(
			system, props);

	ElasticSearchIndexConfig config = ElasticSearchIndexConfig.COM_WEBSITE;
	IndexDocumentType documentType = IndexDocumentType.PRODUCT_GROUP;
	String indexName = "trialindexName";
	IndexDocumentTypeMessageVO indexDocumentTypeMessageVO = new IndexDocumentTypeMessageVO()
			.config(config).documentType(documentType)
			.newIndexName(indexName);

	List<ProductGroup> productGroupList = new ArrayList<ProductGroup>();
	ProductGroup productGroup = new ProductGroup();
	// For now ids hard coded in generator for testing
	Long productGroupId = 1l;
	productGroup.setId(productGroupId);
	productGroupList.add(productGroup);

	expect(sampleDataGeneratorService.generateProductGroupSampleData())
			.andReturn(productGroupList);
	replay(sampleDataGeneratorService);

	TestProbe testProbe = TestProbe.apply(system);
	ref.tell(indexDocumentTypeMessageVO, testProbe.ref());
	verify(sampleDataGeneratorService);

	testProbe.expectMsgClass(Integer.class);
	TestActor.Message sizeMessage = testProbe.lastMessage();
	Integer resultMsgCount = (Integer) sizeMessage.msg();
	assertEquals(1, resultMsgCount.intValue());

	testProbe.expectMsgClass(IndexDocumentVO.class);
	TestActor.Message message = testProbe.lastMessage();
	IndexDocumentVO resultMsg = (IndexDocumentVO) message.msg();
	assertEquals(productGroupId, resultMsg.getDocumentId());
	assertEquals(config, resultMsg.getConfig());
	assertEquals(documentType, resultMsg.getDocumentType());
	assertEquals(indexName, resultMsg.getNewIndexName());
}
 
Example 20
Source File: SetupDocumentTypeWorkerActorTest.java    From searchanalytics-bigdata with MIT License 4 votes vote down vote up
@Test
public void handleFullFlow() {
	final Props props = Props.create(SetupDocumentTypeWorkerActor.class,
			null, null);
	final TestActorRef<SetupDocumentTypeWorkerActor> ref = TestActorRef
			.create(system, props);
	final SetupDocumentTypeWorkerActor actor = ref.underlyingActor();
	// Mock the behavior of child/worker actors.
	TestProbe testProbeDataGeneratorWorker = TestProbe.apply(system);
	TestProbe testProbeDocumentGeneratorWorker = TestProbe.apply(system);
	TestProbe testProbeIndexDataWorker = TestProbe.apply(system);
	actor.setDataGeneratorWorkerRouter(testProbeDataGeneratorWorker.ref());
	actor.setDocumentGeneratorWorkerRouter(testProbeDocumentGeneratorWorker
			.ref());
	actor.setIndexDocumentWorkerRouter(testProbeIndexDataWorker.ref());
	ElasticSearchIndexConfig config = ElasticSearchIndexConfig.COM_WEBSITE;
	IndexDocumentType documentType = IndexDocumentType.PRODUCT;
	String indexName = "trialindexName";
	IndexDocumentTypeMessageVO indexDocumentTypeMessageVO = new IndexDocumentTypeMessageVO()
			.config(config).documentType(documentType)
			.newIndexName(indexName);
	assertEquals(0, actor.getTotalDocumentsToIndex());
	assertEquals(0, actor.getTotalDocumentsToIndexDone());
	assertEquals(null, actor.getIndexDocumentType());
	TestProbe testProbeOriginalSender = TestProbe.apply(system);
	ref.tell(indexDocumentTypeMessageVO, testProbeOriginalSender.ref());
	testProbeDataGeneratorWorker
			.expectMsgClass(IndexDocumentTypeMessageVO.class);
	TestActor.Message message = testProbeDataGeneratorWorker.lastMessage();
	IndexDocumentTypeMessageVO resultMsg = (IndexDocumentTypeMessageVO) message
			.msg();
	assertEquals(config, resultMsg.getConfig());
	assertEquals(documentType, resultMsg.getIndexDocumentType());
	assertEquals(indexName, resultMsg.getNewIndexName());
	// updated actor state
	assertEquals(0, actor.getTotalDocumentsToIndex());
	assertEquals(0, actor.getTotalDocumentsToIndexDone());
	assertEquals(documentType, actor.getIndexDocumentType());
	// Let's say total data to generate to 1
	ref.tell(Integer.valueOf(1), testProbeDataGeneratorWorker.ref());
	assertEquals(1, actor.getTotalDocumentsToIndex());
	assertEquals(0, actor.getTotalDocumentsToIndexDone());
	assertEquals(documentType, actor.getIndexDocumentType());
	Long documentId = 1l;
	IndexDocumentVO indexDocumentVO = new IndexDocumentVO()
			.config(resultMsg.getConfig())
			.documentType(indexDocumentTypeMessageVO.getIndexDocumentType())
			.newIndexName(indexDocumentTypeMessageVO.getNewIndexName())
			.documentId(documentId);
	// Send data back to the sender, generate document
	ref.tell(indexDocumentVO, testProbeDataGeneratorWorker.ref());
	testProbeDocumentGeneratorWorker.expectMsgClass(IndexDocumentVO.class);
	TestActor.Message messageDoc = testProbeDocumentGeneratorWorker
			.lastMessage();
	IndexDocumentVO resultMsgDoc = (IndexDocumentVO) messageDoc.msg();
	assertEquals(config, resultMsgDoc.getConfig());
	assertEquals(documentType, resultMsgDoc.getDocumentType());
	assertEquals(indexName, resultMsgDoc.getNewIndexName());
	assertEquals(documentId, resultMsgDoc.getDocumentId());
	assertEquals(1, actor.getTotalDocumentsToIndex());
	assertEquals(0, actor.getTotalDocumentsToIndexDone());
	assertEquals(documentType, actor.getIndexDocumentType());
	// send data back, index document.
	Product product = new Product();
	product.setId(documentId);
	resultMsgDoc.product(product);
	ref.tell(resultMsgDoc, testProbeDocumentGeneratorWorker.ref());
	testProbeIndexDataWorker.expectMsgClass(IndexDocumentVO.class);
	TestActor.Message messageDocIndex = testProbeIndexDataWorker
			.lastMessage();
	IndexDocumentVO resultMsgDocIndex = (IndexDocumentVO) messageDocIndex
			.msg();
	assertEquals(config, resultMsgDocIndex.getConfig());
	assertEquals(documentType, resultMsgDocIndex.getDocumentType());
	assertEquals(indexName, resultMsgDocIndex.getNewIndexName());
	assertEquals(documentId, resultMsgDocIndex.getDocumentId());
	assertEquals(product, resultMsgDocIndex.getProduct());
	assertEquals(1, actor.getTotalDocumentsToIndex());
	assertEquals(0, actor.getTotalDocumentsToIndexDone());
	assertEquals(documentType, actor.getIndexDocumentType());
	// Send back message, indexdone.
	resultMsgDocIndex.indexDone(true);
	TestProbe testProbeParent = TestProbe.apply(system);
	String string = testProbeParent.ref().path().toString();
	actor.setParentActorPathString(string);
	ref.tell(resultMsgDocIndex, null);
	// state is set back to initial and message sent to parent.
	testProbeParent.expectMsgClass(IndexDocumentType.class);
	TestActor.Message messageDocIndexDone = testProbeParent.lastMessage();
	IndexDocumentType resultMsgDocIndexDone = (IndexDocumentType) messageDocIndexDone
			.msg();
	// state reset
	assertEquals(documentType, resultMsgDocIndexDone);
	assertEquals(0, actor.getTotalDocumentsToIndex());
	assertEquals(0, actor.getTotalDocumentsToIndexDone());
	assertEquals(null, actor.getIndexDocumentType());
}