Package org.apache.storm.testing
Class MockLeaderElector
- java.lang.Object
-
- org.apache.storm.testing.MockLeaderElector
-
- All Implemented Interfaces:
AutoCloseable,ILeaderElector
public class MockLeaderElector extends Object implements ILeaderElector
-
-
Constructor Summary
Constructors Constructor Description MockLeaderElector()MockLeaderElector(boolean isLeader)MockLeaderElector(boolean isLeader, String host, int port)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToLeaderLockQueue()queue up for leadership lock.booleanawaitLeadership(long timeout, TimeUnit timeUnit)Wait for the caller to gain leadership.voidclose()Method called to allow for cleanup.List<NimbusInfo>getAllNimbuses()Get list of current nimbus addresses.NimbusInfogetLeader()Get the current leader's address.booleanisLeader()Decide if the caller currently has the leader lock.voidprepare(Map<String,Object> conf)Method guaranteed to be called as part of initialization of leader elector instance.voidquitElectionFor(int delayMs)Removes the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.
-
-
-
Constructor Detail
-
MockLeaderElector
public MockLeaderElector()
-
MockLeaderElector
public MockLeaderElector(boolean isLeader)
-
MockLeaderElector
public MockLeaderElector(boolean isLeader, String host, int port)
-
-
Method Detail
-
prepare
public void prepare(Map<String,Object> conf)
Description copied from interface:ILeaderElectorMethod guaranteed to be called as part of initialization of leader elector instance.- Specified by:
preparein interfaceILeaderElector- Parameters:
conf- configuration
-
addToLeaderLockQueue
public void addToLeaderLockQueue() throws ExceptionDescription copied from interface:ILeaderElectorqueue 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:
addToLeaderLockQueuein interfaceILeaderElector- Throws:
Exception
-
quitElectionFor
public void quitElectionFor(int delayMs) throws ExceptionDescription copied from interface:ILeaderElectorRemoves the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.- Specified by:
quitElectionForin interfaceILeaderElector- Parameters:
delayMs- The delay to wait before re-entering the election- Throws:
Exception
-
isLeader
public boolean isLeader() throws ExceptionDescription copied from interface:ILeaderElectorDecide if the caller currently has the leader lock.- Specified by:
isLeaderin interfaceILeaderElector- Returns:
- true if the caller currently has the leader lock.
- Throws:
Exception
-
awaitLeadership
public boolean awaitLeadership(long timeout, TimeUnit timeUnit) throws InterruptedExceptionDescription copied from interface:ILeaderElectorWait 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:
awaitLeadershipin interfaceILeaderElector- Returns:
- true is leadership was acquired, false otherwise
- Throws:
InterruptedException
-
getLeader
public NimbusInfo getLeader()
Description copied from interface:ILeaderElectorGet the current leader's address.- Specified by:
getLeaderin interfaceILeaderElector- Returns:
- the current leader's address, may return null if no one has the lock.
-
getAllNimbuses
public List<NimbusInfo> getAllNimbuses() throws Exception
Description copied from interface:ILeaderElectorGet list of current nimbus addresses.- Specified by:
getAllNimbusesin interfaceILeaderElector- Returns:
- list of current nimbus addresses, includes leader.
- Throws:
Exception
-
close
public void close()
Description copied from interface:ILeaderElectorMethod called to allow for cleanup. Relinquishes leadership if owned by the caller.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceILeaderElector
-
-