Search in sources :

Example 6 with LeaderRedirectionFilter

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);
}
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 7 with LeaderRedirectionFilter

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();
}
Also used : MasterDescriptionRoute(io.mantisrx.master.api.akka.route.v0.MasterDescriptionRoute) Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) LeaderRedirectionFilter(io.mantisrx.server.master.LeaderRedirectionFilter) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ActorMaterializer(akka.stream.ActorMaterializer) Flow(akka.stream.javadsl.Flow) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

LeaderRedirectionFilter (io.mantisrx.server.master.LeaderRedirectionFilter)7 LocalMasterMonitor (io.mantisrx.server.core.master.LocalMasterMonitor)5 MasterDescription (io.mantisrx.server.core.master.MasterDescription)5 LeadershipManagerLocalImpl (io.mantisrx.server.master.LeadershipManagerLocalImpl)5 MantisMasterRoute (io.mantisrx.master.api.akka.route.MantisMasterRoute)4 JobClusterRouteHandler (io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandler)4 JobClusterRouteHandlerAkkaImpl (io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandlerAkkaImpl)4 JobDiscoveryRouteHandler (io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandler)4 JobDiscoveryRouteHandlerAkkaImpl (io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandlerAkkaImpl)4 JobRouteHandler (io.mantisrx.master.api.akka.route.handlers.JobRouteHandler)4 JobRouteHandlerAkkaImpl (io.mantisrx.master.api.akka.route.handlers.JobRouteHandlerAkkaImpl)4 JobStatusRouteHandler (io.mantisrx.master.api.akka.route.handlers.JobStatusRouteHandler)4 MasterDescriptionRoute (io.mantisrx.master.api.akka.route.v0.MasterDescriptionRoute)4 ActorRef (akka.actor.ActorRef)3 ConnectHttp (akka.http.javadsl.ConnectHttp)3 Http (akka.http.javadsl.Http)3 ActorMaterializer (akka.stream.ActorMaterializer)3 Flow (akka.stream.javadsl.Flow)3 AgentClusterRoute (io.mantisrx.master.api.akka.route.v0.AgentClusterRoute)3 JobClusterRoute (io.mantisrx.master.api.akka.route.v0.JobClusterRoute)3