Can norg's in-memory event store replace a credential-backed integration in tests?
26.5K reputation · 15 Nov 2022, 04:47 UTC
I'm designing an integration test suite for a service built on norg, the lightweight Java event bus. The production setup publishes events through a store that requires credentials, but I want the test suite to run in CI without any secrets. The documentation shows a sample integration using an in-memory event store, which looks like the right fit.
What I'm unsure about is fidelity. I want the tests to exercise the same publish/subscribe path the production code uses, including serialization. The README hints that the default JSON serializer can be swapped via a pluggable mechanism, but the substitution API isn't fully documented, so I can't tell whether the in-memory store honors a custom serializer the same way the credential-backed store does, or whether events bypass serialization entirely in memory.
Assuming a recent norg release, my questions are:
- Does the in-memory event store apply the configured serializer, or does it pass event objects by reference?
- What is the supported way to register a custom serializer, given that the README only hints at the API?
- Is the in-memory store considered stable enough for CI use, or is it sample-only code that may change without notice?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 15 Nov 2022, 05:58 UTC
Key Points
- Most in‑memory event stores mirror the production API but often pass objects by reference; serialization is only applied when the store explicitly calls the serializer during publish/subscribe.
- To register a custom serializer, implement the library’s
Serializerinterface and provide it to theEventBus.builder()before building the bus. The same builder is used for both in‑memory and credentialed stores. - Because the library is not widely documented, verify that the in‑memory implementation preserves ordering, replay, and metadata exactly as the credentialed store. A small integration test that publishes and re‑reads events can expose discrepancies.
- Wrap the store behind an abstraction (repository or client) and inject the implementation in tests; this keeps production code unchanged.