forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...c/test/java/org/elasticsearch/xpack/core/ml/inference/TrainedModelCacheMetadataTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.ml.inference; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractChunkedSerializingTestCase; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
import org.elasticsearch.xpack.core.ml.inference.TrainedModelCacheMetadata.TrainedModelCacheMetadataEntry; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class TrainedModelCacheMetadataTests extends AbstractChunkedSerializingTestCase<TrainedModelCacheMetadata> { | ||
public static TrainedModelCacheMetadataEntry randomEntry() { | ||
return new TrainedModelCacheMetadataEntry(randomIdentifier()); | ||
} | ||
|
||
public static TrainedModelCacheMetadata randomInstance() { | ||
Map<String, TrainedModelCacheMetadataEntry> entries = Stream.generate(TrainedModelCacheMetadataTests::randomEntry) | ||
.limit(randomInt(5)) | ||
.collect(Collectors.toMap(TrainedModelCacheMetadataEntry::getModelId, Function.identity(), (k, k1) -> k, HashMap::new)); | ||
|
||
return new TrainedModelCacheMetadata(entries); | ||
} | ||
|
||
@Override | ||
protected TrainedModelCacheMetadata doParseInstance(XContentParser parser) throws IOException { | ||
return TrainedModelCacheMetadata.fromXContent(parser); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<TrainedModelCacheMetadata> instanceReader() { | ||
return TrainedModelCacheMetadata::new; | ||
} | ||
|
||
@Override | ||
protected TrainedModelCacheMetadata createTestInstance() { | ||
return randomInstance(); | ||
} | ||
|
||
@Override | ||
protected TrainedModelCacheMetadata mutateInstance(TrainedModelCacheMetadata instance) { | ||
return randomValueOtherThan(instance, () -> randomInstance()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.