2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.singleton.dom.impl;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.never;
14 import static org.mockito.Mockito.verify;
15 import com.google.common.util.concurrent.Futures;
16 import java.util.concurrent.ConcurrentHashMap;
17 import java.util.concurrent.ConcurrentMap;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipChangeState;
24 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipCandidateRegistration;
25 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipChange;
26 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipListener;
27 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipService;
28 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
29 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
30 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
31 import org.opendaylight.mdsal.singleton.dom.impl.ClusterSingletonServiceGroup;
32 import org.opendaylight.mdsal.singleton.dom.impl.ClusterSingletonServiceGroupImpl;
33 import org.opendaylight.mdsal.singleton.dom.impl.util.TestEntity;
34 import org.opendaylight.mdsal.singleton.dom.impl.util.TestInstanceIdentifier;
37 * Testing {@link ClusterSingletonServiceGroupImpl}
39 public class ClusterSingletonServiceGroupImplTest {
41 private static final String SERVICE_ENTITY_TYPE = "org.opendaylight.mdsal.ServiceEntityType";
42 private static final String CLOSE_SERVICE_ENTITY_TYPE = "org.opendaylight.mdsal.AsyncServiceCloseEntityType";
43 private static final String SERVICE_IDENTIFIER = "TestServiceIdent";
44 private static final ServiceGroupIdentifier SERVICE_GROUP_IDENT = ServiceGroupIdentifier.create(SERVICE_IDENTIFIER);
47 private ClusterSingletonService mockClusterSingletonService;
49 private ClusterSingletonService mockClusterSingletonServiceSecond;
51 private GenericEntityOwnershipCandidateRegistration<?, ?> mockEntityCandReg;
53 private GenericEntityOwnershipCandidateRegistration<?, ?> mockCloseEntityCandReg;
55 private GenericEntityOwnershipListener<TestInstanceIdentifier,GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>> mockEosListener;
58 private GenericEntityOwnershipService<TestInstanceIdentifier,TestEntity, GenericEntityOwnershipListener<TestInstanceIdentifier,GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>>> mockEosService;
60 private ClusterSingletonServiceGroupImpl<TestInstanceIdentifier,TestEntity,GenericEntityOwnershipChange<TestInstanceIdentifier,TestEntity>,
61 GenericEntityOwnershipListener<TestInstanceIdentifier, GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>>,
62 GenericEntityOwnershipService<TestInstanceIdentifier, TestEntity, GenericEntityOwnershipListener<TestInstanceIdentifier,
63 GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>>>> singletonServiceGroup;
65 private final TestEntity mainEntity = new TestEntity(SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
66 private final TestEntity closeEntity = new TestEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
67 private final ConcurrentMap<String, ClusterSingletonServiceGroup<?, ?, ?>> map = new ConcurrentHashMap<>();
70 * Initialization functionality for every Tests in this suite
72 * @throws Exception - unexpected exception
75 public void setup() throws Exception {
76 MockitoAnnotations.initMocks(this);
78 doReturn(mockEntityCandReg).when(mockEosService).registerCandidate(mainEntity);
79 doReturn(mockCloseEntityCandReg).when(mockEosService).registerCandidate(closeEntity);
80 doNothing().when(mockEntityCandReg).close();
81 doNothing().when(mockCloseEntityCandReg).close();
82 doNothing().when(mockClusterSingletonService).instantiateServiceInstance();
83 doReturn(Futures.immediateFuture(null)).when(mockClusterSingletonService).closeServiceInstance();
85 doReturn(SERVICE_GROUP_IDENT).when(mockClusterSingletonService).getIdentifier();
86 doReturn(SERVICE_GROUP_IDENT).when(mockClusterSingletonServiceSecond).getIdentifier();
88 singletonServiceGroup = new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, mainEntity, closeEntity, mockEosService, map);
92 * Test NULL ServiceIdent input for new ServiceGroup instance
94 * @throws Exception - unexpected exception
96 @Test(expected = IllegalArgumentException.class)
97 public void instantiationClusterSingletonServiceGroupNullIdentTest() throws Exception {
98 singletonServiceGroup = new ClusterSingletonServiceGroupImpl(null, mainEntity, closeEntity, mockEosService, map);
102 * Test empty ServiceIdent input for new ServiceGroup instance
104 * @throws Exception - unexpected exception
106 @Test(expected = IllegalArgumentException.class)
107 public void instantiationClusterSingletonServiceGroupEmptyIdentTest() throws Exception {
108 singletonServiceGroup = new ClusterSingletonServiceGroupImpl("", mainEntity, closeEntity, mockEosService, map);
112 * Test NULL MainEntity input for new ServiceGroup instance
114 * @throws Exception - unexpected exception
116 @Test(expected = NullPointerException.class)
117 public void instantiationClusterSingletonServiceGroupNullMainEntityTest() throws Exception {
118 singletonServiceGroup = new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, null, closeEntity, mockEosService, map);
122 * Test NULL MainEntity input for new ServiceGroup instance
124 * @throws Exception - unexpected exception
126 @Test(expected = NullPointerException.class)
127 public void instantiationClusterSingletonServiceGroupNullCloseEntityTest() throws Exception {
128 singletonServiceGroup = new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, mainEntity, null, mockEosService, map);
132 * Test NULL MainEntity input for new ServiceGroup instance
134 * @throws Exception - unexpected exception
136 @Test(expected = NullPointerException.class)
137 public void instantiationClusterSingletonServiceGroupNullEOS_Test() throws Exception {
138 singletonServiceGroup = new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, mainEntity, closeEntity, null, map);
142 * Test NULL MainEntity input for new ServiceGroup instance
144 * @throws Exception - unexpected exception
146 @Test(expected = NullPointerException.class)
147 public void instantiationClusterSingletonServiceGroupNullMapRefTest() throws Exception {
148 singletonServiceGroup = new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, mainEntity, closeEntity, mockEosService, null);
152 * Test GoldPath for initialization ServiceGroup
154 * @throws Exception - unexpected exception
157 public void initializationClusterSingletonServiceGroupTest() throws Exception {
158 singletonServiceGroup.initializationClusterSingletonGroup();
159 verify(mockEosService).registerCandidate(mainEntity);
163 * Test GoldPath for NO-TO-SLAVE entity Candidate role change
165 * @throws Exception - unexpected exception
168 public void initializationSlaveTest() throws Exception {
169 singletonServiceGroup.initializationClusterSingletonGroup();
170 verify(mockEosService).registerCandidate(mainEntity);
171 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
172 .registerService(mockClusterSingletonService);
173 Assert.assertNotNull(reg);
174 singletonServiceGroup.ownershipChanged(getEntityToSlave());
175 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
176 verify(mockEosService, never()).registerCandidate(closeEntity);
180 * Test GoldPath for NO-TO-SLAVE but without MASTER entity Candidate role change
182 * @throws Exception - unexpected exception
185 public void initializationNoMasterTest() throws Exception {
186 singletonServiceGroup.initializationClusterSingletonGroup();
187 verify(mockEosService).registerCandidate(mainEntity);
188 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
189 .registerService(mockClusterSingletonService);
190 Assert.assertNotNull(reg);
191 singletonServiceGroup.ownershipChanged(getEntityToSlaveNoMaster());
192 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
193 verify(mockEosService, never()).registerCandidate(closeEntity);
197 * Test GoldPath for InJeopardy entity Candidate role change
199 * @throws Exception - unexpected exception
202 public void initializationInJeopardyTest() throws Exception {
203 singletonServiceGroup.initializationClusterSingletonGroup();
204 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
205 verify(mockEosService).registerCandidate(mainEntity);
206 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
207 .registerService(mockClusterSingletonService);
208 Assert.assertNotNull(reg);
209 singletonServiceGroup.ownershipChanged(getEntityToJeopardy());
210 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
211 Assert.assertNull(serviceGroup);
212 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
213 verify(mockEosService, never()).registerCandidate(closeEntity);
217 * Test GoldPath for registration SingletonService
219 * @throws Exception - unexpected exception
222 public void serviceRegistrationClusterSingletonServiceGroupTest() throws Exception {
223 singletonServiceGroup.initializationClusterSingletonGroup();
224 verify(mockEosService).registerCandidate(mainEntity);
225 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
226 .registerService(mockClusterSingletonService);
227 Assert.assertNotNull(reg);
231 * Test GoldPath for registration SingletonService
233 * @throws Exception - unexpected exception
236 public void serviceRegistrationClusterSingletonServiceGroupTwoServiceTest() throws Exception {
237 singletonServiceGroup.initializationClusterSingletonGroup();
238 verify(mockEosService).registerCandidate(mainEntity);
239 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
240 .registerService(mockClusterSingletonService);
241 Assert.assertNotNull(reg);
242 final ClusterSingletonServiceRegistration reg2 = singletonServiceGroup
243 .registerService(mockClusterSingletonServiceSecond);
244 Assert.assertNotNull(reg2);
248 * Test GoldPath for unregistration SingletonService don't call closeServiceInstance
249 * without mastership and don't remove ServiceGroup from map
251 * @throws Exception - unexpected exception
254 public void serviceUnregistrationClusterSingletonServiceGroupTest() throws Exception {
255 singletonServiceGroup.initializationClusterSingletonGroup();
256 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
257 verify(mockEosService).registerCandidate(mainEntity);
258 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
259 .registerService(mockClusterSingletonService);
260 Assert.assertNotNull(reg);
262 verify(mockClusterSingletonService, never()).closeServiceInstance();
263 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
264 Assert.assertNull(serviceGroup);
268 * Test GoldPath for unregistration SingletonService don't call closeServiceInstance
269 * without mastership and don't remove ServiceGroup from map
271 * @throws Exception - unexpected exception
274 public void serviceUnregistrationClusterSingletonServiceGroupTwoServicesTest() throws Exception {
275 singletonServiceGroup.initializationClusterSingletonGroup();
276 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
277 verify(mockEosService).registerCandidate(mainEntity);
278 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
279 .registerService(mockClusterSingletonService);
280 Assert.assertNotNull(reg);
281 final ClusterSingletonServiceRegistration reg2 = singletonServiceGroup
282 .registerService(mockClusterSingletonServiceSecond);
283 Assert.assertNotNull(reg2);
285 verify(mockClusterSingletonService, never()).closeServiceInstance();
286 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
287 Assert.assertNotNull(serviceGroup);
291 * Test GoldPath get Slave role for registered main entity
293 * @throws Exception - unexpected exception
296 public void getSlaveClusterSingletonServiceGroupTest() throws Exception {
297 singletonServiceGroup.initializationClusterSingletonGroup();
298 verify(mockEosService).registerCandidate(mainEntity);
299 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
300 .registerService(mockClusterSingletonService);
301 Assert.assertNotNull(reg);
302 singletonServiceGroup.ownershipChanged(getEntityToSlave());
303 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
307 * Test GoldPath get Master role for registered main entity
309 * @throws Exception - unexpected exception
312 public void tryToTakeLeaderClusterSingletonServiceGroupTest() throws Exception {
313 singletonServiceGroup.initializationClusterSingletonGroup();
314 verify(mockEosService).registerCandidate(mainEntity);
315 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
316 .registerService(mockClusterSingletonService);
317 Assert.assertNotNull(reg);
318 singletonServiceGroup.ownershipChanged(getEntityToMaster());
319 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
320 verify(mockEosService).registerCandidate(closeEntity);
324 * Test GoldPath get Master role for registered close entity
326 * @throws Exception - unexpected exception
329 public void takeMasterClusterSingletonServiceGroupTest() throws Exception {
330 singletonServiceGroup.initializationClusterSingletonGroup();
331 verify(mockEosService).registerCandidate(mainEntity);
332 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
333 .registerService(mockClusterSingletonService);
334 Assert.assertNotNull(reg);
335 singletonServiceGroup.ownershipChanged(getEntityToMaster());
336 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
337 verify(mockEosService).registerCandidate(closeEntity);
338 singletonServiceGroup.ownershipChanged(getDoubleEntityToMaster());
339 verify(mockClusterSingletonService).instantiateServiceInstance();
343 * Test GoldPath get Master role for registered entity but initial Slave
344 * role for closeEntity
346 * @throws Exception - unexpected exception
349 public void waitToTakeMasterClusterSingletonServiceGroupTest() throws Exception {
350 singletonServiceGroup.initializationClusterSingletonGroup();
351 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
352 verify(mockEosService).registerCandidate(mainEntity);
353 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
354 .registerService(mockClusterSingletonService);
355 Assert.assertNotNull(reg);
356 singletonServiceGroup.ownershipChanged(getEntityToMaster());
357 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
358 verify(mockEosService).registerCandidate(closeEntity);
359 singletonServiceGroup.ownershipChanged(getInitDoubleEntityToSlave());
360 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
361 verify(mockClusterSingletonService, never()).closeServiceInstance();
362 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
363 Assert.assertNotNull(serviceGroup);
367 * Test inJeopardy validation during wait phase for Master role for closeEntity
369 * @throws Exception - unexpected exception
372 public void inJeopardyInWaitPhaseClusterSingletonServiceGroupTest() throws Exception {
373 singletonServiceGroup.initializationClusterSingletonGroup();
374 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
375 verify(mockEosService).registerCandidate(mainEntity);
376 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
377 .registerService(mockClusterSingletonService);
378 Assert.assertNotNull(reg);
379 singletonServiceGroup.ownershipChanged(getEntityToMaster());
380 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
381 verify(mockEosService).registerCandidate(closeEntity);
382 singletonServiceGroup.ownershipChanged(getEntityToJeopardy());
383 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
384 verify(mockClusterSingletonService, never()).closeServiceInstance();
385 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
386 Assert.assertNull(serviceGroup);
390 * Test inJeopardy validation during wait phase for Master role for closeEntity
392 * @throws Exception - unexpected exception
395 public void inJeopardyInWaitPhaseClusterSingletonServiceGroupTwoServiceTest() throws Exception {
396 singletonServiceGroup.initializationClusterSingletonGroup();
397 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
398 verify(mockEosService).registerCandidate(mainEntity);
399 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
400 .registerService(mockClusterSingletonService);
401 Assert.assertNotNull(reg);
402 final ClusterSingletonServiceRegistration reg2 = singletonServiceGroup
403 .registerService(mockClusterSingletonServiceSecond);
404 Assert.assertNotNull(reg2);
405 singletonServiceGroup.ownershipChanged(getEntityToMaster());
406 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
407 verify(mockEosService).registerCandidate(closeEntity);
408 singletonServiceGroup.ownershipChanged(getEntityToJeopardy());
409 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
410 verify(mockClusterSingletonService, never()).closeServiceInstance();
411 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
412 Assert.assertNull(serviceGroup);
416 * Test inJeopardy validation for holding leadership
418 * @throws Exception - unexpected exception
421 public void inJeopardyLeaderClusterSingletonServiceGroupTest() throws Exception {
422 singletonServiceGroup.initializationClusterSingletonGroup();
423 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
424 verify(mockEosService).registerCandidate(mainEntity);
425 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
426 .registerService(mockClusterSingletonService);
427 Assert.assertNotNull(reg);
428 singletonServiceGroup.ownershipChanged(getEntityToMaster());
429 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
430 verify(mockEosService).registerCandidate(closeEntity);
431 singletonServiceGroup.ownershipChanged(getDoubleEntityToMaster());
432 verify(mockClusterSingletonService).instantiateServiceInstance();
433 singletonServiceGroup.ownershipChanged(getEntityToJeopardy());
434 verify(mockClusterSingletonService).closeServiceInstance();
435 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
436 Assert.assertNull(serviceGroup);
440 * Test GoldPath for SLAVE-TO-MASTER entity Candidate role change
442 * @throws Exception - unexpected exception
445 public void lostLeaderClusterSingletonServiceGroupTest() throws Exception {
446 singletonServiceGroup.initializationClusterSingletonGroup();
447 verify(mockEosService).registerCandidate(mainEntity);
448 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
449 .registerService(mockClusterSingletonService);
450 Assert.assertNotNull(reg);
451 singletonServiceGroup.ownershipChanged(getEntityToMaster());
452 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
453 verify(mockEosService).registerCandidate(closeEntity);
454 singletonServiceGroup.ownershipChanged(getDoubleEntityToMaster());
455 verify(mockClusterSingletonService).instantiateServiceInstance();
456 singletonServiceGroup.ownershipChanged(getEntityToSlave());
457 verify(mockClusterSingletonService).closeServiceInstance();
461 * Test checks validation Error processing for SLAVE-TO-MASTER entity Candidate role change.
462 * Not initialized provider has to close and remove all singletonServices from Group and
463 * Group itself remove too.
465 * @throws Exception - unexpected exception
468 public void tryToTakeLeaderForNotInitializedGroupTest() throws Exception {
469 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
470 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
471 .registerService(mockClusterSingletonService);
472 Assert.assertNull(reg);
473 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
474 Assert.assertNull(serviceGroup);
478 * Test checks closing procesing for close {@link ClusterSingletonServiceRegistration}
480 * @throws Exception - unexpected exception
483 public void checkClosingRegistrationTest() throws Exception {
484 singletonServiceGroup.initializationClusterSingletonGroup();
485 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
486 verify(mockEosService).registerCandidate(mainEntity);
487 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
488 .registerService(mockClusterSingletonService);
489 Assert.assertNotNull(reg);
490 singletonServiceGroup.ownershipChanged(getEntityToMaster());
491 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
492 verify(mockEosService).registerCandidate(closeEntity);
493 singletonServiceGroup.ownershipChanged(getDoubleEntityToMaster());
494 verify(mockClusterSingletonService).instantiateServiceInstance();
496 verify(mockClusterSingletonService).closeServiceInstance();
500 * Test checks validation Error processing for MASTER-TO-SLAVE closeEntity Candidate role change
502 * @throws Exception - unexpected exception
505 public void checkClosingUnexpectedDoubleEntityForMasterOwnershipChangeRegistrationTest() throws Exception {
506 singletonServiceGroup.initializationClusterSingletonGroup();
507 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
508 verify(mockEosService).registerCandidate(mainEntity);
509 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
510 .registerService(mockClusterSingletonService);
511 Assert.assertNotNull(reg);
512 singletonServiceGroup.ownershipChanged(getEntityToMaster());
513 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
514 verify(mockEosService).registerCandidate(closeEntity);
515 singletonServiceGroup.ownershipChanged(getDoubleEntityToMaster());
516 verify(mockClusterSingletonService).instantiateServiceInstance();
517 singletonServiceGroup.ownershipChanged(getDoubleEntityToSlave());
518 verify(mockClusterSingletonService).closeServiceInstance();
519 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
520 Assert.assertNull(serviceGroup);
524 * Test checks validation Error processing for MASTER-TO-SLAVE closeEntity Candidate role change
525 * without closeEntity registration
527 * @throws Exception - unexpected exception
530 public void checkClosingUnexpectedDoubleEntityForSlaveOwnershipChangeRegistrationTest() throws Exception {
531 singletonServiceGroup.initializationClusterSingletonGroup();
532 map.putIfAbsent(SERVICE_IDENTIFIER, singletonServiceGroup);
533 verify(mockEosService).registerCandidate(mainEntity);
534 final ClusterSingletonServiceRegistration reg = singletonServiceGroup
535 .registerService(mockClusterSingletonService);
536 Assert.assertNotNull(reg);
537 singletonServiceGroup.ownershipChanged(getEntityToSlave());
538 verify(mockClusterSingletonService, never()).instantiateServiceInstance();
539 verify(mockEosService, never()).registerCandidate(closeEntity);
540 singletonServiceGroup.ownershipChanged(getDoubleEntityToSlave());
541 verify(mockClusterSingletonService, never()).closeServiceInstance();
542 final ClusterSingletonServiceGroup<?, ?, ?> serviceGroup = map.get(SERVICE_IDENTIFIER);
543 Assert.assertNull(serviceGroup);
546 private GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity> getEntityToMaster() {
547 return new GenericEntityOwnershipChange<>(mainEntity, EntityOwnershipChangeState.from(false, true, true));
550 private GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity> getEntityToSlave() {
551 return new GenericEntityOwnershipChange<>(mainEntity, EntityOwnershipChangeState.from(true, false, true));
554 private GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity> getEntityToSlaveNoMaster() {
555 return new GenericEntityOwnershipChange<>(mainEntity, EntityOwnershipChangeState.from(true, false, false));
558 private GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity> getDoubleEntityToMaster() {
559 return new GenericEntityOwnershipChange<>(closeEntity, EntityOwnershipChangeState.from(false, true, true));
562 private GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity> getDoubleEntityToSlave() {
563 return new GenericEntityOwnershipChange<>(closeEntity, EntityOwnershipChangeState.from(true, false, true));
566 private GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity> getInitDoubleEntityToSlave() {
567 return new GenericEntityOwnershipChange<>(closeEntity, EntityOwnershipChangeState.from(false, false, true));
570 private GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity> getEntityToJeopardy() {
571 return new GenericEntityOwnershipChange<>(mainEntity, EntityOwnershipChangeState.from(false, false, false), true);