Skip to content

Commit

Permalink
Bring SessionRequest and CreateSessionRequest into alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Apr 27, 2021
1 parent 7e20289 commit 47824b3
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Set<Dialect> getDownstreamDialects() {
return downstreamDialects;
}

public Capabilities getCapabilities() {
public Capabilities getDesiredCapabilities() {
return capabilities;
}

Expand All @@ -69,7 +69,7 @@ private static CreateSessionRequest fromJson(JsonInput input) {
input.beginObject();
while (input.hasNext()) {
switch (input.nextName()) {
case "capabilities":
case "desiredCapabilities":
capabilities = input.read(Capabilities.class);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Sess

// Reject new session immediately if no node has the required capabilities
boolean hostsWithCaps = model.stream()
.anyMatch(nodeStatus -> nodeStatus.hasCapability(firstRequest.getCapabilities()));
.anyMatch(nodeStatus -> nodeStatus.hasCapability(firstRequest.getDesiredCapabilities()));

if (!hostsWithCaps) {
String errorMessage = String.format(
Expand All @@ -214,7 +214,7 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Sess
}

// Find a Node that supports the capabilities present in the new session
Set<SlotId> slotIds = slotSelector.selectSlot(firstRequest.getCapabilities(), model);
Set<SlotId> slotIds = slotSelector.selectSlot(firstRequest.getDesiredCapabilities(), model);
if (!slotIds.isEmpty()) {
selected = reserve(slotIds.iterator().next(), firstRequest);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public boolean test(Capabilities capabilities) {

@Override
public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sessionRequest) {
LOG.info("Starting session for " + sessionRequest.getCapabilities());
LOG.info("Starting session for " + sessionRequest.getDesiredCapabilities());

int port = runningInDocker ? 4444 : PortProber.findFreePort();
try (Span span = tracer.getCurrentContext().createSpan("docker_session_factory.apply")) {
Expand All @@ -143,7 +143,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
String logMessage = runningInDocker ? "Creating container..." :
"Creating container, mapping container port 4444 to " + port;
LOG.info(logMessage);
Container container = createBrowserContainer(port, sessionRequest.getCapabilities());
Container container = createBrowserContainer(port, sessionRequest.getDesiredCapabilities());
container.start();
ContainerInfo containerInfo = container.inspect();

Expand Down Expand Up @@ -184,7 +184,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess

Command command = new Command(
null,
DriverCommand.NEW_SESSION(sessionRequest.getCapabilities()));
DriverCommand.NEW_SESSION(sessionRequest.getDesiredCapabilities()));
ProtocolHandshake.Result result;
Response response;
try {
Expand All @@ -211,7 +211,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess

SessionId id = new SessionId(response.getSessionId());
Capabilities capabilities = new ImmutableCapabilities((Map<?, ?>) response.getValue());
Capabilities mergedCapabilities = capabilities.merge(sessionRequest.getCapabilities());
Capabilities mergedCapabilities = capabilities.merge(sessionRequest.getDesiredCapabilities());

Container videoContainer = null;
Optional<DockerAssetsPath> path = ofNullable(this.assetsPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
return Either.left(new SessionNotCreatedException("No downstream dialects were found."));
}

if (!test(sessionRequest.getCapabilities())) {
if (!test(sessionRequest.getDesiredCapabilities())) {
return Either.left(new SessionNotCreatedException("New session request capabilities do not "
+ "match the stereotype."));
}

try (Span span = tracer.getCurrentContext().createSpan("driver_service_factory.apply")) {

Capabilities capabilities = browserOptionsMutator.apply(sessionRequest.getCapabilities());
Capabilities capabilities = browserOptionsMutator.apply(sessionRequest.getDesiredCapabilities());

Optional<Platform> platformName = Optional.ofNullable(capabilities.getPlatformName());
if (platformName.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
throw new IllegalStateException("Only expected one session at a time");
}

Optional<WebDriver> driver = driverInfo.createDriver(sessionRequest.getCapabilities());
Optional<WebDriver> driver = driverInfo.createDriver(sessionRequest.getDesiredCapabilities());
if (!driver.isPresent()) {
return Either.left(new WebDriverException("Unable to create a driver instance"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
attributeMap
.put(AttributeKey.LOGGER_CLASS.getKey(), EventAttribute.setValue(getClass().getName()));
attributeMap.put("session.request.capabilities",
EventAttribute.setValue(sessionRequest.getCapabilities().toString()));
EventAttribute.setValue(sessionRequest.getDesiredCapabilities().toString()));
attributeMap.put("session.request.downstreamdialect",
EventAttribute.setValue(sessionRequest.getDownstreamDialects().toString()));

Expand All @@ -304,7 +304,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
SessionSlot slotToUse = null;
synchronized (factories) {
for (SessionSlot factory : factories) {
if (!factory.isAvailable() || !factory.test(sessionRequest.getCapabilities())) {
if (!factory.isAvailable() || !factory.test(sessionRequest.getDesiredCapabilities())) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
return Either.left(new RetrySessionRequestException("Slot is busy. Try another slot."));
}

if (!test(sessionRequest.getCapabilities())) {
if (!test(sessionRequest.getDesiredCapabilities())) {
return Either.left(new SessionNotCreatedException("New session request capabilities do not "
+ "match the stereotype."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public boolean test(Capabilities capabilities) {
@Override
public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
Require.nonNull("Session creation request", sessionRequest);
DriverService service = createService.apply(sessionRequest.getCapabilities());
DriverService service = createService.apply(sessionRequest.getDesiredCapabilities());

try {
service.start();
Expand All @@ -168,7 +168,7 @@ public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
service,
url,
sessionRequest.getDownstreamDialects(),
sessionRequest.getCapabilities());
sessionRequest.getDesiredCapabilities());
} catch (IOException | IllegalStateException | NullPointerException | InvalidArgumentException e) {
LOG.log(Level.INFO, e.getMessage(), e);
service.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public boolean test(Capabilities capabilities) {

@Override
public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
LOG.finest("Capabilities are: " + new Json().toJson(sessionRequest.getCapabilities()));
LOG.finest("Capabilities are: " + new Json().toJson(sessionRequest.getDesiredCapabilities()));
return factories.stream()
.filter(factory -> factory.test(sessionRequest.getCapabilities()))
.filter(factory -> factory.test(sessionRequest.getDesiredCapabilities()))
.peek(factory -> LOG.finest(String.format("Matched factory %s", factory)))
.map(factory -> factory.apply(sessionRequest))
.filter(Optional::isPresent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {

// Assume the blob fits in the available memory.
try {
if (!provider.canCreateDriverInstanceFor(sessionRequest.getCapabilities())) {
if (!provider.canCreateDriverInstanceFor(sessionRequest.getDesiredCapabilities())) {
return Optional.empty();
}

WebDriver driver = provider.newInstance(sessionRequest.getCapabilities());
WebDriver driver = provider.newInstance(sessionRequest.getDesiredCapabilities());

// Prefer the OSS dialect.
Set<Dialect> downstreamDialects = sessionRequest.getDownstreamDialects();
Dialect downstream = downstreamDialects.contains(Dialect.OSS) || downstreamDialects.isEmpty() ?
Dialect.OSS :
downstreamDialects.iterator().next();
return Optional.of(
new InMemorySession(driver, sessionRequest.getCapabilities(), downstream));
new InMemorySession(driver, sessionRequest.getDesiredCapabilities(), downstream));
} catch (IllegalStateException e) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
if (running != null) {
return Either.left(new SessionNotCreatedException("Session already exists"));
}
Session session = factory.apply(sessionRequest.getCapabilities());
Session session = factory.apply(sessionRequest.getDesiredCapabilities());
running = session;
return Either.right(
new CreateSessionResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public TestSessionFactory(Capabilities stereotype, BiFunction<SessionId, Capabil
@Override
public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sessionRequest) {
SessionId id = new SessionId(UUID.randomUUID());
Session session = sessionGenerator.apply(id, sessionRequest.getCapabilities());
Session session = sessionGenerator.apply(id, sessionRequest.getDesiredCapabilities());

URL url;
try {
Expand Down

0 comments on commit 47824b3

Please sign in to comment.