-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import anachronos | ||
from anachronos import Anachronos | ||
|
||
from e2e_test.testing_messages import ASYNC_INSTANTIATED_EVENT_HANDLER, \ | ||
ASYNC_FUNCTION_EVENT_HANDLER, ASYNC_RUNNABLE_EVENT_HANDLER | ||
from jivago.event.config.annotations import EventHandler, EventHandlerClass | ||
from jivago.lang.annotations import Inject, Override | ||
from jivago.lang.runnable import Runnable | ||
|
||
|
||
@EventHandler("async-event") | ||
class MyHandler(Runnable): | ||
|
||
@Inject | ||
def __init__(self, anachronos: Anachronos): | ||
self.anachronos = anachronos | ||
|
||
@Override | ||
def run(self): | ||
self.anachronos.store(ASYNC_RUNNABLE_EVENT_HANDLER) | ||
|
||
|
||
@EventHandlerClass | ||
class MyHandlerClass(object): | ||
|
||
@Inject | ||
def __init__(self, anachronos: Anachronos): | ||
self.anachronos = anachronos | ||
|
||
@EventHandler("async-event") | ||
def handle(self): | ||
self.anachronos.store(ASYNC_INSTANTIATED_EVENT_HANDLER) | ||
|
||
|
||
@EventHandler("async-event") | ||
def my_event_handler_function(): | ||
anachronos.get_instance().store(ASYNC_FUNCTION_EVENT_HANDLER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
from jivago.event.async_event_bus import AsyncEventBus | ||
from jivago.event.event_bus import EventBus | ||
from jivago.lang.annotations import Inject | ||
from jivago.wsgi.annotations import Resource | ||
from jivago.wsgi.methods import GET | ||
from jivago.wsgi.annotations import Resource, Path | ||
from jivago.wsgi.methods import POST | ||
|
||
|
||
@Resource("/event") | ||
class EventResource(object): | ||
|
||
@Inject | ||
def __init__(self, event_bus: EventBus): | ||
def __init__(self, event_bus: EventBus, async_event_bus: AsyncEventBus): | ||
self.async_event_bus = async_event_bus | ||
self.event_bus = event_bus | ||
|
||
@GET | ||
@POST | ||
def send_event(self) -> str: | ||
self.event_bus.emit("event") | ||
return "OK" | ||
|
||
@POST | ||
@Path("/async") | ||
def send_event_async(self) -> str: | ||
self.async_event_bus.emit("async-event") | ||
return "OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
import anachronos | ||
|
||
from e2e_test.runner import http | ||
from e2e_test.testing_messages import RUNNABLE_EVENT_HANDLER, INSTANTIATED_EVENT_HANDLER, FUNCTION_EVENT_HANDLER | ||
from e2e_test.testing_messages import RUNNABLE_EVENT_HANDLER, INSTANTIATED_EVENT_HANDLER, FUNCTION_EVENT_HANDLER, \ | ||
ASYNC_FUNCTION_EVENT_HANDLER, ASYNC_INSTANTIATED_EVENT_HANDLER, ASYNC_RUNNABLE_EVENT_HANDLER | ||
|
||
|
||
class EventTest(anachronos.TestCase): | ||
|
||
def test_sendEvent(self): | ||
http.get("/event") | ||
http.post("/event") | ||
|
||
self.assertThat(RUNNABLE_EVENT_HANDLER).is_stored() | ||
self.assertThat(INSTANTIATED_EVENT_HANDLER).is_stored() | ||
self.assertThat(FUNCTION_EVENT_HANDLER).is_stored() | ||
|
||
def test_sendAsyncEvent(self): | ||
http.post("/event/async") | ||
|
||
self.assertThat(ASYNC_RUNNABLE_EVENT_HANDLER).is_stored() | ||
self.assertThat(ASYNC_INSTANTIATED_EVENT_HANDLER).is_stored() | ||
self.assertThat(ASYNC_FUNCTION_EVENT_HANDLER).is_stored() | ||
|
||
|
||
if __name__ == '__main__': | ||
anachronos.run_tests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters