Java Code Examples for io.vlingo.actors.World#terminate()
The following examples show how to use
io.vlingo.actors.World#terminate() .
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: MessageExpirationTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@Test public void testMessageExpirationRuns() { World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "MessageExpirationTest: is started" ); final MessageExpirationResults results = new MessageExpirationResults(); final AccessSafely access = results.afterCompleting( ORDERS ); OrderProcessor purchaseAgent = world.actorFor(OrderProcessor.class, PurchaseAgent.class, results); OrderProcessor purchaseRouter = world.actorFor(OrderProcessor.class, PurchaseRouter.class, purchaseAgent); purchaseRouter.placeOrder( new Order( "1", "11", 50.00, 1000L )); purchaseRouter.placeOrder( new Order( "2", "22", 250.00, 100L )); purchaseRouter.placeOrder( new Order( "3", "33", 32.95, 10L )); final int expectedOrderPlaced = ORDERS - (int) access.readFrom("afterOrderExpiredCount"); Assert.assertEquals(expectedOrderPlaced, (int) access.readFrom("afterOrderPlacedCount")); world.defaultLogger().debug( "MessageExpirationTest: is completed" ); world.terminate(); }
Example 2
Source File: InventoryOrdersTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
/** * Test lifecycle of an {@link OrderPlaced} */ @Test public void testOrderPlaced() { OrderItem orderItem1 = new OrderItem ( "1", "TypeABC.4", "An item of type ABC.4.", 29.95 ); OrderItem orderItem2 = new OrderItem ( "2", "TypeABC.1", "An item of type ABC.1.", 99.95 ); OrderItem orderItem3 = new OrderItem ( "3", "TypeABC.9", "An item of type ABC.9.", 14.95 ); Map<String, OrderItem> items = Maps.newHashMap (); items.put ( orderItem1.getItemType (), orderItem1 ); items.put ( orderItem2.getItemType (), orderItem2 ); items.put ( orderItem3.getItemType (), orderItem3 ); OrderPlaced orderPlaced = new OrderPlaced ( new Order ( "123", "TypeABC", items ) ); OrderItem orderItem4 = new OrderItem ( "4", "TypeXYZ.2", "An item of type XYZ.2.", 74.95 ); OrderItem orderItem5 = new OrderItem ( "5", "TypeXYZ.1", "An item of type XYZ.1.", 59.95 ); OrderItem orderItem6 = new OrderItem ( "6", "TypeXYZ.7", "An item of type XYZ.7.", 29.95 ); OrderItem orderItem7 = new OrderItem ( "7", "TypeXYZ.5", "An item of type XYZ.5.", 9.95 ); Map<String, OrderItem> items1 = Maps.newHashMap (); items1.put ( orderItem4.getItemType (), orderItem4 ); items1.put ( orderItem5.getItemType (), orderItem5 ); items1.put ( orderItem6.getItemType (), orderItem6 ); items1.put ( orderItem7.getItemType (), orderItem7 ); OrderPlaced orderPlaced2 = new OrderPlaced ( new Order ( "124", "TypeXYZ", items1 ) ); final World world = World.startWithDefaults ( WORLD_NAME ); final OrderRoutingResults results = new OrderRoutingResults(); final AccessSafely access = results.afterCompleting(2); final OrderRouter orderRouter = world.actorFor (OrderRouter.class, OrderRouterActor.class, results); orderRouter.routeOrder ( orderPlaced ); orderRouter.routeOrder ( orderPlaced2 ); Assert.assertEquals(2, (int) access.readFrom("afterOrderRoutedCount")); world.terminate (); }
Example 3
Source File: SplitterTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testSplitterRuns() { World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "SplitterTest: is started" ); final SplitterResults results = new SplitterResults(); final AccessSafely access = results.afterCompleting( ORDERS_ITEMS ); final OrderProcessor orderRouter = world.actorFor( OrderProcessor.class, OrderRouter.class, results ); final OrderItem orderItem1 = new OrderItem( "1", OrderProcessor.ITEM_TYPE_A, "An item of type A", 23.95 ); final OrderItem orderItem2 = new OrderItem( "2", OrderProcessor.ITEM_TYPE_B, "An item of type B", 99.95 ); final OrderItem orderItem3 = new OrderItem( "3", OrderProcessor.ITEM_TYPE_C, "An item of type C", 14.95 ); final OrderItem[] orderItems = { orderItem1, orderItem2, orderItem3 }; final Order order = new Order( orderItems ); orderRouter.placeOrder( order ); Assert.assertEquals(1, (int) access.readFrom("afterOrderPlacedCount")); Assert.assertEquals(1, (int) access.readFrom("afterOrderByReceivedAProcessorCount")); Assert.assertEquals(1, (int) access.readFrom("afterOrderByReceivedBProcessorCount")); Assert.assertEquals(1, (int) access.readFrom("afterOrderByReceivedCProcessorCount")); world.defaultLogger().debug( "SplitterTest: is completed" ); world.terminate(); }
Example 4
Source File: MessageBusTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testMessageBusRuns() { World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "TradingBus: is started" ); final TradingBusResults results = new TradingBusResults(); final AccessSafely access = results.afterCompleting( EVENTS ); final TradingBusProcessor tradingBus = world.actorFor(TradingBusProcessor.class, TradingBus.class, results); @SuppressWarnings("unused") final TradingProcessor stockTrader = world.actorFor(TradingProcessor.class, StockTrader.class, results, tradingBus); @SuppressWarnings("unused") final TradingProcessor portfolioManager = world.actorFor(TradingProcessor.class, PortfolioManager.class, results, tradingBus); @SuppressWarnings("unused") final TradingProcessor marketAnalysisTool = world.actorFor(TradingProcessor.class, MarketAnalysisTools.class, results, tradingBus); tradingBus.trade( new TradingCommand( TradingProcessor.EXECUTE_BUY_ORDER, "p123", "MSFT", 100, 31.85 )); tradingBus.trade( new TradingCommand( TradingProcessor.EXECUTE_SELL_ORDER, "p456", "MSFT", 200, 31.80 )); tradingBus.trade( new TradingCommand( TradingProcessor.EXECUTE_BUY_ORDER, "p789", "MSFT", 100, 31.83 )); Assert.assertEquals(3, (int) access.readFrom("afterCommandDispatchedCount")); Assert.assertEquals(6, (int) access.readFrom("afterNotificationDispatchedCount")); Assert.assertEquals(2, (int) access.readFrom("afterHandlerRegisteredCount")); Assert.assertEquals(4, (int) access.readFrom("afterInterestRegisteredCount")); Assert.assertEquals(2, (int) access.readFrom("afterMarketAnalysisBuyOrderExecutedCount")); Assert.assertEquals(1, (int) access.readFrom("afterMarketAnalysisSellOrderExecutedCount")); Assert.assertEquals(2, (int) access.readFrom("afterPortfolioManagerBuyOrderExecutedCount")); Assert.assertEquals(1, (int) access.readFrom("afterPortfolioManagerSellOrderExecutedCount")); Assert.assertEquals(2, (int) access.readFrom("afterStockTraderBuyOrderExecutedCount")); Assert.assertEquals(1, (int) access.readFrom("afterStockTraderSellOrderExecutedCount")); world.defaultLogger().debug( "TradingBus: is completed" ); world.terminate(); }
Example 5
Source File: PlaygroundTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testPlayPingPong() { final World world = World.startWithDefaults("playground"); final TestUntil until = TestUntil.happenings(1); final Pinger pinger = world.actorFor(Pinger.class, PingerActor.class, until); final Ponger ponger = world.actorFor(Ponger.class, PongerActor.class); pinger.ping(ponger); until.completes(); world.terminate(); }
Example 6
Source File: Bootstrap.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Flyway.configure().dataSource(DB_URL, DB_USER, DB_PWD).load().migrate(); final Configuration configuration = new Configuration( DatabaseType.Postgres, new NoopConfigurationInterest(), "org.postgresql.Driver", DataFormat.Text, DB_URL, DB_NAME, DB_USER, DB_PWD, false, "", false ); final World world = World.startWithDefaults("event-journal"); final NoopEventJournalDispatcher journalDispatcher = new NoopEventJournalDispatcher(); Journal<String> journal = Journal.using(world.stage(), JDBCJournalActor.class, journalDispatcher, configuration); final Counter counter = world.actorFor( Counter.class, Definition.has(CounterActor.class, Definition.parameters(DB_NAME, journal)) ); final CounterQuery counterQuery = world.actorFor( CounterQuery.class, Definition.has(CounterQueryActor.class, Definition.parameters(journal.journalReader(DB_NAME).<JournalReader<Entry<?>>>await(), new EntryAdapterProvider())) ); for (int i = 0; i < 5000; i++) { if (i % 10 == 0) { counter.decrease(); } else { counter.increase(); } pause(); counterQuery.counter().andThenConsume(System.out::println); } world.terminate(); }
Example 7
Source File: ScatterGatherTest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Test public void testScatterGatherRuns() { World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "ScatterGatherTest: is started" ); final ScatterGatherResults results = new ScatterGatherResults(); final AccessSafely access = results.afterCompleting(10); AggregateProcessor priceQuoteAggregator = world.actorFor( AggregateProcessor.class, PriceQuoteAggregator.class ); OrderProcessor mtnSuppliesOrderProcessor = world.actorFor( OrderProcessor.class, MountainSuppliesOrderProcessor.class, priceQuoteAggregator, results ); world.actorFor( QuoteProcessor.class, BudgetHikersPriceQuotes.class, mtnSuppliesOrderProcessor ); world.actorFor( QuoteProcessor.class, HighSierraPriceQuotes.class, mtnSuppliesOrderProcessor ); world.actorFor( QuoteProcessor.class, MountainAscentPriceQuotes.class, mtnSuppliesOrderProcessor ); world.actorFor( QuoteProcessor.class, PinnacleGearPriceQuotes.class, mtnSuppliesOrderProcessor ); world.actorFor( QuoteProcessor.class, RockBottomOuterwearPriceQuotes.class, mtnSuppliesOrderProcessor ); world.defaultLogger().debug("Register completes!!!"); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "123", new RetailItem( "1", 29.95 ), new RetailItem( "2", 99.95 ), new RetailItem( "3", 14.95 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "125", new RetailItem( "4", 39.95 ), new RetailItem( "5", 199.95 ), new RetailItem( "6", 149.95 ), new RetailItem( "7", 724.99 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "129", new RetailItem( "8", 119.99 ), new RetailItem( "9", 499.95 ), new RetailItem( "10", 519.00 ), new RetailItem( "11", 209.50 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "135", new RetailItem( "12", .97 ), new RetailItem( "13", 9.50 ), new RetailItem( "14", 1.99 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "140", new RetailItem( "15", 107.50 ), new RetailItem( "16", 9.50 ), new RetailItem( "17", 599.99 ), new RetailItem( "18", 249.95 ), new RetailItem( "19", 789.99 ) ) ); Assert.assertEquals(5, (int) access.readFrom("afterProcessorRegisteredCount")); Assert.assertEquals(5, (int) access.readFrom("afterBestPriceQuotationRegisteredCount")); world.defaultLogger().debug( "ScatterGatherTest: is completed" ); world.terminate(); }
Example 8
Source File: PointToPointChannelTest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Test public void testPointToPointChannelRuns() { final World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "PointToPointChannel: is starting" ); final PointToPointResults results = new PointToPointResults(); final AccessSafely access = results.afterCompleting( NUMBER_MESSAGES ); final PointToPointProcessor peerNodeActor = world.actorFor(PointToPointProcessor.class, PeerNodeActor.class, results); peerNodeActor.process( MSG_ID_1 ); peerNodeActor.process( MSG_ID_2 ); peerNodeActor.process( MSG_ID_3 ); peerNodeActor.process( MSG_ID_4 ); Assert.assertEquals(NUMBER_MESSAGES.intValue(), (int) access.readFrom("afterMessageProcessedCount")); world.defaultLogger().debug( "PointToPointChannel: is completed" ); world.terminate(); }
Example 9
Source File: MessageRouterTest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Test public void testAlternatingRouteProcessorRuns() { final World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "AlternatingRouteProcessor: is starting" ); final MessageRouterResults results = new MessageRouterResults(); final AccessSafely access = results.afterCompleting( ROUTES ); final Processor messageProcessor1 = world.actorFor(Processor.class, WorkerProcessor.class, "MP One" ); final Processor messageProcessor2 = world.actorFor(Processor.class, WorkerProcessor.class, "MP Two" ); final Processor alternatingRouter = world.actorFor(Processor.class, AlternatingRouteProcessor.class, results, messageProcessor1, messageProcessor2 ); int routeCount = 0; int j = 0; while ( true ) { int remaining = ROUTES - access.totalWrites(); if ( routeCount < ROUTES ) { alternatingRouter.process( routeCount ); routeCount++; } if ( j != remaining ) { world.defaultLogger().debug( String.format( "Count: %d", remaining )); j = remaining; } if ( remaining == 0 ) break; } Assert.assertEquals(10, (int) access.readFrom("afterMessageProcessedByFirstProcessorCount")); Assert.assertEquals(10, (int) access.readFrom("afterMessageProcessedBySecondProcessorCount")); world.defaultLogger().debug( "AlternatingRouteProcessor: is completed" ); world.terminate(); }
Example 10
Source File: RecipientListTest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Test public void testRecipientListRuns() { World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "RecipientListTest: is started" ); final RecipientListResults results = new RecipientListResults(); final AccessSafely access = results.afterCompleting(119); OrderProcessor mtnSuppliesOrderProcessor = world.actorFor( OrderProcessor.class, MountainSuppliesOrderProcessor.class, results ); world.actorFor( QuoteProcessor.class, BudgetHikersPriceQuotes.class, mtnSuppliesOrderProcessor, results ); world.actorFor( QuoteProcessor.class, HighSierraPriceQuotes.class, mtnSuppliesOrderProcessor, results ); world.actorFor( QuoteProcessor.class, MountainAscentPriceQuotes.class, mtnSuppliesOrderProcessor, results ); world.actorFor( QuoteProcessor.class, PinnacleGearPriceQuotes.class, mtnSuppliesOrderProcessor, results ); world.actorFor( QuoteProcessor.class, RockBottomOuterwearPriceQuotes.class, mtnSuppliesOrderProcessor, results ); world.defaultLogger().debug("Register completes!!!"); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "123", new RetailItem( "1", 29.95 ), new RetailItem( "2", 99.95 ), new RetailItem( "3", 14.95 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "125", new RetailItem( "4", 39.95 ), new RetailItem( "5", 199.95 ), new RetailItem( "6", 149.95 ), new RetailItem( "7", 724.99 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "129", new RetailItem( "8", 119.99 ), new RetailItem( "9", 499.95 ), new RetailItem( "10", 519.00 ), new RetailItem( "11", 209.50 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "135", new RetailItem( "12", .97 ), new RetailItem( "13", 9.50 ), new RetailItem( "14", 1.99 ) ) ); mtnSuppliesOrderProcessor .requestForQuote( new RetailBasket( "140", new RetailItem( "15", 107.50 ), new RetailItem( "16", 9.50 ), new RetailItem( "17", 599.99 ), new RetailItem( "18", 249.95 ), new RetailItem( "19", 789.99 ) ) ); Assert.assertEquals(5, (int) access.readFrom("afterProcessorRegistered")); Assert.assertEquals(57, (int) access.readFrom("afterQuotationRemitted")); Assert.assertEquals(6, (int) access.readFrom("afterQuotationReceivedAtBudgetHikersCount")); Assert.assertEquals(16, (int) access.readFrom("afterQuotationReceivedAtHighSierraCount")); Assert.assertEquals(3, (int) access.readFrom("afterQuotationReceivedAtMountainAscentCount")); Assert.assertEquals(13, (int) access.readFrom("afterQuotationReceivedAtPinnacleGearCount")); Assert.assertEquals(19, (int) access.readFrom("afterQuotationReceivedAtRockBottomOuterwearCount")); world.defaultLogger().debug( "RecipientListTest: is completed" ); world.terminate(); }