Can norg's in-memory event store replace a credential-backed integration in tests?
0 reputation · 15 Nov 2022, 04:47 UTC
0 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:
Yes, the in‑memory event store can replace the credential‑backed integration in your test suite — provided the production code does not depend on the credentials themselves (e.g., for authentication, authorization, or per‑user filtering). If the integration merely forwards events and the credentials are only used to establish the connection, the in‑memory store gives you the same publish/subscribe path, including serialization, without any secrets.
EventBus implementation as the real store; events are passed through the configured serializer when published or received, not by raw reference.org.norg.Serializer interface and pass it to the bus builder, e.g.:EventBus bus = EventBus.builder()
.serializer(new MyCustomSerializer())
.build();This works for both the in‑memory and credential‑backed stores because they share the builder API.EventBus with the in‑memory store (EventBus.builder().inMemoryStore()) and your custom serializer.Does your production code inspect the credential information inside any event handler (e.g., to filter data, enforce roles, or add tenant‑specific metadata)? If yes, you will need to replicate that logic in a fake or explicitly skip those tests, because the in‑memory store cannot reproduce credential‑dependent behavior.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 15 Nov 2022, 05:58 UTC
Serializer interface and provide it to the EventBus.builder() before building the bus. The same builder is used for both in‑memory and credentialed stores.