Skip to content

Commit 3fb23fd

Browse files
committed
more testing
1 parent 50450b5 commit 3fb23fd

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/planning/AssignmentPlannerTests.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import static org.elasticsearch.test.hamcrest.OptionalMatchers.isEmpty;
2828
import static org.hamcrest.Matchers.contains;
29+
import static org.hamcrest.Matchers.containsInAnyOrder;
2930
import static org.hamcrest.Matchers.equalTo;
3031
import static org.hamcrest.Matchers.everyItem;
3132
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -1169,7 +1170,7 @@ public void testGivenClusterResize_ShouldRemoveAllocatedDeployments_NewMemoryFie
11691170
assertThat(assignmentPlan.getRemainingNodeCores(node1.id()), greaterThanOrEqualTo(0));
11701171
}
11711172

1172-
public void testDeploymentWithZeroAllocationsIsPreserved() {
1173+
public void testZeroAllocationsDeploymentIsPreserved() {
11731174
Node node = new Node("n_1", ByteSizeValue.ofGb(4).getBytes(), 4);
11741175
Deployment deployment = new Deployment(
11751176
"m_1",
@@ -1187,10 +1188,69 @@ public void testDeploymentWithZeroAllocationsIsPreserved() {
11871188
AssignmentPlan assignmentPlan = new AssignmentPlanner(List.of(node), List.of(deployment)).computePlan();
11881189

11891190
assertThat(assignmentPlan.deployments(), contains(deployment));
1191+
assertThat(assignmentPlan.assignments(deployment), isEmpty());
1192+
assertThat(assignmentPlan.satisfiesAllocations(deployment), is(true));
11901193
assertThat(assignmentPlan.getRemainingNodeMemory(node.id()), equalTo(ByteSizeValue.ofGb(4).getBytes()));
11911194
assertThat(assignmentPlan.getRemainingNodeCores(node.id()), equalTo(4));
11921195
}
11931196

1197+
public void testMultipleZeroAllocationsDeploymentsArePreserved() {
1198+
Node node = new Node("n_1", ByteSizeValue.ofMb(4096).getBytes(), 4);
1199+
Deployment zeroAllocationDeployment1 = new Deployment(
1200+
"m_1",
1201+
"m_1",
1202+
ByteSizeValue.ofMb(500).getBytes(),
1203+
0,
1204+
1,
1205+
Map.of(),
1206+
0,
1207+
new AdaptiveAllocationsSettings(true, 0, 42),
1208+
0,
1209+
0
1210+
);
1211+
Deployment zeroAllocationDeployment2 = new Deployment(
1212+
"m_2",
1213+
"m_2",
1214+
ByteSizeValue.ofMb(600).getBytes(),
1215+
0,
1216+
1,
1217+
Map.of(),
1218+
4,
1219+
new AdaptiveAllocationsSettings(true, 0, 42),
1220+
0,
1221+
0
1222+
);
1223+
Deployment oneAllocationDeployment = new AssignmentPlan.Deployment(
1224+
"m_1",
1225+
"m_1",
1226+
ByteSizeValue.ofMb(100).getBytes(),
1227+
1,
1228+
1,
1229+
Map.of(),
1230+
0,
1231+
null,
1232+
0,
1233+
0
1234+
);
1235+
1236+
AssignmentPlan assignmentPlan = new AssignmentPlanner(
1237+
List.of(node),
1238+
List.of(zeroAllocationDeployment1, oneAllocationDeployment, zeroAllocationDeployment2)
1239+
).computePlan();
1240+
1241+
assertThat(
1242+
assignmentPlan.deployments(),
1243+
containsInAnyOrder(zeroAllocationDeployment1, zeroAllocationDeployment2, oneAllocationDeployment)
1244+
);
1245+
assertModelFullyAssignedToNode(assignmentPlan, oneAllocationDeployment, node);
1246+
assertThat(assignmentPlan.assignments(zeroAllocationDeployment1), isEmpty());
1247+
assertThat(assignmentPlan.assignments(zeroAllocationDeployment2), isEmpty());
1248+
assertThat(assignmentPlan.assignments(zeroAllocationDeployment1), isEmpty());
1249+
assertThat(assignmentPlan.assignments(zeroAllocationDeployment2), isEmpty());
1250+
assertThat(assignmentPlan.getRemainingNodeMemory(node.id()), greaterThanOrEqualTo(0L));
1251+
assertThat(assignmentPlan.getRemainingNodeCores(node.id()), equalTo(3));
1252+
}
1253+
11941254
public static List<Deployment> createDeploymentsFromPlan(AssignmentPlan plan) {
11951255
List<Deployment> deployments = new ArrayList<>();
11961256
for (Deployment m : plan.deployments()) {

0 commit comments

Comments
 (0)