Skip to content

Commit 39bf65d

Browse files
Improving tests, corrected changelog
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
1 parent d9166f3 commit 39bf65d

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55

66
## [Unreleased 3.x]
77
### Added
8-
- Add WrappedScorerAccessor interface for plugin access to wrapped scorers in profiling decorators ([#20548](https://github.com/opensearch-project/OpenSearch/issues/20548))
8+
- Add WrappedScorerAccessor interface for plugin access to wrapped scorers in profiling decorators ([#20607](https://github.com/opensearch-project/OpenSearch/pull/20607))
99
- Support expected cluster name with validation in CCS Sniff mode ([#20532](https://github.com/opensearch-project/OpenSearch/pull/20532))
1010
- Choose the best performing node when writing with append-only index ([#20065](https://github.com/opensearch-project/OpenSearch/pull/20065))
1111
- Add security policy to allow `accessUnixDomainSocket` in `transport-grpc` module ([#20463](https://github.com/opensearch-project/OpenSearch/pull/20463))
@@ -28,7 +28,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2828
- Service does not start on Windows with OpenJDK ([#20615](https://github.com/opensearch-project/OpenSearch/pull/20615))
2929
- Update RemoteClusterStateCleanupManager to performed batched deletions of stale ClusterMetadataManifests and address deletion timeout issues ([#20566](https://github.com/opensearch-project/OpenSearch/pull/20566))
3030
- Fix the regression of terms agg optimization at high cardinality ([#20623](https://github.com/opensearch-project/OpenSearch/pull/20623))
31-
- Fix ProfileScorer.getChildren() to expose wrapped scorer in scorer tree for plugin compatibility ([#20548](https://github.com/opensearch-project/OpenSearch/issues/20548))
3231

3332
### Dependencies
3433
- Bump `ch.qos.logback:logback-core` and `ch.qos.logback:logback-classic` from 1.5.24 to 1.5.27 ([#20525](https://github.com/opensearch-project/OpenSearch/pull/20525))

server/src/test/java/org/opensearch/search/profile/query/ProfileScorerTests.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,36 @@ public void testImplementsWrappedScorerAccessor() throws IOException {
129129
assertSame("WrappedScorerAccessor.getWrappedScorer() should return the original scorer", fakeScorer, accessor.getWrappedScorer());
130130
}
131131

132-
public void testUnwrapFromScorableReference() throws IOException {
133-
// Simulate how a plugin collector receives a generic Scorable reference
134-
// (e.g., via LeafCollector.setScorer()) and uses WrappedScorerAccessor
135-
// to unwrap the profiling wrapper and access the original scorer
132+
public void testUnwrapNestedProfilingScorerFromScorableReference() throws IOException {
133+
// Simulate nested profiling: a scorer wrapped in two ProfileScorer layers.
134+
// This tests that a plugin can iteratively unwrap through multiple profiling
135+
// layers via a generic Scorable reference (as received in LeafCollector.setScorer())
136136
Query query = new MatchAllDocsQuery();
137137
Weight weight = query.createWeight(new IndexSearcher(new MultiReader()), ScoreMode.TOP_SCORES, 1f);
138138
FakeScorer fakeScorer = new FakeScorer(weight);
139-
QueryProfileBreakdown profile = new QueryProfileBreakdown(ProfileMetricUtil.getDefaultQueryProfileMetrics());
140-
141-
// Plugin only sees a Scorable reference, not ProfileScorer
142-
Scorable scorable = new ProfileScorer(fakeScorer, profile);
143-
144-
// Plugin uses instanceof to detect the wrapper and unwrap
145-
assertTrue("Scorable should be detected as WrappedScorerAccessor", scorable instanceof WrappedScorerAccessor);
146-
Scorer unwrapped = ((WrappedScorerAccessor) scorable).getWrappedScorer();
147-
assertSame("Unwrapped scorer should be the original FakeScorer", fakeScorer, unwrapped);
139+
QueryProfileBreakdown innerProfile = new QueryProfileBreakdown(ProfileMetricUtil.getDefaultQueryProfileMetrics());
140+
QueryProfileBreakdown outerProfile = new QueryProfileBreakdown(ProfileMetricUtil.getDefaultQueryProfileMetrics());
141+
142+
// Create nested profiling: FakeScorer -> innerProfileScorer -> outerProfileScorer
143+
ProfileScorer innerProfileScorer = new ProfileScorer(fakeScorer, innerProfile);
144+
ProfileScorer outerProfileScorer = new ProfileScorer(innerProfileScorer, outerProfile);
145+
146+
// Plugin only sees a Scorable reference
147+
Scorable scorable = outerProfileScorer;
148+
149+
// Unwrap first layer
150+
assertTrue("Outer Scorable should be detected as WrappedScorerAccessor", scorable instanceof WrappedScorerAccessor);
151+
Scorer firstUnwrap = ((WrappedScorerAccessor) scorable).getWrappedScorer();
152+
assertNotSame("First unwrap should not be the original scorer", fakeScorer, firstUnwrap);
153+
assertTrue(
154+
"First unwrap should still be a WrappedScorerAccessor (inner ProfileScorer)",
155+
firstUnwrap instanceof WrappedScorerAccessor
156+
);
157+
158+
// Unwrap second layer to reach the original scorer
159+
Scorer secondUnwrap = ((WrappedScorerAccessor) firstUnwrap).getWrappedScorer();
160+
assertSame("Second unwrap should be the original FakeScorer", fakeScorer, secondUnwrap);
161+
assertFalse("Original scorer should not implement WrappedScorerAccessor", secondUnwrap instanceof WrappedScorerAccessor);
148162
}
149163

150164
public void testGetChildren_delegatesToWrappedScorer() throws IOException {

0 commit comments

Comments
 (0)