Skip to content

Commit 8e7af4e

Browse files
committed
Fix and unmute SemanticInferenceMetadataFieldsRecoveryTests
Use the TranslogOperationAsserter to compare the raw operations. Closes #124383 Closes #124384 Closes #124385
1 parent 31bb3d1 commit 8e7af4e

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

muted-tests.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,6 @@ tests:
240240
- class: org.elasticsearch.smoketest.MlWithSecurityIT
241241
method: test {yaml=ml/3rd_party_deployment/Test start and stop multiple deployments}
242242
issue: https://github.com/elastic/elasticsearch/issues/124315
243-
- class: org.elasticsearch.xpack.inference.mapper.SemanticInferenceMetadataFieldsRecoveryTests
244-
method: testSnapshotRecovery {p0=false p1=true}
245-
issue: https://github.com/elastic/elasticsearch/issues/124383
246-
- class: org.elasticsearch.xpack.inference.mapper.SemanticInferenceMetadataFieldsRecoveryTests
247-
method: testSnapshotRecovery {p0=true p1=false}
248-
issue: https://github.com/elastic/elasticsearch/issues/124384
249-
- class: org.elasticsearch.xpack.inference.mapper.SemanticInferenceMetadataFieldsRecoveryTests
250-
method: testSnapshotRecovery {p0=false p1=false}
251-
issue: https://github.com/elastic/elasticsearch/issues/124385
252243
- class: org.elasticsearch.env.NodeEnvironmentTests
253244
method: testIndexCompatibilityChecks
254245
issue: https://github.com/elastic/elasticsearch/issues/124388

test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,8 @@ public static void assertConsistentHistoryBetweenTranslogAndLuceneIndex(Engine e
14001400
assertThat(luceneOp.toString(), luceneOp.primaryTerm(), equalTo(translogOp.primaryTerm()));
14011401
assertThat(luceneOp.opType(), equalTo(translogOp.opType()));
14021402
if (luceneOp.opType() == Translog.Operation.Type.INDEX) {
1403-
if (engine.engineConfig.getIndexSettings().isRecoverySourceSyntheticEnabled()) {
1403+
if (engine.engineConfig.getIndexSettings().isRecoverySourceSyntheticEnabled()
1404+
|| engine.engineConfig.getMapperService().mappingLookup().inferenceFields().isEmpty() == false) {
14041405
assertTrue(
14051406
"luceneOp=" + luceneOp + " != translogOp=" + translogOp,
14061407
translogOperationAsserter.assertSameIndexOperation((Translog.Index) luceneOp, (Translog.Index) translogOp)

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticInferenceMetadataFieldsRecoveryTests.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.index.engine.LuceneChangesSnapshot;
2222
import org.elasticsearch.index.engine.LuceneSyntheticSourceChangesSnapshot;
2323
import org.elasticsearch.index.engine.SearchBasedChangesSnapshot;
24+
import org.elasticsearch.index.engine.TranslogOperationAsserter;
2425
import org.elasticsearch.index.mapper.InferenceMetadataFieldsMapper;
2526
import org.elasticsearch.index.mapper.MapperService;
2627
import org.elasticsearch.index.mapper.SourceFieldMapper;
@@ -42,7 +43,6 @@
4243
import java.util.ArrayList;
4344
import java.util.List;
4445

45-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
4646
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettings;
4747
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomChunkedInferenceEmbeddingByte;
4848
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomChunkedInferenceEmbeddingFloat;
@@ -63,6 +63,13 @@ public SemanticInferenceMetadataFieldsRecoveryTests(boolean useSynthetic, boolea
6363
this.chunkingSettings = generateRandomChunkingSettings();
6464
this.useSynthetic = useSynthetic;
6565
this.useIncludesExcludes = useIncludesExcludes;
66+
System.out.println(
67+
model1.getServiceSettings().dimensions()
68+
+ " "
69+
+ model1.getServiceSettings().similarity()
70+
+ " "
71+
+ model1.getServiceSettings().elementType()
72+
);
6673
}
6774

6875
@ParametersFactory
@@ -137,7 +144,7 @@ protected String defaultMapping() {
137144
}
138145

139146
public void testSnapshotRecovery() throws IOException {
140-
List<Engine.Index> expectedOperations = new ArrayList<>();
147+
List<Translog.Index> expectedOperations = new ArrayList<>();
141148
int size = randomIntBetween(10, 50);
142149
for (int i = 0; i < size; i++) {
143150
var source = randomSource();
@@ -159,8 +166,19 @@ public void testSnapshotRecovery() throws IOException {
159166
}
160167
}
161168
var op = indexForDoc(doc);
162-
expectedOperations.add(op);
163-
engine.index(op);
169+
var result = engine.index(op);
170+
expectedOperations.add(
171+
new Translog.Index(
172+
result.getId(),
173+
result.getSeqNo(),
174+
result.getTerm(),
175+
result.getVersion(),
176+
op.source(),
177+
op.routing(),
178+
op.getAutoGeneratedIdTimestamp()
179+
)
180+
);
181+
164182
if (frequently()) {
165183
engine.flush();
166184
}
@@ -181,13 +199,12 @@ public void testSnapshotRecovery() throws IOException {
181199
IndexVersion.current()
182200
)
183201
) {
202+
var asserter = TranslogOperationAsserter.withEngineConfig(engine.config());
184203
for (int i = 0; i < size; i++) {
185204
var op = snapshot.next();
186205
assertThat(op.opType(), equalTo(Translog.Operation.Type.INDEX));
187206
Translog.Index indexOp = (Translog.Index) op;
188-
assertThat(indexOp.id(), equalTo(expectedOperations.get(i).id()));
189-
assertThat(indexOp.routing(), equalTo(expectedOperations.get(i).routing()));
190-
assertToXContentEquivalent(indexOp.source(), expectedOperations.get(i).source(), XContentType.JSON);
207+
asserter.assertSameIndexOperation(indexOp, expectedOperations.get(i));
191208
}
192209
assertNull(snapshot.next());
193210
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ public static ChunkedInferenceEmbedding randomChunkedInferenceEmbeddingByte(Mode
194194
for (String input : inputs) {
195195
byte[] values = new byte[embeddingLength];
196196
for (int j = 0; j < values.length; j++) {
197-
values[j] = randomByte();
197+
// to avoid vectors with zero magnitude
198+
values[j] = (byte) Math.max(1, randomByte());
198199
}
199200
chunks.add(
200201
new EmbeddingResults.Chunk(

0 commit comments

Comments
 (0)