Search in sources :

Example 1 with ILeadershipManager

use of io.mantisrx.server.master.ILeadershipManager in project mantis by Netflix.

the class LeaderRedirectionFilterTest method testRouteChangesIfNotLeader.

@Test
public void testRouteChangesIfNotLeader() {
    final MasterDescription fakeMasterDesc = new MasterDescription("localhost", "127.0.0.1", 8100, 8100 + 2, 8100 + 4, "api/postjobstatus", 8100 + 6, System.currentTimeMillis());
    MasterMonitor masterMonitor = new LocalMasterMonitor(fakeMasterDesc);
    ILeadershipManager leadershipManager = new LeadershipManagerLocalImpl(fakeMasterDesc);
    // Stop being leader, the filter should redirect so the returned Route is different from the input Route
    leadershipManager.stopBeingLeader();
    LeaderRedirectionFilter filter = new LeaderRedirectionFilter(masterMonitor, leadershipManager);
    Route testRoute = route(path("test", () -> complete("done")));
    Route route = filter.redirectIfNotLeader(testRoute);
    // filter should return input Route if we are current leader
    assertNotEquals(testRoute, route);
}
Also used : MasterDescription(io.mantisrx.server.core.master.MasterDescription) MasterMonitor(io.mantisrx.server.core.master.MasterMonitor) LocalMasterMonitor(io.mantisrx.server.core.master.LocalMasterMonitor) LocalMasterMonitor(io.mantisrx.server.core.master.LocalMasterMonitor) LeadershipManagerLocalImpl(io.mantisrx.server.master.LeadershipManagerLocalImpl) LeaderRedirectionFilter(io.mantisrx.server.master.LeaderRedirectionFilter) Route(akka.http.javadsl.server.Route) ILeadershipManager(io.mantisrx.server.master.ILeadershipManager) Test(org.junit.Test)

Example 2 with ILeadershipManager

use of io.mantisrx.server.master.ILeadershipManager in project mantis by Netflix.

the class LeaderRedirectionFilterTest method testRouteUnchangedIfLeader.

@Test
public void testRouteUnchangedIfLeader() {
    // Become leader and make Master monitor return the localhost master, filter should return input Route
    final MasterDescription fakeMasterDesc = new MasterDescription("localhost", "127.0.0.1", 8100, 8100 + 2, 8100 + 4, "api/postjobstatus", 8100 + 6, System.currentTimeMillis());
    MasterMonitor masterMonitor = new LocalMasterMonitor(fakeMasterDesc);
    ILeadershipManager leadershipManager = new LeadershipManagerLocalImpl(fakeMasterDesc);
    leadershipManager.becomeLeader();
    LeaderRedirectionFilter filter = new LeaderRedirectionFilter(masterMonitor, leadershipManager);
    Route testRoute = route(path("test", () -> complete("done")));
    Route route = filter.redirectIfNotLeader(testRoute);
    // leader is not ready by default
    assertNotEquals(testRoute, route);
    // mark leader ready
    leadershipManager.setLeaderReady();
    Route route2 = filter.redirectIfNotLeader(testRoute);
    // leader is not ready by default
    assertEquals(testRoute, route2);
}
Also used : MasterDescription(io.mantisrx.server.core.master.MasterDescription) MasterMonitor(io.mantisrx.server.core.master.MasterMonitor) LocalMasterMonitor(io.mantisrx.server.core.master.LocalMasterMonitor) LocalMasterMonitor(io.mantisrx.server.core.master.LocalMasterMonitor) LeadershipManagerLocalImpl(io.mantisrx.server.master.LeadershipManagerLocalImpl) LeaderRedirectionFilter(io.mantisrx.server.master.LeaderRedirectionFilter) Route(akka.http.javadsl.server.Route) ILeadershipManager(io.mantisrx.server.master.ILeadershipManager) Test(org.junit.Test)

Aggregations

Route (akka.http.javadsl.server.Route)2 LocalMasterMonitor (io.mantisrx.server.core.master.LocalMasterMonitor)2 MasterDescription (io.mantisrx.server.core.master.MasterDescription)2 MasterMonitor (io.mantisrx.server.core.master.MasterMonitor)2 ILeadershipManager (io.mantisrx.server.master.ILeadershipManager)2 LeaderRedirectionFilter (io.mantisrx.server.master.LeaderRedirectionFilter)2 LeadershipManagerLocalImpl (io.mantisrx.server.master.LeadershipManagerLocalImpl)2 Test (org.junit.Test)2