Skip to content

Commit 600e63f

Browse files
committed
[grid]: Node sessionTimeout include in Grid status
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent 438b77c commit 600e63f

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

java/src/org/openqa/selenium/grid/data/NodeStatus.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public boolean equals(Object o) {
214214
return Objects.equals(this.nodeId, that.nodeId)
215215
&& Objects.equals(this.externalUri, that.externalUri)
216216
&& this.maxSessionCount == that.maxSessionCount
217+
&& this.sessionTimeout == that.sessionTimeout
217218
&& Objects.equals(this.slots, that.slots)
218219
&& Objects.equals(this.availability, that.availability)
219220
&& Objects.equals(this.version, that.version);
@@ -224,7 +225,7 @@ public int hashCode() {
224225
return Objects.hash(nodeId, externalUri, maxSessionCount, slots, version);
225226
}
226227

227-
private Map<String, Object> toJson() {
228+
public Map<String, Object> toJson() {
228229
Map<String, Object> toReturn = new TreeMap<>();
229230
toReturn.put("nodeId", nodeId);
230231
toReturn.put("externalUri", externalUri);

java/src/org/openqa/selenium/grid/graphql/Grid.java

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public List<Node> getNodes() {
9797
status.getExternalUri(),
9898
status.getAvailability(),
9999
status.getMaxSessionCount(),
100+
status.getSessionTimeout(),
100101
status.getSlots().size(),
101102
stereotypes,
102103
sessions,

java/src/org/openqa/selenium/grid/graphql/Node.java

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.collect.ImmutableList;
2121
import java.net.URI;
22+
import java.time.Duration;
2223
import java.util.ArrayList;
2324
import java.util.HashMap;
2425
import java.util.List;
@@ -38,6 +39,7 @@ public class Node {
3839
private final URI uri;
3940
private final Availability status;
4041
private final int maxSession;
42+
private final Duration sessionTimeout;
4143
private final Map<Capabilities, Integer> stereotypes;
4244
private final Map<Session, Slot> activeSessions;
4345
private final String version;
@@ -49,6 +51,7 @@ public Node(
4951
URI uri,
5052
Availability status,
5153
int maxSession,
54+
Duration sessionTimeout,
5255
int slotCount,
5356
Map<Capabilities, Integer> stereotypes,
5457
Map<Session, Slot> activeSessions,
@@ -63,6 +66,7 @@ public Node(
6366
this.activeSessions = Require.nonNull("Active sessions", activeSessions);
6467
this.version = Require.nonNull("Grid Node version", version);
6568
this.osInfo = Require.nonNull("Grid Node OS info", osInfo);
69+
this.sessionTimeout = Require.positive("Node session timeout", sessionTimeout);
6670
}
6771

6872
public List<org.openqa.selenium.grid.graphql.Session> getSessions() {
@@ -122,6 +126,10 @@ public OsInfo getOsInfo() {
122126
return osInfo;
123127
}
124128

129+
public Duration getSessionTimeout() {
130+
return sessionTimeout;
131+
}
132+
125133
private org.openqa.selenium.grid.graphql.Session createGraphqlSession(
126134
Map.Entry<Session, Slot> entry) {
127135
Session session = entry.getKey();

java/src/org/openqa/selenium/grid/graphql/selenium-grid-schema.graphqls

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Node {
3838
uri: Uri!
3939
status: Status!
4040
maxSession: Int!
41+
sessionTimeout: String!
4142
slotCount: Int!
4243
sessions: [Session]!
4344
sessionCount: Int!

java/src/org/openqa/selenium/grid/router/GridStatusHandler.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,7 @@ public HttpResponse execute(HttpRequest req) {
138138
.map(
139139
node ->
140140
new ImmutableMap.Builder<String, Object>()
141-
.put("id", node.getNodeId())
142-
.put("uri", node.getExternalUri())
143-
.put("maxSessions", node.getMaxSessionCount())
144-
.put("osInfo", node.getOsInfo())
145-
.put("heartbeatPeriod", node.getHeartbeatPeriod().toMillis())
146-
.put("availability", node.getAvailability())
147-
.put("version", node.getVersion())
148-
.put("slots", node.getSlots())
141+
.putAll(node.toJson())
149142
.build())
150143
.collect(toList());
151144

java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public void setUp() throws URISyntaxException {
102102
LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
103103
.add(caps, new TestSessionFactory((id, c) -> new Handler(c)))
104104
.maximumConcurrentSessions(2)
105+
.sessionTimeout(Duration.ofSeconds(30))
105106
.build();
106107

107108
wait =
@@ -143,6 +144,7 @@ void testAddNodeToDistributor() {
143144
NodeStatus distributorNode = nodes.iterator().next();
144145
assertThat(distributorNode.getNodeId()).isEqualByComparingTo(localNode.getId());
145146
assertThat(distributorNode.getExternalUri()).isEqualTo(uri);
147+
assertThat(distributorNode.getSessionTimeout()).isEqualTo(Duration.ofSeconds(30));
146148
}
147149

148150
@Test

0 commit comments

Comments
 (0)