henrykuijpers opened a new pull request, #20: URL: https://github.com/apache/sling-org-apache-sling-testing-sling-mock-oak/pull/20
https://issues.apache.org/jira/browse/SLING-13405 Adds optional Oak Lucene index support to the `JCR_OAK` resource resolver type, so tests can run full-text (`jcr:contains`) and Lucene-index-backed queries. ## Usage 1. Add `org.apache.jackrabbit:oak-lucene` (matching the shaded Oak version, currently `1.86.0`) as test dependency. 2. Register the context plugin: ```java new SlingContextBuilder(ResourceResolverType.JCR_OAK).plugin(OakLuceneContextPlugins.OAK_LUCENE).build(); new AemContextBuilder(ResourceResolverType.JCR_OAK).plugin(OakLuceneContextPlugins.OAK_LUCENE).build(); ``` ## Details - **Opt-in per context**: without the plugin, the class path and behavior are unchanged. `oak-lucene` is an optional dependency and is excluded from the shaded JAR. The plugin registers a marker service before the repository is created; `OakMockSlingRepository.activate()` then registers the Lucene query index provider and index editor provider. - **Async indexes are updated synchronously** within each commit (`SynchronousAsyncIndexHook`), so index definitions from real instances can be used unchanged (`async=["async"]`, `["fulltext-async"]`, hybrid `["async", "nrt"]` / `["async", "sync"]`), and content is searchable as soon as it is saved. Hybrid indexes are written only once per commit. - **Fail fast**: with the plugin, context setup fails with a clear message if `oak-lucene` is missing, older than the shaded Oak version, or shadowed by another artifact. The AEM API JARs (`uber-jar`, `aem-sdk-api`) contain partial Oak Lucene classes, which are detected via the package manifest (`Implementation-Title: Oak Lucene`). - **Warning without plugin**: if a Lucene index definition is added/changed in `/oak:index` while Lucene support is not enabled, a warning is logged once per index path, explaining how to enable it (full-text queries return no results otherwise). - Index data is kept in the in-memory node store, no files are written. - New exported package `org.apache.sling.testing.mock.sling.oak.lucene` (1.0.0) with `OakLuceneContextPlugins`; implementation in the non-exported `...oak.lucene.impl` package. The existing `...oak` package is unchanged (2.1.0). ## Testing - `LuceneIndexTest`: full-text and Lucene property index queries (verified via `EXPLAIN`), content changes/removals, and an index added for existing content, each for `async` = none, `async`, `async,nrt`, `async,sync`, `fulltext-async`. - `LuceneIndexNotEnabledTest`: Lucene is not used without the plugin, even with `oak-lucene` in the class path. - Existing tests pass with and without `oak-lucene` in the class path. - Verified on a downstream AEM project (4370 `SlingContext`/`AemContext` tests, not using the plugin): all tests pass and no measurable performance difference compared to `master`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
