Skip to content

Commit

Permalink
[grid] Add node removed listener to Redis and Jdbc session map implem…
Browse files Browse the repository at this point in the history
…entations
  • Loading branch information
pujagani committed Aug 31, 2021
1 parent 97b6c1b commit 95c78af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openqa.selenium.events.EventBus;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.ConfigException;
import org.openqa.selenium.grid.data.NodeRemovedEvent;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.grid.data.SessionClosedEvent;
import org.openqa.selenium.grid.log.LoggingOptions;
Expand Down Expand Up @@ -83,6 +84,11 @@ public JdbcBackedSessionMap(Tracer tracer, Connection jdbcConnection, EventBus b

this.connection = jdbcConnection;
this.bus.addListener(SessionClosedEvent.listener(this::remove));

this.bus.addListener(NodeRemovedEvent.listener(nodeStatus -> nodeStatus.getSlots().stream()
.filter(slot -> slot.getSession() != null)
.map(slot -> slot.getSession().getId())
.forEach(this::remove)));
}

public static SessionMap create(Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.events.EventBus;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.data.NodeRemovedEvent;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.grid.data.SessionClosedEvent;
import org.openqa.selenium.grid.log.LoggingOptions;
Expand Down Expand Up @@ -79,6 +80,11 @@ public RedisBackedSessionMap(Tracer tracer, URI serverUri, EventBus bus) {
this.connection = new GridRedisClient(serverUri);
this.serverUri = serverUri;
this.bus.addListener(SessionClosedEvent.listener(this::remove));

this.bus.addListener(NodeRemovedEvent.listener(nodeStatus -> nodeStatus.getSlots().stream()
.filter(slot -> slot.getSession() != null)
.map(slot -> slot.getSession().getId())
.forEach(this::remove)));
}

public static SessionMap create(Config config) {
Expand Down

0 comments on commit 95c78af

Please sign in to comment.