use of akka.http.javadsl.Http in project mantis by Netflix.
the class JobRouteTest method testJobStatus.
@Test(dependsOnMethods = { "testJobClusterScaleStage" })
public void testJobStatus() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.POST(String.format("http://127.0.0.1:%d/api/postjobstatus", targetEndpointPort)).withMethod(HttpMethods.POST).withEntity(ContentTypes.create(MediaTypes.TEXT_PLAIN, HttpCharsets.ISO_8859_1), JobPayloads.JOB_STATUS));
responseFuture.thenCompose(r -> processRespFutWithoutHeadersCheck(r, Optional.of(200))).whenComplete((r, t) -> {
String responseMessage = getResponseMessage(r, t);
logger.info("got response '{}'", responseMessage);
assertEquals("forwarded worker status", responseMessage);
latch.countDown();
});
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of akka.http.javadsl.Http in project mantis by Netflix.
the class JobDiscoveryStreamRouteTest method setup.
@BeforeClass
public 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);
final LifecycleEventPublisher lifecycleEventPublisher = new LifecycleEventPublisherImpl(new AuditEventSubscriberLoggingImpl(), new StatusEventSubscriberLoggingImpl(), new WorkerEventSubscriberLoggingImpl());
TestHelpers.setupMasterConfig();
ActorRef jobClustersManagerActor = system.actorOf(JobClustersManagerActor.props(new MantisJobStore(new io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider(true)), lifecycleEventPublisher), "jobClustersManager");
MantisScheduler fakeScheduler = new FakeMantisScheduler(jobClustersManagerActor);
jobClustersManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(fakeScheduler, false), ActorRef.noSender());
agentsErrorMonitorActor.tell(new AgentsErrorMonitorActor.InitializeAgentsErrorMonitor(fakeScheduler), ActorRef.noSender());
Duration idleTimeout = system.settings().config().getDuration("akka.http.server.idle-timeout");
logger.info("idle timeout {} sec ", idleTimeout.getSeconds());
final JobDiscoveryRouteHandler jobDiscoveryRouteHandler = new JobDiscoveryRouteHandlerAkkaImpl(jobClustersManagerActor, idleTimeout);
final JobDiscoveryStreamRoute jobDiscoveryRoute = new JobDiscoveryStreamRoute(jobDiscoveryRouteHandler);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = jobDiscoveryRoute.createRoute(Function.identity()).flow(system, materializer);
logger.info("starting test server on port {}", SERVER_PORT);
binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", SERVER_PORT), materializer);
latch.countDown();
} catch (Exception e) {
logger.info("caught exception", e);
latch.countDown();
e.printStackTrace();
}
});
t.setDaemon(true);
t.start();
latch.await();
}
use of akka.http.javadsl.Http 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();
}
use of akka.http.javadsl.Http in project mantis by Netflix.
the class LeaderRedirectionRouteTest method testMasterInfoAPIWhenNotLeader.
@Test(dependsOnMethods = { "testMasterInfoAPIWhenLeader" })
public void testMasterInfoAPIWhenNotLeader() throws InterruptedException {
leadershipMgr.stopBeingLeader();
final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(masterEndpoint("masterinfo")));
try {
responseFuture.thenCompose(r -> {
logger.info("headers {} {}", r.getHeaders(), r.status());
assertEquals(302, r.status().intValue());
assert (r.getHeader("Access-Control-Allow-Origin").isPresent());
assertEquals("*", r.getHeader("Access-Control-Allow-Origin").get().value());
assert (r.getHeader("Location").isPresent());
assertEquals("http://example.com:" + targetEndpointPort + "/api/masterinfo", r.getHeader("Location").get().value());
CompletionStage<HttpEntity.Strict> strictEntity = r.entity().toStrict(1000, materializer);
return strictEntity.thenCompose(s -> s.getDataBytes().runFold(ByteString.emptyByteString(), (acc, b) -> acc.concat(b), materializer).thenApply(s2 -> s2.utf8String()));
}).whenComplete((msg, t) -> {
try {
String responseMessage = getResponseMessage(msg, t);
logger.info("got response {}", responseMessage);
} catch (Exception e) {
fail("unexpected error " + e.getMessage());
}
}).toCompletableFuture().get(2, TimeUnit.SECONDS);
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (TimeoutException e) {
throw new RuntimeException(e);
}
leadershipMgr.becomeLeader();
testMasterInfoAPIWhenLeader();
}
use of akka.http.javadsl.Http in project mantis by Netflix.
the class MasterDescriptionRouteTest 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);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = masterDescRoute.createRoute(Function.identity()).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