Package org.apache.storm.testing
Class MockLeaderElector
java.lang.Object
org.apache.storm.testing.MockLeaderElector
- All Implemented Interfaces:
AutoCloseable
,ILeaderElector
-
Constructor Summary
ConstructorDescriptionMockLeaderElector
(boolean isLeader) MockLeaderElector
(boolean isLeader, String host, int port) -
Method Summary
Modifier and TypeMethodDescriptionvoid
queue up for leadership lock.boolean
awaitLeadership
(long timeout, TimeUnit timeUnit) Wait for the caller to gain leadership.void
close()
Method called to allow for cleanup.Get list of current nimbus addresses.Get the current leader's address.boolean
isLeader()
Decide if the caller currently has the leader lock.void
Method guaranteed to be called as part of initialization of leader elector instance.void
quitElectionFor
(int delayMs) Removes the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.
-
Constructor Details
-
MockLeaderElector
public MockLeaderElector() -
MockLeaderElector
public MockLeaderElector(boolean isLeader) -
MockLeaderElector
-
-
Method Details
-
prepare
Description copied from interface:ILeaderElector
Method guaranteed to be called as part of initialization of leader elector instance.- Specified by:
prepare
in interfaceILeaderElector
- Parameters:
conf
- configuration
-
addToLeaderLockQueue
Description copied from interface:ILeaderElector
queue up for leadership lock. The call returns immediately and the caller must check isLeader() to perform any leadership action. This method can be called multiple times so it needs to be idempotent.- Specified by:
addToLeaderLockQueue
in interfaceILeaderElector
- Throws:
Exception
-
quitElectionFor
Description copied from interface:ILeaderElector
Removes the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.- Specified by:
quitElectionFor
in interfaceILeaderElector
- Parameters:
delayMs
- The delay to wait before re-entering the election- Throws:
Exception
-
isLeader
Description copied from interface:ILeaderElector
Decide if the caller currently has the leader lock.- Specified by:
isLeader
in interfaceILeaderElector
- Returns:
- true if the caller currently has the leader lock.
- Throws:
Exception
-
awaitLeadership
Description copied from interface:ILeaderElector
Wait for the caller to gain leadership. This should only be used in single-Nimbus clusters, and is only useful to allow testing code to wait for a LocalCluster's Nimbus to gain leadership before trying to submit topologies.- Specified by:
awaitLeadership
in interfaceILeaderElector
- Returns:
- true is leadership was acquired, false otherwise
- Throws:
InterruptedException
-
getLeader
Description copied from interface:ILeaderElector
Get the current leader's address.- Specified by:
getLeader
in interfaceILeaderElector
- Returns:
- the current leader's address, may return null if no one has the lock.
-
getAllNimbuses
Description copied from interface:ILeaderElector
Get list of current nimbus addresses.- Specified by:
getAllNimbuses
in interfaceILeaderElector
- Returns:
- list of current nimbus addresses, includes leader.
- Throws:
Exception
-
close
public void close()Description copied from interface:ILeaderElector
Method called to allow for cleanup. Relinquishes leadership if owned by the caller.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceILeaderElector
-