use of io.mantisrx.server.master.LeaderRedirectionFilter 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);
}
use of io.mantisrx.server.master.LeaderRedirectionFilter in project mantis by Netflix.
the class LeaderRedirectionRouteTest method setup.
@BeforeClass
public static void setup() throws Exception {
JobTestHelper.deleteAllFiles();
JobTestHelper.createDirsIfRequired();
final CountDownLatch latch = new CountDownLatch(1);
t = new Thread(() -> {
try {
// boot up server using the route as defined below
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
TestHelpers.setupMasterConfig();
final MasterDescriptionRoute app = new MasterDescriptionRoute(fakeMasterDesc);
final LeaderRedirectionFilter leaderRedirectionFilter = new LeaderRedirectionFilter(masterMonitor, leadershipMgr);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(leaderRedirectionFilter::redirectIfNotLeader).flow(system, materializer);
logger.info("starting test server on port {}", serverPort);
latch.countDown();
binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", serverPort), materializer);
} catch (Exception e) {
logger.info("caught exception", e);
latch.countDown();
e.printStackTrace();
}
});
t.setDaemon(true);
t.start();
latch.await();
}
Aggregations