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 and Description
    `MockLeaderElector()`
    `MockLeaderElector(boolean isLeader)`
    `MockLeaderElector(boolean isLeader, String host, int port)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addToLeaderLockQueue()` 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.
    `List<NimbusInfo>` | `getAllNimbuses()` Get list of current nimbus addresses.
    `NimbusInfo` | `getLeader()` Get the current leader’s address.
    `boolean` | `isLeader()` Decide if the caller currently has the leader lock.
    `void` | `prepare(Map<String,Object> conf)` 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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: `ILeaderElector`

      Method guaranteed to be called as part of initialization of leader elector instance.

      Specified by:
        `prepare` in interface `ILeaderElector`
      Parameters:
        `conf` - configuration

    - #### addToLeaderLockQueue

          public void addToLeaderLockQueue()
                                    throws Exception

      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 interface `ILeaderElector`
      Throws:
        `Exception`

    - #### quitElectionFor

          public void quitElectionFor(int delayMs)
                               throws Exception

      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 interface `ILeaderElector`
      Parameters:
        `delayMs` - The delay to wait before re-entering the election
      Throws:
        `Exception`

    - #### isLeader

          public boolean isLeader()
                           throws Exception

      Description copied from interface: `ILeaderElector`

      Decide if the caller currently has the leader lock.

      Specified by:
        `isLeader` in interface `ILeaderElector`
      Returns:
        true if the caller currently has the leader lock.
      Throws:
        `Exception`

    - #### awaitLeadership

          public boolean awaitLeadership(long timeout,
                                         TimeUnit timeUnit)
                                  throws InterruptedException

      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 interface `ILeaderElector`
      Returns:
        true is leadership was acquired, false otherwise
      Throws:
        `InterruptedException`

    - #### getLeader

          public NimbusInfo getLeader()

      Description copied from interface: `ILeaderElector`

      Get the current leader’s address.

      Specified by:
        `getLeader` in interface `ILeaderElector`
      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: `ILeaderElector`

      Get list of current nimbus addresses.

      Specified by:
        `getAllNimbuses` in interface `ILeaderElector`
      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 interface `AutoCloseable`
      Specified by:
        `close` in interface `ILeaderElector`

Copyright © 2019 The Apache Software Foundation. All rights reserved.