Skip to content

Commit 4cc8284

Browse files
committed
[grid] Helping json to map properly Slot.java
This was causing an issue that ended up mapping the id value incorrectly. Fixes #10073
1 parent ef09a53 commit 4cc8284

1 file changed

Lines changed: 51 additions & 38 deletions

File tree

  • java/src/org/openqa/selenium/grid/data

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

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717

1818
package org.openqa.selenium.grid.data;
1919

20+
import static java.util.Collections.unmodifiableMap;
21+
2022
import org.openqa.selenium.Capabilities;
2123
import org.openqa.selenium.ImmutableCapabilities;
2224
import org.openqa.selenium.internal.Require;
2325
import org.openqa.selenium.json.JsonInput;
2426

2527
import java.io.Serializable;
2628
import java.time.Instant;
29+
import java.util.Map;
2730
import java.util.Objects;
31+
import java.util.TreeMap;
2832

2933
public class Slot implements Serializable {
3034

@@ -42,44 +46,6 @@ public Slot(SlotId id, Capabilities stereotype, Instant lastStarted, Session ses
4246
this.slotMatcher = new DefaultSlotMatcher();
4347
}
4448

45-
public SlotId getId() {
46-
return id;
47-
}
48-
49-
public Capabilities getStereotype() {
50-
return stereotype;
51-
}
52-
53-
public Instant getLastStarted() {
54-
return lastStarted;
55-
}
56-
57-
public Session getSession() {
58-
return session;
59-
}
60-
61-
public boolean isSupporting(Capabilities caps) {
62-
return slotMatcher.matches(getStereotype(), caps);
63-
}
64-
65-
@Override
66-
public boolean equals(Object o) {
67-
if (!(o instanceof Slot)) {
68-
return false;
69-
}
70-
71-
Slot that = (Slot) o;
72-
return Objects.equals(this.id, that.id) &&
73-
Objects.equals(this.stereotype, that.stereotype) &&
74-
Objects.equals(this.session, that.session) &&
75-
Objects.equals(this.lastStarted.toEpochMilli(), that.lastStarted.toEpochMilli());
76-
}
77-
78-
@Override
79-
public int hashCode() {
80-
return Objects.hash(id, stereotype, session, lastStarted.toEpochMilli());
81-
}
82-
8349
private static Slot fromJson(JsonInput input) {
8450
SlotId id = null;
8551
Capabilities stereotype = null;
@@ -115,4 +81,51 @@ private static Slot fromJson(JsonInput input) {
11581

11682
return new Slot(id, stereotype, lastStarted, session);
11783
}
84+
85+
private Map<String, Object> toJson() {
86+
Map<String, Object> toReturn = new TreeMap<>();
87+
toReturn.put("id", getId());
88+
toReturn.put("lastStarted", getLastStarted());
89+
toReturn.put("session", getSession());
90+
toReturn.put("stereotype", getStereotype());
91+
return unmodifiableMap(toReturn);
92+
}
93+
94+
public SlotId getId() {
95+
return id;
96+
}
97+
98+
public Capabilities getStereotype() {
99+
return stereotype;
100+
}
101+
102+
public Instant getLastStarted() {
103+
return lastStarted;
104+
}
105+
106+
public Session getSession() {
107+
return session;
108+
}
109+
110+
public boolean isSupporting(Capabilities caps) {
111+
return slotMatcher.matches(getStereotype(), caps);
112+
}
113+
114+
@Override
115+
public boolean equals(Object o) {
116+
if (!(o instanceof Slot)) {
117+
return false;
118+
}
119+
120+
Slot that = (Slot) o;
121+
return Objects.equals(this.id, that.id) &&
122+
Objects.equals(this.stereotype, that.stereotype) &&
123+
Objects.equals(this.session, that.session) &&
124+
Objects.equals(this.lastStarted.toEpochMilli(), that.lastStarted.toEpochMilli());
125+
}
126+
127+
@Override
128+
public int hashCode() {
129+
return Objects.hash(id, stereotype, session, lastStarted.toEpochMilli());
130+
}
118131
}

0 commit comments

Comments
 (0)