Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.device.impl; |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 17 | |
Ray Milkey | cc53abd | 2015-02-19 12:31:33 -0800 | [diff] [blame] | 18 | import java.util.ArrayList; |
| 19 | import java.util.Iterator; |
| 20 | import java.util.List; |
| 21 | import java.util.Set; |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame^] | 22 | import java.util.concurrent.CompletableFuture; |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 23 | |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 24 | import org.junit.After; |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
Ray Milkey | cc53abd | 2015-02-19 12:31:33 -0800 | [diff] [blame] | 27 | import org.onlab.packet.ChassisId; |
| 28 | import org.onlab.packet.IpAddress; |
| 29 | import org.onosproject.cluster.ClusterServiceAdapter; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.cluster.ControllerNode; |
| 31 | import org.onosproject.cluster.DefaultControllerNode; |
| 32 | import org.onosproject.cluster.NodeId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.event.Event; |
| 34 | import org.onosproject.event.impl.TestEventDispatcher; |
| 35 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 36 | import org.onosproject.mastership.MastershipTerm; |
| 37 | import org.onosproject.mastership.MastershipTermService; |
| 38 | import org.onosproject.net.Device; |
| 39 | import org.onosproject.net.DeviceId; |
| 40 | import org.onosproject.net.MastershipRole; |
| 41 | import org.onosproject.net.Port; |
| 42 | import org.onosproject.net.PortNumber; |
| 43 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 44 | import org.onosproject.net.device.DefaultPortDescription; |
| 45 | import org.onosproject.net.device.DeviceAdminService; |
| 46 | import org.onosproject.net.device.DeviceClockProviderService; |
| 47 | import org.onosproject.net.device.DeviceDescription; |
| 48 | import org.onosproject.net.device.DeviceEvent; |
| 49 | import org.onosproject.net.device.DeviceListener; |
| 50 | import org.onosproject.net.device.DeviceProvider; |
| 51 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 52 | import org.onosproject.net.device.DeviceProviderService; |
| 53 | import org.onosproject.net.device.DeviceService; |
| 54 | import org.onosproject.net.device.PortDescription; |
| 55 | import org.onosproject.net.provider.AbstractProvider; |
| 56 | import org.onosproject.net.provider.ProviderId; |
| 57 | import org.onosproject.store.trivial.impl.SimpleDeviceStore; |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 58 | |
Ray Milkey | cc53abd | 2015-02-19 12:31:33 -0800 | [diff] [blame] | 59 | import com.google.common.collect.Sets; |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 60 | |
Ray Milkey | cc53abd | 2015-02-19 12:31:33 -0800 | [diff] [blame] | 61 | import static org.junit.Assert.assertEquals; |
| 62 | import static org.junit.Assert.assertFalse; |
| 63 | import static org.junit.Assert.assertNotNull; |
| 64 | import static org.junit.Assert.assertNull; |
| 65 | import static org.junit.Assert.assertTrue; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 66 | import static org.onosproject.net.Device.Type.SWITCH; |
| 67 | import static org.onosproject.net.DeviceId.deviceId; |
Ray Milkey | cc53abd | 2015-02-19 12:31:33 -0800 | [diff] [blame] | 68 | import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; |
| 69 | import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; |
| 70 | import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_UPDATED; |
| 71 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED; |
| 72 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED; |
| 73 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED; |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Test codifying the device service & device provider service contracts. |
| 77 | */ |
tom | 41a2c5f | 2014-09-19 09:20:35 -0700 | [diff] [blame] | 78 | public class DeviceManagerTest { |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 79 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 80 | private static final ProviderId PID = new ProviderId("of", "foo"); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 81 | private static final DeviceId DID1 = deviceId("of:foo"); |
| 82 | private static final DeviceId DID2 = deviceId("of:bar"); |
| 83 | private static final String MFR = "whitebox"; |
| 84 | private static final String HW = "1.1.x"; |
| 85 | private static final String SW1 = "3.8.1"; |
| 86 | private static final String SW2 = "3.9.5"; |
| 87 | private static final String SN = "43311-12345"; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 88 | private static final ChassisId CID = new ChassisId(); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 89 | |
tom | 24c55cd | 2014-09-06 10:47:25 -0700 | [diff] [blame] | 90 | private static final PortNumber P1 = PortNumber.portNumber(1); |
| 91 | private static final PortNumber P2 = PortNumber.portNumber(2); |
| 92 | private static final PortNumber P3 = PortNumber.portNumber(3); |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 93 | private static final NodeId NID_LOCAL = new NodeId("local"); |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 94 | private static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1"); |
tom | 24c55cd | 2014-09-06 10:47:25 -0700 | [diff] [blame] | 95 | |
tom | 41a2c5f | 2014-09-19 09:20:35 -0700 | [diff] [blame] | 96 | private DeviceManager mgr; |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 97 | |
| 98 | protected DeviceService service; |
| 99 | protected DeviceAdminService admin; |
| 100 | protected DeviceProviderRegistry registry; |
| 101 | protected DeviceProviderService providerService; |
| 102 | protected TestProvider provider; |
| 103 | protected TestListener listener = new TestListener(); |
| 104 | |
| 105 | @Before |
| 106 | public void setUp() { |
tom | 41a2c5f | 2014-09-19 09:20:35 -0700 | [diff] [blame] | 107 | mgr = new DeviceManager(); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 108 | service = mgr; |
| 109 | admin = mgr; |
| 110 | registry = mgr; |
tom | 41a2c5f | 2014-09-19 09:20:35 -0700 | [diff] [blame] | 111 | mgr.store = new SimpleDeviceStore(); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 112 | mgr.eventDispatcher = new TestEventDispatcher(); |
Yuta HIGUCHI | bcac499 | 2014-11-22 19:27:57 -0800 | [diff] [blame] | 113 | TestMastershipManager mastershipManager = new TestMastershipManager(); |
| 114 | mgr.mastershipService = mastershipManager; |
| 115 | mgr.termService = mastershipManager; |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 116 | mgr.clusterService = new TestClusterService(); |
Yuta HIGUCHI | 093e83e | 2014-10-10 22:26:11 -0700 | [diff] [blame] | 117 | mgr.deviceClockProviderService = new TestClockProviderService(); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 118 | mgr.activate(); |
| 119 | |
| 120 | service.addListener(listener); |
| 121 | |
| 122 | provider = new TestProvider(); |
| 123 | providerService = registry.register(provider); |
| 124 | assertTrue("provider should be registered", |
| 125 | registry.getProviders().contains(provider.id())); |
| 126 | } |
| 127 | |
| 128 | @After |
| 129 | public void tearDown() { |
| 130 | registry.unregister(provider); |
| 131 | assertFalse("provider should not be registered", |
| 132 | registry.getProviders().contains(provider.id())); |
| 133 | service.removeListener(listener); |
| 134 | mgr.deactivate(); |
| 135 | } |
| 136 | |
| 137 | private void connectDevice(DeviceId deviceId, String swVersion) { |
| 138 | DeviceDescription description = |
| 139 | new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 140 | HW, swVersion, SN, CID); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 141 | providerService.deviceConnected(deviceId, description); |
| 142 | assertNotNull("device should be found", service.getDevice(DID1)); |
| 143 | } |
| 144 | |
| 145 | @Test |
| 146 | public void deviceConnected() { |
| 147 | assertNull("device should not be found", service.getDevice(DID1)); |
| 148 | connectDevice(DID1, SW1); |
| 149 | validateEvents(DEVICE_ADDED); |
| 150 | |
| 151 | Iterator<Device> it = service.getDevices().iterator(); |
| 152 | assertNotNull("one device expected", it.next()); |
| 153 | assertFalse("only one device expected", it.hasNext()); |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 154 | assertEquals("incorrect device count", 1, service.getDeviceCount()); |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 155 | assertTrue("device should be available", service.isAvailable(DID1)); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Test |
| 159 | public void deviceDisconnected() { |
| 160 | connectDevice(DID1, SW1); |
| 161 | connectDevice(DID2, SW1); |
| 162 | validateEvents(DEVICE_ADDED, DEVICE_ADDED); |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 163 | assertTrue("device should be available", service.isAvailable(DID1)); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 164 | |
| 165 | // Disconnect |
| 166 | providerService.deviceDisconnected(DID1); |
| 167 | assertNotNull("device should not be found", service.getDevice(DID1)); |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 168 | assertFalse("device should not be available", service.isAvailable(DID1)); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 169 | validateEvents(DEVICE_AVAILABILITY_CHANGED); |
| 170 | |
| 171 | // Reconnect |
| 172 | connectDevice(DID1, SW1); |
| 173 | validateEvents(DEVICE_AVAILABILITY_CHANGED); |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 174 | |
| 175 | assertEquals("incorrect device count", 2, service.getDeviceCount()); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Test |
| 179 | public void deviceUpdated() { |
| 180 | connectDevice(DID1, SW1); |
| 181 | validateEvents(DEVICE_ADDED); |
| 182 | |
| 183 | connectDevice(DID1, SW2); |
| 184 | validateEvents(DEVICE_UPDATED); |
| 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void getRole() { |
| 189 | connectDevice(DID1, SW1); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 190 | assertEquals("incorrect role", MastershipRole.MASTER, service.getRole(DID1)); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 191 | } |
| 192 | |
tom | 24c55cd | 2014-09-06 10:47:25 -0700 | [diff] [blame] | 193 | @Test |
| 194 | public void updatePorts() { |
| 195 | connectDevice(DID1, SW1); |
| 196 | List<PortDescription> pds = new ArrayList<>(); |
| 197 | pds.add(new DefaultPortDescription(P1, true)); |
| 198 | pds.add(new DefaultPortDescription(P2, true)); |
| 199 | pds.add(new DefaultPortDescription(P3, true)); |
| 200 | providerService.updatePorts(DID1, pds); |
| 201 | validateEvents(DEVICE_ADDED, PORT_ADDED, PORT_ADDED, PORT_ADDED); |
| 202 | pds.clear(); |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 203 | |
tom | 24c55cd | 2014-09-06 10:47:25 -0700 | [diff] [blame] | 204 | pds.add(new DefaultPortDescription(P1, false)); |
| 205 | pds.add(new DefaultPortDescription(P3, true)); |
| 206 | providerService.updatePorts(DID1, pds); |
| 207 | validateEvents(PORT_UPDATED, PORT_REMOVED); |
| 208 | } |
| 209 | |
| 210 | @Test |
| 211 | public void updatePortStatus() { |
| 212 | connectDevice(DID1, SW1); |
| 213 | List<PortDescription> pds = new ArrayList<>(); |
| 214 | pds.add(new DefaultPortDescription(P1, true)); |
| 215 | pds.add(new DefaultPortDescription(P2, true)); |
| 216 | providerService.updatePorts(DID1, pds); |
| 217 | validateEvents(DEVICE_ADDED, PORT_ADDED, PORT_ADDED); |
| 218 | |
| 219 | providerService.portStatusChanged(DID1, new DefaultPortDescription(P1, false)); |
| 220 | validateEvents(PORT_UPDATED); |
| 221 | providerService.portStatusChanged(DID1, new DefaultPortDescription(P1, false)); |
| 222 | assertTrue("no events expected", listener.events.isEmpty()); |
| 223 | } |
| 224 | |
| 225 | @Test |
| 226 | public void getPorts() { |
| 227 | connectDevice(DID1, SW1); |
| 228 | List<PortDescription> pds = new ArrayList<>(); |
| 229 | pds.add(new DefaultPortDescription(P1, true)); |
| 230 | pds.add(new DefaultPortDescription(P2, true)); |
| 231 | providerService.updatePorts(DID1, pds); |
| 232 | validateEvents(DEVICE_ADDED, PORT_ADDED, PORT_ADDED); |
| 233 | assertEquals("wrong port count", 2, service.getPorts(DID1).size()); |
| 234 | |
| 235 | Port port = service.getPort(DID1, P1); |
| 236 | assertEquals("incorrect port", P1, service.getPort(DID1, P1).number()); |
| 237 | assertEquals("incorrect state", true, service.getPort(DID1, P1).isEnabled()); |
| 238 | } |
| 239 | |
| 240 | @Test |
| 241 | public void removeDevice() { |
| 242 | connectDevice(DID1, SW1); |
| 243 | connectDevice(DID2, SW2); |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 244 | assertEquals("incorrect device count", 2, service.getDeviceCount()); |
tom | 24c55cd | 2014-09-06 10:47:25 -0700 | [diff] [blame] | 245 | admin.removeDevice(DID1); |
| 246 | assertNull("device should not be found", service.getDevice(DID1)); |
| 247 | assertNotNull("device should be found", service.getDevice(DID2)); |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 248 | assertEquals("incorrect device count", 1, service.getDeviceCount()); |
| 249 | |
tom | 24c55cd | 2014-09-06 10:47:25 -0700 | [diff] [blame] | 250 | } |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 251 | |
| 252 | protected void validateEvents(Enum... types) { |
| 253 | int i = 0; |
| 254 | assertEquals("wrong events received", types.length, listener.events.size()); |
| 255 | for (Event event : listener.events) { |
| 256 | assertEquals("incorrect event type", types[i], event.type()); |
| 257 | i++; |
| 258 | } |
| 259 | listener.events.clear(); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | private class TestProvider extends AbstractProvider implements DeviceProvider { |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 264 | private DeviceId deviceReceived; |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 265 | private MastershipRole roleReceived; |
| 266 | |
| 267 | public TestProvider() { |
| 268 | super(PID); |
| 269 | } |
| 270 | |
| 271 | @Override |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 272 | public void triggerProbe(DeviceId deviceId) { |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 276 | public void roleChanged(DeviceId device, MastershipRole newRole) { |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 277 | deviceReceived = device; |
| 278 | roleReceived = newRole; |
| 279 | } |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 280 | |
| 281 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 282 | public boolean isReachable(DeviceId device) { |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 283 | return false; |
| 284 | } |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | private static class TestListener implements DeviceListener { |
| 288 | final List<DeviceEvent> events = new ArrayList<>(); |
| 289 | |
| 290 | @Override |
| 291 | public void event(DeviceEvent event) { |
| 292 | events.add(event); |
| 293 | } |
| 294 | } |
| 295 | |
Yuta HIGUCHI | bcac499 | 2014-11-22 19:27:57 -0800 | [diff] [blame] | 296 | private static class TestMastershipManager |
| 297 | extends MastershipServiceAdapter implements MastershipTermService { |
Ayaka Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 298 | @Override |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 299 | public MastershipRole getLocalRole(DeviceId deviceId) { |
| 300 | return MastershipRole.MASTER; |
Ayaka Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public Set<DeviceId> getDevicesOf(NodeId nodeId) { |
| 305 | return Sets.newHashSet(DID1, DID2); |
| 306 | } |
| 307 | |
| 308 | @Override |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame^] | 309 | public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) { |
| 310 | return CompletableFuture.completedFuture(MastershipRole.MASTER); |
Ayaka Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 311 | } |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 312 | |
| 313 | @Override |
Yuta HIGUCHI | bcac499 | 2014-11-22 19:27:57 -0800 | [diff] [blame] | 314 | public MastershipTerm getMastershipTerm(DeviceId deviceId) { |
| 315 | // FIXME: just returning something not null |
| 316 | return MastershipTerm.of(NID_LOCAL, 1); |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 317 | } |
Ayaka Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 320 | // code clone |
Ray Milkey | cc53abd | 2015-02-19 12:31:33 -0800 | [diff] [blame] | 321 | private final class TestClusterService extends ClusterServiceAdapter { |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 322 | |
| 323 | ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST); |
| 324 | |
| 325 | @Override |
| 326 | public ControllerNode getLocalNode() { |
| 327 | return local; |
| 328 | } |
| 329 | |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | private final class TestClockProviderService implements |
Yuta HIGUCHI | 093e83e | 2014-10-10 22:26:11 -0700 | [diff] [blame] | 333 | DeviceClockProviderService { |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 334 | |
Yuta HIGUCHI | 13c0b87 | 2014-10-30 18:09:22 -0700 | [diff] [blame] | 335 | private Set<DeviceId> registerdBefore = Sets.newConcurrentHashSet(); |
| 336 | |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 337 | @Override |
| 338 | public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) { |
Yuta HIGUCHI | 13c0b87 | 2014-10-30 18:09:22 -0700 | [diff] [blame] | 339 | registerdBefore.add(deviceId); |
| 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public boolean isTimestampAvailable(DeviceId deviceId) { |
| 344 | return registerdBefore.contains(deviceId); |
Yuta HIGUCHI | 33faeaf | 2014-10-07 18:19:44 -0700 | [diff] [blame] | 345 | } |
| 346 | } |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 347 | } |