io.vlingo.actors.testkit.TestWorld Java Examples
The following examples show how to use
io.vlingo.actors.testkit.TestWorld.
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: InMemoryStateStoreEntryReaderActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { testWorld = TestWorld.startWithDefaults("test-store"); world = testWorld.world(); interest = new MockStateStoreResultInterest(); dispatcher = new MockStateStoreDispatcher(interest); final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world); entryAdapterProvider = new EntryAdapterProvider(world); stateAdapterProvider.registerAdapter(Entity1.class, new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher)); final Completes<StateStoreEntryReader<TextEntry>> completes = store.entryReader("test"); reader = completes.await(); StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, Entity1.class.getSimpleName()); StateTypeStateStoreMap.stateTypeToStoreName(Entity2.class, Entity2.class.getSimpleName()); }
Example #2
Source File: GridActorOfTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() throws Exception { Configuration configuration = Configuration .define() .with(Slf4jLoggerPlugin .Slf4jLoggerPluginConfiguration .define() .defaultLogger() .name("vlingo/actors")); testWorld = TestWorld.start("test", configuration); world = testWorld.world(); final io.vlingo.cluster.model.Properties properties = ClusterProperties.oneNode(); grid = Grid.start(world, properties, "node1"); grid.quorumAchieved(); }
Example #3
Source File: EventSourcedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Before @SuppressWarnings({ "unchecked", "rawtypes" }) public void setUp() { testWorld = TestWorld.startWithDefaults("test-es"); world = testWorld.world(); dispatcher = new MockJournalDispatcher(); EntryAdapterProvider entryAdapterProvider = EntryAdapterProvider.instance(world); entryAdapterProvider.registerAdapter(Test1Happened.class, new Test1HappenedAdapter()); entryAdapterProvider.registerAdapter(Test2Happened.class, new Test2HappenedAdapter()); entryAdapterProvider.registerAdapter(Test3Happened.class, new Test3HappenedAdapter()); journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher); registry = new SourcedTypeRegistry(world); registry.register(new Info(journal, TestEventSourcedEntity.class, TestEventSourcedEntity.class.getSimpleName())); registry.register(new Info(journal, ProductEntity.class, ProductEntity.class.getSimpleName())); registry.register(new Info(journal, ProductParent.class, ProductParent.class.getSimpleName())); registry.register(new Info(journal, ProductGrandparent.class, ProductGrandparent.class.getSimpleName())); result = new Result(); entity = world.actorFor(Entity.class, TestEventSourcedEntity.class, result); }
Example #4
Source File: InMemoryStateStoreTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { testWorld = TestWorld.startWithDefaults("test-store"); world = testWorld.world(); interest = new MockStateStoreResultInterest(); dispatcher = new MockStateStoreDispatcher(interest); dispatcher.afterCompleting(0); // avoid NPE final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world); new EntryAdapterProvider(world); stateAdapterProvider.registerAdapter(Entity1.class, new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher)); StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, StoreName1); StateTypeStateStoreMap.stateTypeToStoreName(Entity2.class, StoreName2); }
Example #5
Source File: StockTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@BeforeEach public void setUp() { final World world = TestWorld.start("stock-test").world(); final MapQueryExpression objectQuery = MapQueryExpression.using(Stock.class, "find", MapQueryExpression.map("id", "id")); final ObjectStore objectStore = world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher()); final StateObjectMapper stateObjectMapper = StateObjectMapper.with(Stock.class, new Object(), new Object()); final Info<StockState> info = new Info(objectStore, StockState.class, "ObjectStore", objectQuery, stateObjectMapper); new ObjectTypeRegistry(world).register(info); StockQueryProvider.using(world.stage(), objectStore); }
Example #6
Source File: OrderTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@BeforeEach public void setUp() { final World world = TestWorld.start("order-test").world(); messagingClient = Mockito.mock(MessagingClient.class); applicationRegistry = Mockito.mock(ApplicationRegistry.class); Mockito.when(applicationRegistry.retrieveStage()).thenReturn(world.stage()); Mockito.when(applicationRegistry.retrieveMessagingClient()).thenReturn(messagingClient); final MapQueryExpression objectQuery = MapQueryExpression.using(Order.class, "find", MapQueryExpression.map("id", "id")); final ObjectStore objectStore = world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher()); final StateObjectMapper stateObjectMapper = StateObjectMapper.with(Order.class, new Object(), new Object()); final ObjectTypeRegistry.Info<OrderState> info = new ObjectTypeRegistry.Info(objectStore, OrderState.class, "ObjectStore", objectQuery, stateObjectMapper); new ObjectTypeRegistry(world).register(info); OrderQueryProvider.using(world.stage(), objectStore); }
Example #7
Source File: ActorEnvironmentTest.java From vlingo-actors with Mozilla Public License 2.0 | 6 votes |
@Test @Ignore public void testSecuredEnvironment() throws Exception { final Definition definition = Definition.has( CannotProvideEnvironmentActor.class, Definition.NoParameters, "test-env"); final TestActor<EnvironmentProvider> env = testWorld.actorFor(EnvironmentProvider.class, definition); TestState state = env.viewTestState(); assertEquals(0, TestWorld.Instance.get().allMessagesFor(env.address()).size()); assertNotNull(state.valueOf("address")); assertNull(state.valueOf("defintion")); assertNull(state.valueOf("parent")); assertNull(state.valueOf("stage")); }
Example #8
Source File: CalculationTests.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@BeforeEach public void setUp() { final World world = TestWorld.start("calculation-test").world(); final MapQueryExpression objectQuery = MapQueryExpression.using(Calculation.class, "find", MapQueryExpression.map("id", "id")); final ObjectStore objectStore = world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher()); final StateObjectMapper stateObjectMapper = StateObjectMapper.with(CalculationState.class, new Object(), new Object()); final ObjectTypeRegistry.Info<CalculationState> info = new ObjectTypeRegistry.Info(objectStore, CalculationState.class, "ObjectStore", objectQuery, stateObjectMapper); new ObjectTypeRegistry(world).register(info); CalculationQueryProvider.using(world.stage(), objectStore); }
Example #9
Source File: InterruptableActorTest.java From vlingo-actors with Mozilla Public License 2.0 | 6 votes |
@Test public void testInterruptionWithStop() throws Exception { final TestActor<Interruptable> interruptable = testWorld.actorFor( Interruptable.class, Definition.has(InterruptableActor.class, Definition.NoParameters, "testStoppable")); for (int idx = 0; idx < 10; ++idx) { if (idx == 5) { interruptable.actor().stop(); } interruptable.actor().doThisOrThat(); } assertEquals(6, TestWorld.Instance.get().allMessagesFor(interruptable.address()).size()); // includes stop() assertEquals(5, (int) interruptable.viewTestState().valueOf("totalReceived")); }
Example #10
Source File: DefaultSupervisorOverrideTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@Before @Override public void setUp() throws Exception { Configuration configuration = Configuration .define() .with(DefaultSupervisorOverridePluginConfiguration .define() .supervisor("default", "overrideSupervisor", DefaultSupervisorOverride.class)); testWorld = TestWorld.start("test", configuration); world = testWorld.world(); }
Example #11
Source File: CommonSupervisionTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@Before @Override public void setUp() throws Exception { Configuration configuration = Configuration .define() .with(CommonSupervisorsPluginConfiguration .define() .supervisor("default", "pingSupervisor", Ping.class, PingSupervisorActor.class) .supervisor("default", "pongSupervisor", Pong.class, PongSupervisorActor.class)); testWorld = TestWorld.start("test", configuration); world = testWorld.world(); }
Example #12
Source File: DispatcherTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@Test public void test100MillionTellWhatITellYou() { TestActor<TellAll> test = testWorld.actorFor( TellAll.class, Definition.has(TellAllActor.class, Definition.NoParameters, "test")); for (int i = 0; i < total100Thousand; ++i) { test.actor().tellWhatITellYou(i); } assertEquals(total100Thousand, TestWorld.Instance.get().allMessagesFor(test.address()).size()); assertEquals(total100Thousand - 1, (int) test.viewTestState().valueOf("lastValue")); }
Example #13
Source File: DispatcherTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@Test public void test100MillionTells() { final TestActor<TellSomething> test = testWorld.actorFor( TellSomething.class, Definition.has(TellSomethingActor.class, Definition.NoParameters, "test")); for (int i = 0; i < total100Thousand; ++i) { test.actor().tellMeSomething("Hello!", i); } assertEquals(total100Thousand, TestWorld.Instance.get().allMessagesFor(test.address()).size()); assertEquals(total100Thousand, (int) test.viewTestState().valueOf("times")); }
Example #14
Source File: ActorsTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { Configuration configuration = Configuration .define() .with(Slf4jLoggerPlugin .Slf4jLoggerPluginConfiguration .define() .defaultLogger() .name("vlingo/actors")); testWorld = TestWorld.start("test", configuration); world = testWorld.world(); }
Example #15
Source File: StageNamedTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@Test public void testActorStageNamed() { final Stage defaultStage = testWorld.stage(); final TestActor<StageNameQuery> query = testWorld.actorFor( StageNameQuery.class, Definition.has(StageNamedTest.StageNamedWithResultActor.class, Definition.NoParameters)); final TestActor<StageNameQueryResult> result = testWorld.actorFor( StageNameQueryResult.class, Definition.has(StageNamedTest.StageNamedWithResultActor.class, Definition.NoParameters)); final String uniqueName = UUID.randomUUID().toString(); query.actor().stageNamed(uniqueName, result.actor()); final Stage stageHolder = (Stage) result.viewTestState().valueOf("stageHolder"); assertEquals(1, TestWorld.Instance.get().allMessagesFor(query.address()).size()); assertEquals(1, TestWorld.Instance.get().allMessagesFor(result.address()).size()); assertNotSame(defaultStage, stageHolder); assertSame(stageHolder, testWorld.stageNamed(uniqueName)); }
Example #16
Source File: EntityTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { testWorld = TestWorld.startWithDefaults("entity-test"); world = testWorld.world(); journalDispatcher = new MockJournalDispatcher(); journal = world.actorFor(Journal.class, InMemoryJournalActor.class, journalDispatcher); registry = new SourcedTypeRegistry(world); SourcedRegistration.registerAllWith(registry, journal); }
Example #17
Source File: StockTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testAvailableQuantityManipulation() { final ItemId itemId = ItemId.of(1l); final Location location = Location.LA; final Stage stage = TestWorld.Instance.get().stage(); final StockState state = Stock.openIn(stage, Location.LA) .andThenTo(updated -> Stock.increaseAvailabilityFor(stage, location, itemId, 500)) .andThenTo(updated -> Stock.increaseAvailabilityFor(stage, location, itemId, 100)) .andThenTo(updated -> Stock.unload(stage, location, itemId, 200)) .await(); Assertions.assertEquals(400, state.quantityFor(itemId)); }
Example #18
Source File: EntityTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { testWorld = TestWorld.startWithDefaults("entity-test"); world = testWorld.world(); journalDispatcher = new MockJournalDispatcher(); journal = world.actorFor(Journal.class, InMemoryJournalActor.class, journalDispatcher); registry = new SourcedTypeRegistry(world); SourcedRegistration.registerAllWith(registry, journal); }
Example #19
Source File: TestMailbox.java From vlingo-actors with Mozilla Public License 2.0 | 4 votes |
public TestMailbox() { this.world = TestWorld.Instance.get(); this.queue = new ConcurrentLinkedQueue<>(); this.suspendedOverrides = new AtomicReference<>(new Stack<>()); }
Example #20
Source File: CalculationTests.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@AfterEach public void tearDown() { TestWorld.Instance.get().world().terminate(); CalculationQueryProvider.reset(); pause(); }
Example #21
Source File: CalculationTests.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
private Stage stage() { return TestWorld.Instance.get().world().stage(); }
Example #22
Source File: ActorEnvironmentTest.java From vlingo-actors with Mozilla Public License 2.0 | 4 votes |
@Test public void testExpectedEnvironment() throws Exception { final Definition definition = Definition.has(EnvironmentProviderActor.class, Definition.NoParameters, "test-env"); final TestActor<EnvironmentProvider> env = testWorld.actorFor(EnvironmentProvider.class, definition); TestState state = env.viewTestState(); final Definition actorDefinition = (Definition) state.valueOf("definition"); assertEquals(0, TestWorld.Instance.get().allMessagesFor(env.address()).size()); assertEquals(testWorld.world().addressFactory().testNextIdValue() - 1, ((Address) state.valueOf("address")).id()); assertEquals(definition.actorName(), actorDefinition.actorName()); assertArrayEquals(definition.parameters().toArray(), actorDefinition.parameters().toArray()); assertEquals(testWorld.world().defaultParent(), state.valueOf("parent")); assertSame(testWorld.stage(), state.valueOf("stage")); }
Example #23
Source File: OrderTest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@AfterEach public void tearDown() { TestWorld.Instance.get().world().terminate(); pause(); }
Example #24
Source File: StockTest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@AfterEach public void tearDown() { TestWorld.Instance.get().world().terminate(); pause(); }