Skip to content

Commit b210003

Browse files
committed
[grid] Invoking the create method from MemoizedConfig instead of Config
When the create method was being invoked from Config, the actual configuration was getting lost. This was causing the creation of two in memory buses when the Node was being created through the default implementation class.
1 parent 6a58c62 commit b210003

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

java/server/src/org/openqa/selenium/grid/commands/Standalone.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.openqa.selenium.grid.log.LoggingOptions;
3232
import org.openqa.selenium.grid.node.Node;
3333
import org.openqa.selenium.grid.node.ProxyNodeCdp;
34-
import org.openqa.selenium.grid.node.local.LocalNodeFactory;
34+
import org.openqa.selenium.grid.node.config.NodeOptions;
3535
import org.openqa.selenium.grid.router.Router;
3636
import org.openqa.selenium.grid.security.Secret;
3737
import org.openqa.selenium.grid.security.SecretOptions;
@@ -192,7 +192,7 @@ protected Handlers createHandlers(Config config) {
192192
Route.post("/graphql").to(() -> graphqlHandler),
193193
Route.get("/readyz").to(() -> readinessCheck));
194194

195-
Node node = LocalNodeFactory.create(config);
195+
Node node = new NodeOptions(config).getNode();
196196
combinedHandler.addHandler(node);
197197
distributor.add(node);
198198

java/server/src/org/openqa/selenium/grid/config/Config.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ default <X> X getClass(String section, String option, Class<X> typeOfClass, Stri
5050
// We don't declare a constant on the interface, natch.
5151
Logger.getLogger(Config.class.getName()).fine(String.format("Creating %s as instance of %s", clazz, typeOfClass));
5252

53+
try {
54+
Method create = getCreateMethod(clazz, typeOfClass);
55+
return typeOfClass.cast(create.invoke(null, this));
56+
} catch (ReflectiveOperationException e) {
57+
throw new IllegalArgumentException("Unable to find class: " + clazz, e);
58+
}
59+
}
60+
61+
default <X> Method getCreateMethod(String clazz, Class<X> typeOfClass) {
5362
try {
5463
// Use the context class loader since this is what the `--ext`
5564
// flag modifies.
@@ -58,18 +67,18 @@ default <X> X getClass(String section, String option, Class<X> typeOfClass, Stri
5867

5968
if (!Modifier.isStatic(create.getModifiers())) {
6069
throw new IllegalArgumentException(String.format(
61-
"Class %s's `create(Config)` method must be static", clazz));
70+
"Class %s's `create(Config)` method must be static", clazz));
6271
}
6372

6473
if (!typeOfClass.isAssignableFrom(create.getReturnType())) {
6574
throw new IllegalArgumentException(String.format(
66-
"Class %s's `create(Config)` method must be static", clazz));
75+
"Class %s's `create(Config)` method must be static", clazz));
6776
}
6877

69-
return typeOfClass.cast(create.invoke(null, this));
78+
return create;
7079
} catch (NoSuchMethodException e) {
7180
throw new IllegalArgumentException(String.format(
72-
"Class %s must have a static `create(Config)` method", clazz));
81+
"Class %s must have a static `create(Config)` method", clazz));
7382
} catch (ReflectiveOperationException e) {
7483
throw new IllegalArgumentException("Unable to find class: " + clazz, e);
7584
}

java/server/src/org/openqa/selenium/grid/config/MemoizedConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.openqa.selenium.internal.Require;
2121

22+
import java.lang.reflect.Method;
2223
import java.util.Arrays;
2324
import java.util.List;
2425
import java.util.Map;
@@ -96,7 +97,9 @@ public <X> X getClass(String section, String option, Class<X> typeOfX, String de
9697
new Key(section, option, typeOfX.toGenericString(), defaultClassName),
9798
ignored -> {
9899
try {
99-
return delegate.getClass(section, option, typeOfX, defaultClassName);
100+
String clazz = delegate.get(section, option).orElse(defaultClassName);
101+
Method create = delegate.getCreateMethod(clazz, typeOfX);
102+
return typeOfX.cast(create.invoke(null, this));
100103
} catch (Exception e) {
101104
thrown.set(e);
102105
return null;

0 commit comments

Comments
 (0)