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);
}
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);
}
Aggregations