Java Code Examples for akka.testkit.TestProbe#lastMessage()
The following examples show how to use
akka.testkit.TestProbe#lastMessage() .
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: SetupDocumentTypeWorkerActorTest.java From searchanalytics-bigdata with MIT License | 5 votes |
@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 2
Source File: SetupDocumentTypeWorkerActorTest.java From searchanalytics-bigdata with MIT License | 5 votes |
@Test public void handleIndexDocumentVODocumentGeneration() { 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); actor.setDocumentGeneratorWorkerRouter(testProbeDocumentGeneratorWorker .ref()); ElasticSearchIndexConfig config = ElasticSearchIndexConfig.COM_WEBSITE; IndexDocumentType documentType = IndexDocumentType.PRODUCT; String indexName = "trialindexName"; Long documentId = 1l; IndexDocumentVO indexDocumentVO = new IndexDocumentVO().config(config) .documentType(documentType).newIndexName(indexName) .documentId(documentId); // Send data back to the sender, generate document assertEquals(0, actor.getTotalDocumentsToIndex()); ref.tell(indexDocumentVO, null); 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(0, actor.getTotalDocumentsToIndex()); }
Example 3
Source File: SetupDocumentTypeWorkerActorTest.java From searchanalytics-bigdata with MIT License | 5 votes |
@Test public void handleIndexDocumentVOIndexData() { 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 testProbeIndexDataWorker = TestProbe.apply(system); actor.setIndexDocumentWorkerRouter(testProbeIndexDataWorker.ref()); ElasticSearchIndexConfig config = ElasticSearchIndexConfig.COM_WEBSITE; IndexDocumentType documentType = IndexDocumentType.PRODUCT; String indexName = "trialindexName"; Long documentId = 1l; Product product = new Product(); product.setId(documentId); IndexDocumentVO indexDocumentVO = new IndexDocumentVO().config(config) .documentType(documentType).newIndexName(indexName) .documentId(documentId); // send data back, index document. indexDocumentVO.product(product); // This is controlled for doc generation, won;t change here. assertEquals(0, actor.getTotalDocumentsToIndex()); ref.tell(indexDocumentVO, null); 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(0, actor.getTotalDocumentsToIndex()); }
Example 4
Source File: SetupDocumentTypeWorkerActorTest.java From searchanalytics-bigdata with MIT License | 5 votes |
@Test public void handleUnhandledMessage() { 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 testProbeIndexDataWorker = TestProbe.apply(system); actor.setIndexDocumentWorkerRouter(testProbeIndexDataWorker.ref()); // Actor state check assertEquals(null, actor.getIndexDocumentType()); // Subscribe first TestProbe subscriber = TestProbe.apply(system); system.eventStream() .subscribe(subscriber.ref(), UnhandledMessage.class); // garbage String invalidMessage = "blah blah"; ref.tell(invalidMessage, null); // Expect the unhandled message now. FiniteDuration duration = Duration.create(1, TimeUnit.SECONDS); subscriber.expectMsgClass(duration, UnhandledMessage.class); TestActor.Message message = subscriber.lastMessage(); UnhandledMessage resultMsg = (UnhandledMessage) message.msg(); assertEquals(invalidMessage, resultMsg.getMessage()); // Actor state check assertEquals(null, actor.getIndexDocumentType()); }
Example 5
Source File: SetupDocumentTypeWorkerActorTest.java From searchanalytics-bigdata with MIT License | 5 votes |
@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 6
Source File: DataGeneratorWorkerActorTest.java From searchanalytics-bigdata with MIT License | 5 votes |
@Test public void testExceptionForInvalidDocumentTypeMessage() { final Props props = Props.create(DataGeneratorWorkerActor.class, sampleDataGeneratorService); final TestActorRef<DataGeneratorWorkerActor> ref = TestActorRef.create( system, props); ElasticSearchIndexConfig config = ElasticSearchIndexConfig.COM_WEBSITE; // invalid document type IndexDocumentType documentType = null; String indexName = "trialindexName"; IndexDocumentTypeMessageVO indexDocumentTypeMessageVO = new IndexDocumentTypeMessageVO() .config(config).documentType(documentType) .newIndexName(indexName); replay(sampleDataGeneratorService); TestProbe testProbe = TestProbe.apply(system); ref.tell(indexDocumentTypeMessageVO, testProbe.ref()); verify(sampleDataGeneratorService); testProbe.expectMsgClass(DocumentTypeDataGenerationException.class); TestActor.Message message = testProbe.lastMessage(); DocumentTypeDataGenerationException resultMsg = (DocumentTypeDataGenerationException) message .msg(); assertEquals(documentType, resultMsg.getIndexDocumentType()); }
Example 7
Source File: DataGeneratorWorkerActorTest.java From searchanalytics-bigdata with MIT License | 5 votes |
@Test public void testExceptionForInvalidMessage() { final Props props = Props.create(DataGeneratorWorkerActor.class, sampleDataGeneratorService); final TestActorRef<DataGeneratorWorkerActor> ref = TestActorRef.create( system, props); // Subscribe first TestProbe subscriber = TestProbe.apply(system); system.eventStream() .subscribe(subscriber.ref(), UnhandledMessage.class); replay(sampleDataGeneratorService); TestProbe testProbe = TestProbe.apply(system); // Send message String invalidMessage = "blah blah"; ref.tell(invalidMessage, testProbe.ref()); verify(sampleDataGeneratorService); // Expect the unhandled message now. FiniteDuration duration = Duration.create(1, TimeUnit.SECONDS); subscriber.expectMsgClass(duration, UnhandledMessage.class); TestActor.Message message = subscriber.lastMessage(); UnhandledMessage resultMsg = (UnhandledMessage) message.msg(); assertEquals(invalidMessage, resultMsg.getMessage()); }
Example 8
Source File: SetupDocumentTypeWorkerActorTest.java From searchanalytics-bigdata with MIT License | 4 votes |
@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()); }
Example 9
Source File: DataGeneratorWorkerActorTest.java From searchanalytics-bigdata with MIT License | 4 votes |
@Test public void testProductDataGeneration() { 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; String indexName = "trialindexName"; IndexDocumentTypeMessageVO indexDocumentTypeMessageVO = new IndexDocumentTypeMessageVO() .config(config).documentType(documentType) .newIndexName(indexName); List<Product> productsList = new ArrayList<Product>(); Product product = new Product(); // For now ids hard coded in generator for testing Long productId = 1l; product.setId(productId); productsList.add(product); expect(sampleDataGeneratorService.generateProductsSampleData()) .andReturn(productsList); 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(productId, resultMsg.getDocumentId()); assertEquals(config, resultMsg.getConfig()); assertEquals(documentType, resultMsg.getDocumentType()); assertEquals(indexName, resultMsg.getNewIndexName()); }
Example 10
Source File: DataGeneratorWorkerActorTest.java From searchanalytics-bigdata with MIT License | 4 votes |
@Test public void testProductPropertyDataGeneration() { 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_PROPERTY; String indexName = "trialindexName"; IndexDocumentTypeMessageVO indexDocumentTypeMessageVO = new IndexDocumentTypeMessageVO() .config(config).documentType(documentType) .newIndexName(indexName); Set<ProductProperty> productPropertList = new HashSet<ProductProperty>(); ProductProperty productProperty = new ProductProperty(); // For now ids hard coded in generator for testing Long productPropertyId = 1l; productProperty.setId(productPropertyId); productProperty .setColor(SampleDataGeneratorService.PRODUCTPROPERTY_COLOR_BLACK); productProperty .setSize(SampleDataGeneratorService.PRODUCTPROPERTY_SIZE_13_INCH); productPropertList.add(productProperty); expect(sampleDataGeneratorService.generateProductPropertySampleData()) .andReturn(productPropertList); 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(productPropertyId, resultMsg.getDocumentId()); assertEquals(config, resultMsg.getConfig()); assertEquals(documentType, resultMsg.getDocumentType()); assertEquals(indexName, resultMsg.getNewIndexName()); }
Example 11
Source File: DataGeneratorWorkerActorTest.java From searchanalytics-bigdata with MIT License | 4 votes |
@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()); }