2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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
8 package org.opendaylight.mdsal.singleton.dom.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertThrows;
14 import static org.mockito.ArgumentMatchers.any;
15 import static org.mockito.ArgumentMatchers.eq;
16 import static org.mockito.Mockito.doNothing;
17 import static org.mockito.Mockito.doReturn;
18 import static org.mockito.Mockito.doThrow;
19 import static org.mockito.Mockito.never;
20 import static org.mockito.Mockito.verify;
21 import static org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange.LOCAL_OWNERSHIP_GRANTED;
22 import static org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange.LOCAL_OWNERSHIP_LOST_NEW_OWNER;
23 import static org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange.REMOTE_OWNERSHIP_CHANGED;
24 import static org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange.REMOTE_OWNERSHIP_LOST_NO_OWNER;
25 import static org.opendaylight.mdsal.singleton.dom.impl.AbstractClusterSingletonServiceProviderImpl.CLOSE_SERVICE_ENTITY_TYPE;
26 import static org.opendaylight.mdsal.singleton.dom.impl.AbstractClusterSingletonServiceProviderImpl.SERVICE_ENTITY_TYPE;
28 import com.google.common.util.concurrent.Futures;
29 import com.google.common.util.concurrent.ListenableFuture;
30 import org.eclipse.jdt.annotation.NonNull;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.Mock;
34 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
35 import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
36 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
37 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
38 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
39 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
40 import org.opendaylight.yangtools.concepts.Registration;
43 * Abstract {@link DOMClusterSingletonServiceProviderImpl} testing substrate.
45 public abstract class AbstractDOMClusterServiceProviderTest {
47 * Base states for AbstractClusterProjectProvider.
49 enum TestClusterSingletonServiceState {
51 * State represents a correct Instantiated process.
55 * State represents a correct call abstract method instantiatingProject.
59 * State represents a correct call abstract method destryingProject.
64 static class TestClusterSingletonService implements ClusterSingletonService {
65 private static final @NonNull ServiceGroupIdentifier SERVICE_ID = ServiceGroupIdentifier.create(SERVICE_NAME);
67 private TestClusterSingletonServiceState serviceState = TestClusterSingletonServiceState.INITIALIZED;
70 public final ServiceGroupIdentifier getIdentifier() {
75 public final void instantiateServiceInstance() {
76 serviceState = TestClusterSingletonServiceState.STARTED;
79 final TestClusterSingletonServiceState getServiceState() {
84 public ListenableFuture<Void> closeServiceInstance() {
85 serviceState = TestClusterSingletonServiceState.DESTROYED;
86 return Futures.immediateFuture(null);
90 static final @NonNull String SERVICE_NAME = "testServiceName";
91 static final @NonNull DOMEntity ENTITY = new DOMEntity(SERVICE_ENTITY_TYPE, SERVICE_NAME);
92 static final @NonNull DOMEntity DOUBLE_ENTITY = new DOMEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_NAME);
95 public DOMEntityOwnershipService mockEos;
97 public Registration mockEntityCandReg;
99 public Registration mockDoubleEntityCandReg;
101 public Registration mockEosEntityListReg;
103 public Registration mockEosDoubleEntityListReg;
105 public DOMClusterSingletonServiceProviderImpl clusterSingletonServiceProvider;
106 public TestClusterSingletonService clusterSingletonService;
107 public TestClusterSingletonService clusterSingletonService2;
110 public void setup() throws CandidateAlreadyRegisteredException {
111 doNothing().when(mockEosEntityListReg).close();
112 doNothing().when(mockEosDoubleEntityListReg).close();
113 doNothing().when(mockEntityCandReg).close();
114 doNothing().when(mockDoubleEntityCandReg).close();
115 doReturn(mockEosEntityListReg).when(mockEos).registerListener(eq(SERVICE_ENTITY_TYPE),
116 any(DOMClusterSingletonServiceProviderImpl.class));
117 doReturn(mockEosDoubleEntityListReg).when(mockEos).registerListener(eq(CLOSE_SERVICE_ENTITY_TYPE),
118 any(DOMClusterSingletonServiceProviderImpl.class));
119 doReturn(mockEntityCandReg).when(mockEos).registerCandidate(ENTITY);
120 doReturn(mockDoubleEntityCandReg).when(mockEos).registerCandidate(DOUBLE_ENTITY);
122 clusterSingletonServiceProvider = new DOMClusterSingletonServiceProviderImpl(mockEos);
123 clusterSingletonServiceProvider.initializeProvider();
124 verify(mockEos).registerListener(SERVICE_ENTITY_TYPE, clusterSingletonServiceProvider);
125 verify(mockEos).registerListener(CLOSE_SERVICE_ENTITY_TYPE, clusterSingletonServiceProvider);
127 clusterSingletonService = instantiateService();
128 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
129 clusterSingletonService2 = instantiateService();
130 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
133 TestClusterSingletonService instantiateService() {
134 return new TestClusterSingletonService();
138 * Test checks NullPointer for null {@link DOMEntityOwnershipService} input value.
141 public void initializationClusterSingletonServiceProviderNullInputTest() {
142 assertThrows(NullPointerException.class, () -> new DOMClusterSingletonServiceProviderImpl(null));
146 * Test GoldPath for close {@link DOMClusterSingletonServiceProviderImpl}.
148 * @throws Exception if the condition does not meet
151 public void closeClusterSingletonServiceProviderTest() throws Exception {
152 verify(mockEos).registerListener(SERVICE_ENTITY_TYPE, clusterSingletonServiceProvider);
153 verify(mockEos).registerListener(CLOSE_SERVICE_ENTITY_TYPE, clusterSingletonServiceProvider);
154 clusterSingletonServiceProvider.close();
155 verify(mockEosEntityListReg).close();
156 verify(mockEosDoubleEntityListReg).close();
160 * Test parser ServiceIdentifier from Entity.
163 public void makeEntityClusterSingletonServiceProviderTest() {
164 final DOMEntity testEntity = clusterSingletonServiceProvider.createEntity(SERVICE_ENTITY_TYPE, SERVICE_NAME);
165 assertEquals(ENTITY, testEntity);
166 final DOMEntity testDbEn = clusterSingletonServiceProvider.createEntity(CLOSE_SERVICE_ENTITY_TYPE,
168 assertEquals(DOUBLE_ENTITY, testDbEn);
172 * Test parser ServiceIdentifier from Entity.
175 public void getIdentifierClusterSingletonServiceProviderTest() {
176 final String entityIdentifier = clusterSingletonServiceProvider.getServiceIdentifierFromEntity(ENTITY);
177 assertEquals(SERVICE_NAME, entityIdentifier);
178 final String doubleEntityId = clusterSingletonServiceProvider.getServiceIdentifierFromEntity(DOUBLE_ENTITY);
179 assertEquals(SERVICE_NAME, doubleEntityId);
183 * Test GoldPath for initialization {@link ClusterSingletonService}.
185 * @throws CandidateAlreadyRegisteredException if the condition does not meet
188 public void initializationClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
189 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
190 .registerClusterSingletonService(clusterSingletonService);
192 verify(mockEos).registerCandidate(ENTITY);
193 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
197 * Test GoldPath for initialization with init ownership result SLAVE {@link ClusterSingletonService}.
199 * @throws CandidateAlreadyRegisteredException if the condition does not meet
202 public void slaveInitClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
203 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
204 .registerClusterSingletonService(clusterSingletonService);
206 verify(mockEos).registerCandidate(ENTITY);
207 clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
208 verify(mockEos, never()).registerCandidate(DOUBLE_ENTITY);
209 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
213 * Test GoldPath for initialization with init ownership result SLAVE, but NO-MASTER {@link ClusterSingletonService}.
215 * @throws CandidateAlreadyRegisteredException if the condition does not meet
218 public void slaveInitNoMasterClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
219 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
220 .registerClusterSingletonService(clusterSingletonService);
222 verify(mockEos).registerCandidate(ENTITY);
223 clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_LOST_NO_OWNER, false);
224 verify(mockEos, never()).registerCandidate(DOUBLE_ENTITY);
225 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
229 * Test GoldPath for initialization with init ownership result MASTER {@link ClusterSingletonService}.
231 * @throws CandidateAlreadyRegisteredException if the condition does not meet
234 public void masterInitClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
235 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
236 .registerClusterSingletonService(clusterSingletonService);
238 verify(mockEos).registerCandidate(ENTITY);
239 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
240 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
241 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
245 * Test GoldPath for initialization with init ownership result MASTER {@link ClusterSingletonService}.
247 * @throws CandidateAlreadyRegisteredException if the condition does not meet
250 public void masterInitSlaveDoubleCandidateClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
251 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
252 .registerClusterSingletonService(clusterSingletonService);
254 verify(mockEos).registerCandidate(ENTITY);
255 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
256 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
257 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
258 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
262 * Test GoldPath for takeLeadership with ownership result MASTER {@link ClusterSingletonService}.
264 * @throws CandidateAlreadyRegisteredException if the condition does not meet
267 public void takeLeadershipClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
268 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
269 .registerClusterSingletonService(clusterSingletonService);
271 verify(mockEos).registerCandidate(ENTITY);
272 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
273 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
274 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
275 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
276 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService.getServiceState());
280 * Test GoldPath for initialization with init ownership result MASTER {@link ClusterSingletonService}.
282 * @throws CandidateAlreadyRegisteredException if the condition does not meet
285 public void masterInitClusterSingletonServiceTwoServicesTest() throws CandidateAlreadyRegisteredException {
286 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
287 .registerClusterSingletonService(clusterSingletonService);
289 verify(mockEos).registerCandidate(ENTITY);
290 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
291 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
292 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
293 final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
294 .registerClusterSingletonService(clusterSingletonService2);
296 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
300 * Test GoldPath for takeLeadership with ownership result MASTER {@link ClusterSingletonService}.
302 * @throws CandidateAlreadyRegisteredException if the condition does not meet
305 public void takeLeadershipClusterSingletonServiceTwoAddDuringWaitPhaseServicesTest()
306 throws CandidateAlreadyRegisteredException {
307 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
308 .registerClusterSingletonService(clusterSingletonService);
310 verify(mockEos).registerCandidate(ENTITY);
311 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
312 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
313 final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
314 .registerClusterSingletonService(clusterSingletonService2);
316 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
317 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
318 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
319 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService.getServiceState());
320 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService2.getServiceState());
324 * Test checks CandidateAlreadyRegisteredException processing in initialization phase.
326 * @throws CandidateAlreadyRegisteredException if the condition does not meet
328 @Test(expected = RuntimeException.class)
329 public void initializationClusterSingletonServiceCandidateAlreadyRegistredTest()
330 throws CandidateAlreadyRegisteredException {
331 doThrow(CandidateAlreadyRegisteredException.class).when(mockEos).registerCandidate(ENTITY);
332 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
333 .registerClusterSingletonService(clusterSingletonService);
338 * Test GoldPath for lostLeadership during tryToTakeLeadership with ownership result MASTER
339 * {@link ClusterSingletonService}.
341 * @throws CandidateAlreadyRegisteredException if the condition does not meet
344 public void lostLeadershipDuringTryToTakeLeadershipClusterSingletonServiceTest()
345 throws CandidateAlreadyRegisteredException {
346 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
347 .registerClusterSingletonService(clusterSingletonService);
349 verify(mockEos).registerCandidate(ENTITY);
350 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
351 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
352 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
353 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_LOST_NEW_OWNER, false);
354 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
355 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
356 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
360 * Test GoldPath for lostLeadership with ownership result MASTER-TO-SLAVE {@link ClusterSingletonService}.
362 * @throws CandidateAlreadyRegisteredException if the condition does not meet
365 public void lostLeadershipClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
366 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
367 .registerClusterSingletonService(clusterSingletonService);
369 verify(mockEos).registerCandidate(ENTITY);
370 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
371 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
372 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
373 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
374 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
375 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
376 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService.getServiceState());
377 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_LOST_NEW_OWNER, false);
378 assertEquals(TestClusterSingletonServiceState.DESTROYED, clusterSingletonService.getServiceState());
382 * Test checks inJeopardy Cluster Node state for Slave Instance.
384 * @throws CandidateAlreadyRegisteredException if the condition does not meet
387 public void inJeopardySlaveTest() throws CandidateAlreadyRegisteredException {
388 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
389 .registerClusterSingletonService(clusterSingletonService);
391 verify(mockEos).registerCandidate(ENTITY);
392 clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
393 verify(mockEos, never()).registerCandidate(DOUBLE_ENTITY);
394 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
395 clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_LOST_NO_OWNER, true);
396 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
397 verify(mockEosEntityListReg, never()).close();
398 verify(mockEosDoubleEntityListReg, never()).close();
399 verify(mockEntityCandReg, never()).close();
400 verify(mockDoubleEntityCandReg, never()).close();
404 * Test GoldPath for takeLeadership with ownership result MASTER {@link ClusterSingletonService}.
406 * @throws CandidateAlreadyRegisteredException if the condition does not meet
409 public void takeLeadershipClusterSingletonServiceTowServicesTest() throws CandidateAlreadyRegisteredException {
410 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
411 .registerClusterSingletonService(clusterSingletonService);
413 verify(mockEos).registerCandidate(ENTITY);
414 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
415 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
416 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
417 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
418 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService.getServiceState());
419 final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
420 .registerClusterSingletonService(clusterSingletonService2);
422 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService2.getServiceState());
426 * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
428 * @throws Exception if the condition does not meet
431 public void closeClusterSingletonServiceRegistrationNoRoleTest() throws Exception {
432 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
433 .registerClusterSingletonService(clusterSingletonService);
435 verify(mockEos).registerCandidate(ENTITY);
436 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
438 verify(mockEosEntityListReg, never()).close();
439 verify(mockEosDoubleEntityListReg, never()).close();
440 verify(mockEntityCandReg).close();
441 verify(mockDoubleEntityCandReg, never()).close();
442 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
446 * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
448 * @throws Exception if the condition does not meet
451 public void closeClusterSingletonServiceRegistrationNoRoleTwoServicesTest() throws Exception {
452 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
453 .registerClusterSingletonService(clusterSingletonService);
455 verify(mockEos).registerCandidate(ENTITY);
456 final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
457 .registerClusterSingletonService(clusterSingletonService2);
459 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
460 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
462 verify(mockEosEntityListReg, never()).close();
463 verify(mockEosDoubleEntityListReg, never()).close();
464 verify(mockEntityCandReg, never()).close();
465 verify(mockDoubleEntityCandReg, never()).close();
466 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
467 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
471 * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
473 * @throws Exception if the condition does not meet
476 public void closeClusterSingletonServiceRegistrationSlaveTest() throws Exception {
477 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
478 .registerClusterSingletonService(clusterSingletonService);
480 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
481 verify(mockEos).registerCandidate(ENTITY);
482 clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
484 verify(mockEosEntityListReg, never()).close();
485 verify(mockEosDoubleEntityListReg, never()).close();
486 verify(mockEntityCandReg).close();
487 verify(mockDoubleEntityCandReg, never()).close();
488 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
492 * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
494 * @throws Exception if the condition does not meet
497 public void closeClusterSingletonServiceRegistrationSlaveTwoServicesTest() throws Exception {
498 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
499 .registerClusterSingletonService(clusterSingletonService);
501 verify(mockEos).registerCandidate(ENTITY);
502 final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
503 .registerClusterSingletonService(clusterSingletonService2);
505 clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
506 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
507 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
509 verify(mockEosEntityListReg, never()).close();
510 verify(mockEosDoubleEntityListReg, never()).close();
511 verify(mockEntityCandReg, never()).close();
512 verify(mockDoubleEntityCandReg, never()).close();
513 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
514 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
518 * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
520 * @throws Exception if the condition does not meet
523 public void closeClusterSingletonServiceRegistrationMasterTwoServicesTest() throws Exception {
524 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
525 .registerClusterSingletonService(clusterSingletonService);
527 final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
528 .registerClusterSingletonService(clusterSingletonService2);
530 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
531 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
532 verify(mockEos).registerCandidate(ENTITY);
533 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
534 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
535 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
536 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService.getServiceState());
537 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService2.getServiceState());
539 verify(mockEosEntityListReg, never()).close();
540 verify(mockEosDoubleEntityListReg, never()).close();
541 verify(mockEntityCandReg, never()).close();
542 verify(mockDoubleEntityCandReg, never()).close();
543 assertEquals(TestClusterSingletonServiceState.DESTROYED, clusterSingletonService.getServiceState());
544 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService2.getServiceState());
548 * Test checks validation Error processing for SLAVE-TO-MASTER entity Candidate role change.
550 * @throws Exception if the condition does not meet
553 public void tryToTakeLeaderForClosedServiceRegistrationTest() throws Exception {
554 final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
555 .registerClusterSingletonService(clusterSingletonService);
557 final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
558 .registerClusterSingletonService(clusterSingletonService2);
560 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
561 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
562 verify(mockEos).registerCandidate(ENTITY);
564 clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
565 verify(mockEos).registerCandidate(DOUBLE_ENTITY);
566 clusterSingletonServiceProvider.ownershipChanged(DOUBLE_ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
567 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
568 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService2.getServiceState());
569 verify(mockEosEntityListReg, never()).close();
570 verify(mockEosDoubleEntityListReg, never()).close();
571 verify(mockEntityCandReg, never()).close();
572 verify(mockDoubleEntityCandReg, never()).close();
573 assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
574 assertEquals(TestClusterSingletonServiceState.STARTED, clusterSingletonService2.getServiceState());