@@ -131,6 +131,37 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
131
131
assertThat (lightest .getSlots ().stream ()).anyMatch (slot -> expected .equals (slot .getId ()));
132
132
}
133
133
134
+ @ Test
135
+ public void theNodeWhichHasExceededMaxSessionsIsNotSelected () {
136
+ Capabilities chrome = new ImmutableCapabilities ("browserName" , "chrome" );
137
+
138
+ NodeStatus lightLoad =
139
+ createNode (ImmutableList .of (chrome ), 12 , 2 );
140
+ NodeStatus mediumLoad =
141
+ createNode (ImmutableList .of (chrome ), 12 , 5 );
142
+ NodeStatus maximumLoad =
143
+ createNode (ImmutableList .of (chrome ), 12 , 12 );
144
+
145
+ Set <SlotId > ids = selector .selectSlot (chrome , ImmutableSet .of (maximumLoad , mediumLoad , lightLoad ));
146
+ SlotId expected = ids .iterator ().next ();
147
+
148
+ // The slot should belong to the Node with light load
149
+ assertThat (lightLoad .getSlots ().stream ())
150
+ .anyMatch (slot -> expected .equals (slot .getId ()));
151
+
152
+ // The node whose current number of sessions is greater than or equal to the max sessions is not included
153
+ // Hence, the node with the maximum load is skipped
154
+ ImmutableSet <NodeId > nodeIds = ids .stream ()
155
+ .map (SlotId ::getOwningNodeId )
156
+ .distinct ()
157
+ .collect (toImmutableSet ());
158
+ assertThat (nodeIds ).doesNotContain (maximumLoad .getNodeId ());
159
+ assertThat (nodeIds )
160
+ .containsSequence (
161
+ lightLoad .getNodeId (),
162
+ mediumLoad .getNodeId ());
163
+ }
164
+
134
165
@ Test
135
166
public void nodesAreOrderedByNumberOfSupportedBrowsersAndLoad () {
136
167
Capabilities chrome = new ImmutableCapabilities ("browserName" , "chrome" );
@@ -161,6 +192,7 @@ public void nodesAreOrderedByNumberOfSupportedBrowsersAndLoad() {
161
192
.anyMatch (slot -> expected .equals (slot .getId ()));
162
193
163
194
// Nodes are ordered by the diversity of supported browsers, then by load
195
+ // The node whose current number of sessions is greater than or equal to the max sessions is not included
164
196
ImmutableSet <NodeId > nodeIds = ids .stream ()
165
197
.map (SlotId ::getOwningNodeId )
166
198
.distinct ()
@@ -169,7 +201,6 @@ public void nodesAreOrderedByNumberOfSupportedBrowsersAndLoad() {
169
201
.containsSequence (
170
202
highLoadAndOneBrowser .getNodeId (),
171
203
mediumLoadAndTwoBrowsers .getNodeId (),
172
- mediumLoadAndOtherTwoBrowsers .getNodeId (),
173
204
lightLoadAndThreeBrowsers .getNodeId ());
174
205
}
175
206
0 commit comments