Skip to content

Commit 2cf47f3

Browse files
committed
[grid] Fix Redis Session Map test
1 parent 9b5c7b9 commit 2cf47f3

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

java/server/src/org/openqa/selenium/grid/sessionmap/redis/RedisBackedSessionMap.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,9 @@ private void setCommonEventAttributes(Map<String, EventAttributeValue> map) {
305305
EventAttribute.setValue(serverUri.toString()));
306306
}
307307
}
308+
309+
public GridRedisClient getRedisClient() {
310+
return connection;
311+
}
312+
308313
}

java/server/test/org/openqa/selenium/grid/sessionmap/redis/RedisBackedSessionMapTest.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
package org.openqa.selenium.grid.sessionmap.redis;
1919

20-
import org.junit.AfterClass;
21-
import org.junit.BeforeClass;
20+
import org.junit.After;
21+
import org.junit.Before;
2222
import org.junit.Test;
2323
import org.openqa.selenium.ImmutableCapabilities;
2424
import org.openqa.selenium.NoSuchSessionException;
@@ -43,35 +43,36 @@
4343

4444
public class RedisBackedSessionMapTest {
4545

46-
private static RedisServer server;
47-
private static EventBus bus;
48-
private static Tracer tracer = DefaultTestTracer.createTracer();
49-
private static URI uri;
46+
private RedisServer server;
47+
private EventBus bus;
48+
private Tracer tracer = DefaultTestTracer.createTracer();
49+
private URI uri;
50+
private RedisBackedSessionMap sessions;
5051

51-
@BeforeClass
52-
public static void startRedisServer() throws URISyntaxException {
53-
bus = new GuavaEventBus();
52+
@Before
53+
public void setUp() throws URISyntaxException {
5454
uri = new URI("redis://localhost:" + PortProber.findFreePort());
5555
server = RedisServer.builder().port(uri.getPort()).build();
5656
server.start();
57+
58+
tracer = DefaultTestTracer.createTracer();
59+
bus = new GuavaEventBus();
60+
sessions = new RedisBackedSessionMap(tracer, uri, bus);
5761
}
5862

59-
@AfterClass
60-
public static void tearDownRedisServer() {
63+
@After
64+
public void tearDownRedisServer() {
65+
sessions.getRedisClient().close();
6166
safelyCall(() -> server.stop());
6267
}
6368

6469
@Test(expected = NoSuchSessionException.class)
6570
public void shouldThrowANoSuchSessionExceptionIfTheSessionDoesNotExist() {
66-
SessionMap sessions = new RedisBackedSessionMap(tracer, uri, bus);
67-
6871
sessions.get(new SessionId(UUID.randomUUID()));
6972
}
7073

7174
@Test
7275
public void canGetTheUriOfASessionWithoutNeedingUrl() throws URISyntaxException {
73-
SessionMap sessions = new RedisBackedSessionMap(tracer, uri, bus);
74-
7576
Session expected = new Session(
7677
new SessionId(UUID.randomUUID()),
7778
new URI("http://example.com/foo"),
@@ -89,8 +90,6 @@ public void canGetTheUriOfASessionWithoutNeedingUrl() throws URISyntaxException
8990

9091
@Test
9192
public void canCreateARedisBackedSessionMap() throws URISyntaxException {
92-
SessionMap sessions = new RedisBackedSessionMap(tracer, uri, bus);
93-
9493
Session expected = new Session(
9594
new SessionId(UUID.randomUUID()),
9695
new URI("http://example.com/foo"),
@@ -108,8 +107,6 @@ public void canCreateARedisBackedSessionMap() throws URISyntaxException {
108107

109108
@Test
110109
public void shouldBeAbleToRemoveSessions() throws URISyntaxException {
111-
SessionMap sessions = new RedisBackedSessionMap(tracer, uri, bus);
112-
113110
Session expected = new Session(
114111
new SessionId(UUID.randomUUID()),
115112
new URI("http://example.com/foo"),
@@ -118,12 +115,10 @@ public void shouldBeAbleToRemoveSessions() throws URISyntaxException {
118115
Instant.now());
119116
sessions.add(expected);
120117

121-
SessionMap reader = new RedisBackedSessionMap(tracer, uri, bus);
122-
123-
reader.remove(expected.getId());
118+
sessions.remove(expected.getId());
124119

125120
try {
126-
reader.get(expected.getId());
121+
sessions.get(expected.getId());
127122
fail("Oh noes!");
128123
} catch (NoSuchSessionException ignored) {
129124
// This is expected

0 commit comments

Comments
 (0)