Skip to content

Commit

Permalink
[grid]: Pass the HttpClient.Factory to the RemoteNode
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Feb 11, 2019
1 parent 2af549f commit c5c18d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openqa.selenium.grid.distributor;

import static org.openqa.selenium.json.Json.MAP_TYPE;
import static org.openqa.selenium.net.Urls.fromUri;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
Expand Down Expand Up @@ -81,10 +80,10 @@ public void execute(HttpRequest req, HttpResponse resp) throws IOException {

Node node = new RemoteNode(
tracer,
httpFactory,
id,
uri,
capabilities,
httpFactory.createClient(fromUri(uri)));
capabilities);

distributor.add(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.grid.node.remote;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.openqa.selenium.net.Urls.fromUri;
import static org.openqa.selenium.remote.http.HttpMethod.DELETE;
import static org.openqa.selenium.remote.http.HttpMethod.GET;
import static org.openqa.selenium.remote.http.HttpMethod.POST;
Expand All @@ -28,9 +29,9 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.grid.component.HealthCheck;
import org.openqa.selenium.grid.data.NodeStatus;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.grid.node.Node;
import org.openqa.selenium.grid.data.NodeStatus;
import org.openqa.selenium.grid.web.Values;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonInput;
Expand Down Expand Up @@ -63,15 +64,16 @@ public class RemoteNode extends Node {

public RemoteNode(
DistributedTracer tracer,
HttpClient.Factory clientFactory,
UUID id,
URI externalUri,
Collection<Capabilities> capabilities,
HttpClient client) {
Collection<Capabilities> capabilities) {
super(tracer, id);
this.externalUri = Objects.requireNonNull(externalUri);
this.capabilities = ImmutableSet.copyOf(capabilities);

Objects.requireNonNull(client);
HttpClient client = Objects.requireNonNull(clientFactory).createClient(fromUri(externalUri));

this.client = req -> {
try {
return client.execute(req);
Expand Down
13 changes: 6 additions & 7 deletions java/server/test/org/openqa/selenium/grid/node/NodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,19 @@ public void execute(HttpRequest req, HttpResponse resp) {
.maximumConcurrentSessions(2)
.build();

HttpClient client = new PassthroughHttpClient<>(local);
node = new RemoteNode(
tracer,
new PassthroughHttpClient.Factory<>(local),
UUID.randomUUID(),
uri,
ImmutableSet.of(caps),
client);
ImmutableSet.of(caps));
}

@Test
public void shouldRefuseToCreateASessionIfNoFactoriesAttached() {
Node local = LocalNode.builder(tracer, bus, clientFactory, uri).build();
HttpClient client = new PassthroughHttpClient<>(local);
Node node = new RemoteNode(tracer, UUID.randomUUID(), uri, ImmutableSet.of(), client);
HttpClient.Factory clientFactory = new PassthroughHttpClient.Factory<>(local);
Node node = new RemoteNode(tracer, clientFactory, UUID.randomUUID(), uri, ImmutableSet.of());

Optional<Session> session = node.newSession(caps);

Expand Down Expand Up @@ -234,10 +233,10 @@ public void execute(HttpRequest req, HttpResponse resp) {
.build();
Node remote = new RemoteNode(
tracer,
new PassthroughHttpClient.Factory<>(local),
UUID.randomUUID(),
uri,
ImmutableSet.of(caps),
new PassthroughHttpClient<>(local));
ImmutableSet.of(caps));

Session session = remote.newSession(caps)
.orElseThrow(() -> new RuntimeException("Session not created"));
Expand Down

0 comments on commit c5c18d3

Please sign in to comment.