Conversation
|
@wezell In this case it seemed that the DataGen was actually using DEFER by default when removing. This actually triggered the code in com.dotcms.content.elasticsearch.business.ESContentFactoryImpl#findAllCurrent(int, int) to still find the removed items in search, but the db in the internal find() method in that class already saw the item removed. This lead to the result list containing null entries as the null result from find() was being added to the list. At the moment the test case has been updated to skip these null cases and we should now be ensuring that the search state is correctly updated anyway, but should we update the source of findAllCurrent to just skip null results from find() |
There was a problem hiding this comment.
I think this is the wrong fix for a few reasons.
findAllContentshould be using the db not ES- If there are still null entries, these should be filtered out in the API and not in the test
Here is what the method should look like (this is untested but you get the idea):
final long ultimateLimit = Math.min(limit, ESContentletAPIImpl.MAX_LIMIT);
List<Contentlet> contentlets = new ArrayList<>();
try {
final DotConnect dotConnect = new DotConnect("select working_inode from contentlet_version_info limit " + limit + " offset " + offset);
dotConnect.addParam(ultimateLimit);
dotConnect.addParam(offset);
List<Map<String, Object>> results = dotConnect.loadObjectResults();
for (Map<String, Object> result : results) {
contentlets.add(find((String) result.get("working_inode")));
}
}catch(Exception e){
throw new DotRuntimeException(e);
}
return contentlets;
****
return contentlets;
bd8110d to
266c006
Compare
wezell
left a comment
There was a problem hiding this comment.
This looks great, thanks.
…#34600) - Change ESContentFactoryImpl.findAllCurrent to query DB (contentlet_version_info) instead of Elasticsearch, which can have stale entries - Filter null entries in the API layer since find() can return null - Fix testGet_showCategories_AsAnonUser by ensuring permission propagation - Update ContentletDataGen destructive methods (archive, delete, destroy) to use IndexPolicy.WAIT_FOR for better test reliability Root cause: The ES index can have stale entries when content is deleted from DB but not yet removed from ES. Using the DB as source of truth eliminates this race condition. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add a test-specific findAllContent method to ContentletDataGen that queries the database directly. This provides a reliable alternative to the deprecated ContentletAPI.findAllContent for test code. Updates tests to use the new ContentletDataGen.findAllContent: - ContentMapTest - ContentletIndexAPIImplTest - PushedAssetsAPITest - ContentletAPITest Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ility Update all findAllContent method deprecation Javadocs across the ContentletAPI stack to clearly state: - Method should not be used (DO NOT USE) - For tests, use ContentletDataGen.findAllContent(offset, limit) instead Updated files: - ContentletAPI.java - Main interface with detailed deprecation message - ESContentletAPIImpl.java - Implementation - ContentletAPIInterceptor.java - Interceptor - ContentletAPIPreHook.java - Pre-hook interface - ContentletAPIPostHook.java - Post-hook interface Also fixed typo: "0 of no limit" -> "0 if no limit" Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
266c006 to
03ddaa3
Compare
Summary
Fixes flaky tests
ContentMapTest.testGetRecycledRequestandtestGet_showCategories_AsAnonUserby addressing the root cause:findAllContentwas using Elasticsearch which can have stale entries after content deletion.Changes
Fixed
ESContentFactoryImpl.findAllCurrentto use database queries instead of Elasticsearchcontentlet_version_infotable directly for working contentlet inodesAdded
ContentletDataGen.findAllContenttest utilityDeprecated
ContentletAPI.findAllContent@Deprecatedannotation across all API layers:ContentletAPI.java(interface)ESContentletAPIImpl.java(implementation)ContentletAPIInterceptor.javaContentletAPIPreHook.javaContentletAPIPostHook.javaUpdated tests to use new test utility
ContentMapTestContentletIndexAPIImplTestPushedAssetsAPITestContentletAPITestAdded
IndexPolicy.WAIT_FORtoContentletDataGendestructive methodsarchive(),delete(),destroy()now wait for ES index updatesRoot Cause
The Elasticsearch index can have stale entries when content is deleted from the database but not yet removed from the ES index. By querying the
contentlet_version_infotable directly and then loading contentlets by inode, we ensure we only get valid, existing content.Test plan
ContentMapTest.testGetRecycledRequest- passes consistentlyContentMapTest.testGet_showCategories_AsAnonUser- passes consistently🤖 Generated with Claude Code
Closes #34600
This PR fixes: #34600