2323import static org .mockito .Mockito .mock ;
2424import static org .mockito .Mockito .never ;
2525import static org .mockito .Mockito .spy ;
26+ import static org .mockito .Mockito .times ;
2627import static org .mockito .Mockito .verify ;
2728import static org .mockito .Mockito .when ;
2829
30+ import java .util .HashSet ;
31+ import java .util .Set ;
32+
2933import org .junit .Before ;
3034import org .junit .Test ;
3135import org .mockito .InOrder ;
3236
37+ import org .apache .geode .distributed .internal .ServerLocation ;
38+
3339public class QueueManagerImplTest {
3440 private final InternalPool pool = mock (InternalPool .class , RETURNS_DEEP_STUBS );
3541 private final Endpoint endpoint = mock (Endpoint .class );
@@ -39,6 +45,9 @@ public class QueueManagerImplTest {
3945 private final ClientUpdater clientUpdater = mock (ClientUpdater .class );
4046 private QueueManagerImpl queueManager ;
4147
48+ private final QueueManagerImpl .ConnectionList queueConnections = mock (
49+ QueueManagerImpl .ConnectionList .class );
50+
4251 @ Before
4352 public void setup () {
4453 queueManager = new QueueManagerImpl (pool , null , null , null , 1 , 1 , null , null );
@@ -53,6 +62,34 @@ public void setup() {
5362 when (backupEndpoint .isClosed ()).thenReturn (false );
5463 }
5564
65+ @ Test
66+ public void whenPrimaryIsNotDestroyedThenPrimaryRecoveryIsNotNeeded () {
67+ assertThat (queueManager .addToConnectionList ((primary ), true )).isTrue ();
68+ when (primary .isDestroyed ()).thenReturn (false );
69+ when (pool .getPoolOrCacheCancelInProgress ()).thenReturn (null );
70+ Set <ServerLocation > excludedServers = new HashSet <>();
71+ queueManager .recoverPrimary (excludedServers );
72+ verify (pool , times (2 )).getPoolOrCacheCancelInProgress ();
73+ }
74+
75+ @ Test
76+ public void whenPrimaryIsNullThenPrimaryRecoveryIsNeeded () {
77+ assertThat (QueueManagerImpl .isPrimaryRecoveryNeeded (null )).isTrue ();
78+ }
79+
80+ @ Test
81+ public void whenConnectionListIsNullThenPrimaryRecoveryIsNeeded () {
82+ when (queueConnections .getPrimary ()).thenReturn (null );
83+ assertThat (QueueManagerImpl .isPrimaryRecoveryNeeded (queueConnections )).isTrue ();
84+ }
85+
86+ @ Test
87+ public void whenPrimaryIsDestroyedThenPrimaryRecoveryIsNeeded () {
88+ when (queueConnections .getPrimary ()).thenReturn (primary );
89+ when (primary .isDestroyed ()).thenReturn (true );
90+ assertThat (QueueManagerImpl .isPrimaryRecoveryNeeded (queueConnections )).isTrue ();
91+ }
92+
5693 @ Test
5794 public void addNoClientUpdaterConnectionToConnectionListReturnsFalse () {
5895 when (primary .getUpdater ()).thenReturn (null );
0 commit comments