17
17
18
18
package org .openqa .selenium .grid .sessionmap .redis ;
19
19
20
- import org .junit .AfterClass ;
21
- import org .junit .BeforeClass ;
20
+ import org .junit .After ;
21
+ import org .junit .Before ;
22
22
import org .junit .Test ;
23
23
import org .openqa .selenium .ImmutableCapabilities ;
24
24
import org .openqa .selenium .NoSuchSessionException ;
43
43
44
44
public class RedisBackedSessionMapTest {
45
45
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 ;
50
51
51
- @ BeforeClass
52
- public static void startRedisServer () throws URISyntaxException {
53
- bus = new GuavaEventBus ();
52
+ @ Before
53
+ public void setUp () throws URISyntaxException {
54
54
uri = new URI ("redis://localhost:" + PortProber .findFreePort ());
55
55
server = RedisServer .builder ().port (uri .getPort ()).build ();
56
56
server .start ();
57
+
58
+ tracer = DefaultTestTracer .createTracer ();
59
+ bus = new GuavaEventBus ();
60
+ sessions = new RedisBackedSessionMap (tracer , uri , bus );
57
61
}
58
62
59
- @ AfterClass
60
- public static void tearDownRedisServer () {
63
+ @ After
64
+ public void tearDownRedisServer () {
65
+ sessions .getRedisClient ().close ();
61
66
safelyCall (() -> server .stop ());
62
67
}
63
68
64
69
@ Test (expected = NoSuchSessionException .class )
65
70
public void shouldThrowANoSuchSessionExceptionIfTheSessionDoesNotExist () {
66
- SessionMap sessions = new RedisBackedSessionMap (tracer , uri , bus );
67
-
68
71
sessions .get (new SessionId (UUID .randomUUID ()));
69
72
}
70
73
71
74
@ Test
72
75
public void canGetTheUriOfASessionWithoutNeedingUrl () throws URISyntaxException {
73
- SessionMap sessions = new RedisBackedSessionMap (tracer , uri , bus );
74
-
75
76
Session expected = new Session (
76
77
new SessionId (UUID .randomUUID ()),
77
78
new URI ("http://example.com/foo" ),
@@ -89,8 +90,6 @@ public void canGetTheUriOfASessionWithoutNeedingUrl() throws URISyntaxException
89
90
90
91
@ Test
91
92
public void canCreateARedisBackedSessionMap () throws URISyntaxException {
92
- SessionMap sessions = new RedisBackedSessionMap (tracer , uri , bus );
93
-
94
93
Session expected = new Session (
95
94
new SessionId (UUID .randomUUID ()),
96
95
new URI ("http://example.com/foo" ),
@@ -108,8 +107,6 @@ public void canCreateARedisBackedSessionMap() throws URISyntaxException {
108
107
109
108
@ Test
110
109
public void shouldBeAbleToRemoveSessions () throws URISyntaxException {
111
- SessionMap sessions = new RedisBackedSessionMap (tracer , uri , bus );
112
-
113
110
Session expected = new Session (
114
111
new SessionId (UUID .randomUUID ()),
115
112
new URI ("http://example.com/foo" ),
@@ -118,12 +115,10 @@ public void shouldBeAbleToRemoveSessions() throws URISyntaxException {
118
115
Instant .now ());
119
116
sessions .add (expected );
120
117
121
- SessionMap reader = new RedisBackedSessionMap (tracer , uri , bus );
122
-
123
- reader .remove (expected .getId ());
118
+ sessions .remove (expected .getId ());
124
119
125
120
try {
126
- reader .get (expected .getId ());
121
+ sessions .get (expected .getId ());
127
122
fail ("Oh noes!" );
128
123
} catch (NoSuchSessionException ignored ) {
129
124
// This is expected
0 commit comments