Java Code Examples for io.vlingo.actors.World#startWithDefaults()

The following examples show how to use io.vlingo.actors.World#startWithDefaults() . 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: ResourceFailureTest.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-request-failure");

  resource = new FailResource();

  port = nextPort.incrementAndGet();

  server = Server.startWith(
          world.stage(),
          Resources.are(resource.routes()),
          Filters.none(),
          port,
          Sizing.define(),
          Timing.define());
}
 
Example 2
Source File: ReturnAddressTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatReturnAddressRuns() {
  System.out.println("ReturnAddress: is starting.");

  final World world = World.startWithDefaults("returnaddress-test");

  final ReturnAddressResults results = new ReturnAddressResults();
  final AccessSafely access = results.afterCompleting(2);

  final Service service = world.actorFor(Service.class, Server.class);
  world.actorFor(Consumer.class, Client.class, service, results);

  Assert.assertEquals(1, (int) access.readFrom("afterSimpleReplyCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterComplexReplyCount"));

  System.out.println("ReturnAddress: is completed.");
}
 
Example 3
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Bootstrap() {
  System.out.println("==============================");
  System.out.println("Starting vlingo/http Server...");
  System.out.println("==============================");

  world = World.startWithDefaults("WebServerActorAwesomeDemo");

  final Servers servers=new Servers();

  servers.produceAdminServerAndAddToCache(world,9090);
  servers.produceOrganizationServerAndAddToCache(world,8081);


  //noinspection AnonymousHasLambdaAlternative
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      bootstrap.world.terminate();
      System.out.println("\n");
      System.out.println("==============================");
      System.out.println("Servers stopped by world ...");
      System.out.println("vlingo world terminated ...");
      System.out.println("==============================");
    }
  });
}
 
Example 4
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Bootstrap() {
  this.world = World.startWithDefaults("backservice");
  
  TokensSseFeedActor.registerInstantiator();
  
  this.server = Server.startWith(world.stage());
  
  EventJournal.startWith(this.world.stage());

  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      bootStrap.server.stop();
      System.out.println("\n");
      System.out.println("======================");
      System.out.println("Stopping backservice.");
      System.out.println("======================");
      pause();
    }
  });
}
 
Example 5
Source File: CommandSourcedTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() {
  world = World.startWithDefaults("test-cs");

  dispatcher = new MockJournalDispatcher();

  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);

  registry = new SourcedTypeRegistry(world);
  registry.register(new Info(journal, TestCommandSourcedEntity.class, TestCommandSourcedEntity.class.getSimpleName()));
  registry.info(TestCommandSourcedEntity.class)
    .registerEntryAdapter(DoCommand1.class, new DoCommand1Adapter())
    .registerEntryAdapter(DoCommand2.class, new DoCommand2Adapter())
    .registerEntryAdapter(DoCommand3.class, new DoCommand3Adapter());

  result = new Result();
  entity = world.actorFor(Entity.class, TestCommandSourcedEntity.class, result);
}
 
Example 6
Source File: StatefulEntityTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("stateful-entity");
  dispatcher = new MockTextDispatcher();

  stateAdapterProvider = new StateAdapterProvider(world);
  stateAdapterProvider.registerAdapter(Entity1State.class, new Entity1StateAdapter());
  new EntryAdapterProvider(world);
  registry = new StatefulTypeRegistry(world);

  store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher));

  registry.register(new Info<>(store, Entity1State.class, Entity1State.class.getSimpleName()));
}
 
Example 7
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private Bootstrap() throws Exception {
  final World world = World.startWithDefaults("agile-collaboration");

  final Exchange camelExchange = new ExchangeBootstrap(world).initExchange();
  final ExchangeDispatcher dispatcher = new ExchangeDispatcher(camelExchange);
  final Journal journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);
  final SourcedTypeRegistry registry = new SourcedTypeRegistry(world);

  SourcedRegistration.registerAllWith(registry, journal);
}
 
Example 8
Source File: PingPong.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
private static PingPong game() {
  final World world = World.startWithDefaults("ping-pong");
  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);

  return new PingPong(world, until, pinger, ponger);
}
 
Example 9
Source File: CommandRouterTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-command-router");
  address = world.addressFactory().unique();
  world.stage().actorFor(Solver.class, Definition.has(SolverActor.class, Definition.NoParameters), address);
  completes = Completes.using(world.stage().scheduler());
}
 
Example 10
Source File: MessageFilterTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatMessageFilterRuns() {

    System.out.println("Message Filter: is starting.");

    final World world = World.startWithDefaults("message-filter-test");

    final MessageFilterResults results = new MessageFilterResults();

    final AccessSafely access = results.afterCompleting(3);

    final InventorySystem restrictedInventorySystemActor =
            world.actorFor(InventorySystem.class, RestrictedInventorySystemActor.class, results);

    final InventorySystem notRestrictedInventorySystemActor =
            world.actorFor(InventorySystem.class, NotRestrictedInventorySystemActor.class, results);

    final InventorySystem inventoryMessageFilter =
            world.actorFor(InventorySystem.class, InventorySystemMessageFilter.class, results, notRestrictedInventorySystemActor);

    final Order order =
            new Order("1",
                    "TypeDEF",
                    Arrays.asList(
                            new OrderItem("2", "TypeDEF", "A description", 100d),
                            new OrderItem("3", "TypeDEF", "A description", 150d))
                            .stream().collect(toMap(OrderItem::orderItemId, identity())));

    restrictedInventorySystemActor.processOrder(order);
    notRestrictedInventorySystemActor.processOrder(order);
    inventoryMessageFilter.processOrder(order);

    Assert.assertEquals(1, (int) access.readFrom("afterOrderProcessedCount"));
    Assert.assertEquals(2, (int) access.readFrom("afterOrderFilteredCount"));

    System.out.println("Message Filter: is completed.");
}
 
Example 11
Source File: FeedResourceTest.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  world = World.startWithDefaults("test-stream-userResource");

  final int testServerPort = serverPort.incrementAndGet();

  properties = new java.util.Properties();
  properties.setProperty("server.http.port", ""+testServerPort);
  properties.setProperty("server.dispatcher.pool", "10");
  properties.setProperty("server.buffer.pool.size", "100");
  properties.setProperty("server.message.buffer.size", "65535");
  properties.setProperty("server.probe.interval", "2");
  properties.setProperty("server.probe.timeout", "2");
  properties.setProperty("server.processor.pool.size", "10");
  properties.setProperty("server.request.missing.content.timeout", "100");

  properties.setProperty("feed.resource.name.events", FeedURI);
  properties.setProperty("feed.resource.events.producer.class", "io.vlingo.http.resource.feed.EventsFeedProducerActor");
  properties.setProperty("feed.resource.events.elements", "5");
  properties.setProperty("feed.resource.events.pool", "10");

  server = Server.startWith(world.stage(), properties);
  assertTrue(server.startUp().await(500L));

  progress = new Progress();
  consumer = world.actorFor(ResponseChannelConsumer.class, Definition.has(TestResponseChannelConsumer.class, Definition.parameters(progress)));
  client = new NettyClientRequestResponseChannel(Address.from(Host.of("localhost"), testServerPort, AddressType.NONE), consumer, 100, 10240);
}
 
Example 12
Source File: PipesAndFiltersTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatPipesAndFiltersRuns() {
  System.out.println("PipesAndFilters: is starting.");

  final World world = World.startWithDefaults("pipesandfilters-test");

  final PipeAndFilterResults results = new PipeAndFilterResults();
  final AccessSafely access = results.afterCompleting(9);

  final String orderText = "(encryption)(certificate)<order id='123'>...</order>";
  final byte[] rawOrderBytes = orderText.getBytes();

  final OrderProcessor filter5 = world.actorFor(OrderProcessor.class, OrderManagementSystem.class, results);
  final OrderProcessor filter4 = world.actorFor(OrderProcessor.class, Deduplicator.class, filter5, results);
  final OrderProcessor filter3 = world.actorFor(OrderProcessor.class, Authenticator.class, filter4, results);
  final OrderProcessor filter2 = world.actorFor(OrderProcessor.class, Decrypter.class, filter3, results);
  final OrderProcessor filter1 = world.actorFor(OrderProcessor.class, OrderAcceptanceEndpoint.class, filter2, results);

  filter1.processIncomingOrder(rawOrderBytes);
  filter1.processIncomingOrder(rawOrderBytes);

  Assert.assertEquals(2, (int) access.readFrom("afterOrderAuthenticatedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderDecryptedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderDeduplicatedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderAcceptedCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterOrderManagedCount"));

  System.out.println("PipesAndFilters: is completed.");
}
 
Example 13
Source File: SseStreamResourceTest.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-stream-userResource");
  Configuration.define();
  resource = new MockSseStreamResource(world);
  Configuration.define();
  context = new MockRequestResponseContext(new MockResponseSenderChannel());
  client = new SseClient(context);
  AllSseFeedActor.registerInstantiator();
}
 
Example 14
Source File: RetryActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    world = World.startWithDefaults("retry-actor-tests");
    readerActor = world.actorFor(Reader.class, RetryReaderActor.class);
}
 
Example 15
Source File: RecipientListTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@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();
}
 
Example 16
Source File: ArrayQueueBenchmark.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Setup
public void setup() {
  world = World.startWithDefaults("ArrayQueueBenchmark");
}
 
Example 17
Source File: LocalExchangeStreamTest.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    world = World.startWithDefaults("streams");
}
 
Example 18
Source File: ActorTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Before
public void setUpWorld() throws Exception {
    world = World.startWithDefaults("test");
}
 
Example 19
Source File: MessageRouterTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@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 20
Source File: FeedTest.java    From vlingo-lattice with Mozilla Public License 2.0 3 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() {
  world = World.startWithDefaults("feed-test");

  dispatcher = new MockJournalDispatcher();

  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);

  entryReader = journal.journalReader("feed-test-reader").await();

  consumer = new MockFeedConsumer();

  interest = noOpInterest();
}