|
20 | 20 | import com.google.common.collect.ImmutableMap;
|
21 | 21 | import com.google.common.collect.ImmutableSet;
|
22 | 22 | import org.assertj.core.api.AbstractAssert;
|
| 23 | +import org.junit.Assert; |
23 | 24 | import org.junit.Before;
|
24 | 25 | import org.junit.Ignore;
|
25 | 26 | import org.junit.Test;
|
|
35 | 36 | import org.openqa.selenium.grid.data.CreateSessionRequest;
|
36 | 37 | import org.openqa.selenium.grid.data.CreateSessionResponse;
|
37 | 38 | import org.openqa.selenium.grid.data.DistributorStatus;
|
| 39 | +import org.openqa.selenium.grid.data.NodeHeartBeatEvent; |
38 | 40 | import org.openqa.selenium.grid.data.NodeRemovedEvent;
|
39 | 41 | import org.openqa.selenium.grid.data.NodeStatus;
|
40 | 42 | import org.openqa.selenium.grid.data.Session;
|
|
81 | 83 | import java.util.UUID;
|
82 | 84 | import java.util.concurrent.CountDownLatch;
|
83 | 85 | import java.util.concurrent.TimeUnit;
|
| 86 | +import java.util.concurrent.atomic.AtomicBoolean; |
84 | 87 | import java.util.concurrent.atomic.AtomicReference;
|
85 | 88 | import java.util.logging.Logger;
|
86 | 89 | import java.util.stream.Collectors;
|
@@ -148,6 +151,56 @@ public void creatingANewSessionWithoutANodeEndsInFailure() {
|
148 | 151 | }
|
149 | 152 | }
|
150 | 153 |
|
| 154 | + @Test |
| 155 | + public void shouldStartHeartBeatOnNodeRegistration() { |
| 156 | + EventBus bus = new GuavaEventBus(); |
| 157 | + LocalSessionMap sessions = new LocalSessionMap(tracer, bus); |
| 158 | + LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue( |
| 159 | + tracer, |
| 160 | + bus, |
| 161 | + Duration.ofSeconds(2), |
| 162 | + Duration.ofSeconds(2)); |
| 163 | + LocalNewSessionQueuer queuer = new LocalNewSessionQueuer( |
| 164 | + tracer, |
| 165 | + bus, |
| 166 | + localNewSessionQueue, |
| 167 | + registrationSecret); |
| 168 | + LocalNode node = LocalNode.builder(tracer, bus, routableUri, routableUri, registrationSecret) |
| 169 | + .add( |
| 170 | + caps, |
| 171 | + new TestSessionFactory((id, c) -> new Session(id, nodeUri, stereotype, c, Instant.now()))) |
| 172 | + .build(); |
| 173 | + |
| 174 | + Distributor distributor = new LocalDistributor( |
| 175 | + tracer, |
| 176 | + bus, |
| 177 | + new PassthroughHttpClient.Factory(node), |
| 178 | + sessions, |
| 179 | + queuer, |
| 180 | + registrationSecret); |
| 181 | + distributor.add(node); |
| 182 | + |
| 183 | + AtomicBoolean heartbeatStarted = new AtomicBoolean(); |
| 184 | + CountDownLatch latch = new CountDownLatch(1); |
| 185 | + |
| 186 | + bus.addListener(NodeHeartBeatEvent.listener(nodeId -> { |
| 187 | + latch.countDown(); |
| 188 | + if (node.getId().equals(nodeId)) { |
| 189 | + heartbeatStarted.set(true); |
| 190 | + } |
| 191 | + })); |
| 192 | + waitToHaveCapacity(distributor); |
| 193 | + boolean eventFired = false; |
| 194 | + try { |
| 195 | + eventFired = latch.await(30, TimeUnit.SECONDS); |
| 196 | + } catch (InterruptedException e) { |
| 197 | + Assert.fail("Thread Interrupted"); |
| 198 | + } |
| 199 | + |
| 200 | + assertThat(eventFired).isTrue(); |
| 201 | + assertThat(heartbeatStarted).isTrue(); |
| 202 | + } |
| 203 | + |
151 | 204 | @Test
|
152 | 205 | public void shouldBeAbleToAddANodeAndCreateASession() {
|
153 | 206 | LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
|
|
0 commit comments