Search in sources :

Example 1 with Ports

use of org.folio.okapi.bean.Ports in project okapi by folio-org.

the class DeploymentManagerTest method setUp.

@Before
public void setUp(TestContext context) {
    async = context.async();
    vertx = Vertx.vertx();
    ports = new Ports(9231, 9239);
    em = new EnvManager(new EnvStoreNull());
    ds = new DeploymentStoreNull();
    em.init(vertx, res1 -> {
        dis = new DiscoveryManager(ds);
        dis.init(vertx, res2 -> {
            dm = new DeploymentManager(vertx, dis, em, "myhost.index", ports, 9230, "");
            async.complete();
        });
    });
}
Also used : EnvStoreNull(org.folio.okapi.service.impl.EnvStoreNull) DiscoveryManager(org.folio.okapi.discovery.DiscoveryManager) DeploymentStoreNull(org.folio.okapi.service.impl.DeploymentStoreNull) DeploymentManager(org.folio.okapi.deployment.DeploymentManager) Ports(org.folio.okapi.bean.Ports) EnvManager(org.folio.okapi.env.EnvManager) Before(org.junit.Before)

Example 2 with Ports

use of org.folio.okapi.bean.Ports in project okapi by folio-org.

the class DockerModuleHandleTest method testHostNoExposedPorts.

@Test
public void testHostNoExposedPorts(TestContext context) {
    Vertx vertx = Vertx.vertx();
    LaunchDescriptor ld = new LaunchDescriptor();
    ld.setDockerImage("folioci/mod-users:5.0.0-SNAPSHOT");
    ld.setDockerPull(false);
    Ports ports = new Ports(9232, 9233);
    JsonObject conf = new JsonObject().put("dockerUrl", "tcp://localhost:9231");
    DockerModuleHandle dh = new DockerModuleHandle(vertx, ld, "mod-users-5.0.0-SNAPSHOT", ports, "localhost", 0, /* no exposed port */
    conf);
    dh.start().onComplete(context.asyncAssertFailure(cause -> context.assertEquals("No exposedPorts in image", cause.getMessage())));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) HttpServer(io.vertx.core.http.HttpServer) RunWith(org.junit.runner.RunWith) Router(io.vertx.ext.web.Router) WithAssertions(org.assertj.core.api.WithAssertions) RoutingContext(io.vertx.ext.web.RoutingContext) OkapiLogger(org.folio.okapi.common.OkapiLogger) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) Ports(org.folio.okapi.bean.Ports) DOCKER_REGISTRIES_EMPTY_LIST(org.folio.okapi.service.impl.DockerModuleHandle.DOCKER_REGISTRIES_EMPTY_LIST) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) AdditionalAnswers(org.mockito.AdditionalAnswers) JsonArray(io.vertx.core.json.JsonArray) Mockito(org.mockito.Mockito) Base64(java.util.Base64) Logger(org.apache.logging.log4j.Logger) AnyDescriptor(org.folio.okapi.bean.AnyDescriptor) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Assert(org.junit.Assert) EnvEntry(org.folio.okapi.bean.EnvEntry) HttpClient(io.vertx.core.http.HttpClient) Ports(org.folio.okapi.bean.Ports) JsonObject(io.vertx.core.json.JsonObject) Vertx(io.vertx.core.Vertx) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Test(org.junit.Test)

Example 3 with Ports

use of org.folio.okapi.bean.Ports in project okapi by folio-org.

the class DockerModuleHandleTest method createDockerModuleHandleForMock.

DockerModuleHandle createDockerModuleHandleForMock(Vertx vertx, JsonObject conf) {
    LaunchDescriptor ld = new LaunchDescriptor();
    ld.setDockerImage("folioci/mod-x");
    Ports ports = new Ports(9232, 9233);
    return new DockerModuleHandle(vertx, ld, "mod-x-1.0.0", ports, "localhost", 9232, conf);
}
Also used : Ports(org.folio.okapi.bean.Ports) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor)

Example 4 with Ports

use of org.folio.okapi.bean.Ports in project okapi by folio-org.

the class DockerModuleHandleTest method testDockerVersionAtLocal.

@Test
public void testDockerVersionAtLocal(TestContext context) {
    // native transport = call docker via unix domain socket
    Vertx vertx = Vertx.vertx(new VertxOptions().setPreferNativeTransport(true));
    LaunchDescriptor ld = new LaunchDescriptor();
    ld.setDockerImage("folioci/mod-users:5.0.0-SNAPSHOT");
    JsonObject conf = new JsonObject();
    // tell local Docker to use registry on non-listening port
    conf.put("dockerRegistries", new JsonArray().add(new JsonObject().put("registry", "localhost:9231")));
    Ports ports = new Ports(9232, 9233);
    DockerModuleHandle dh = new DockerModuleHandle(vertx, ld, "mod-users-5.0.0-SNAPSHOT", ports, "localhost", 9232, conf);
    JsonObject versionRes = new JsonObject();
    {
        Async async = context.async();
        dh.getUrl("/version", "getVersion").onComplete(res -> {
            if (res.succeeded()) {
                versionRes.put("result", res.result());
            }
            async.complete();
        });
        async.await();
    }
    Assume.assumeTrue(versionRes.containsKey("result"));
    context.assertTrue(versionRes.getJsonObject("result").containsKey("Version"));
    logger.info("Local docker version {}", versionRes.getJsonObject("result").getString("Version"));
    {
        Async async = context.async();
        // provoke 404 not found
        dh.deleteUrl("/version", "msg").onComplete(context.asyncAssertFailure(cause -> {
            context.assertTrue(cause.getMessage().startsWith("msg HTTP error 404"), cause.getMessage());
            // provoke 404 not found
            dh.postUrlJson("/version", null, "msg", "{}").onComplete(context.asyncAssertFailure(cause2 -> {
                context.assertTrue(cause2.getMessage().startsWith("msg HTTP error 404"), cause2.getMessage());
                async.complete();
            }));
        }));
        async.await();
    }
    {
        Async async = context.async();
        dh.pullImage().onComplete(context.asyncAssertFailure(res -> {
            assertThat(res.getMessage()).contains("9231").contains("connection refused");
            async.complete();
        }));
        async.await();
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) TestContext(io.vertx.ext.unit.TestContext) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) HttpServer(io.vertx.core.http.HttpServer) RunWith(org.junit.runner.RunWith) Router(io.vertx.ext.web.Router) WithAssertions(org.assertj.core.api.WithAssertions) RoutingContext(io.vertx.ext.web.RoutingContext) OkapiLogger(org.folio.okapi.common.OkapiLogger) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) Ports(org.folio.okapi.bean.Ports) DOCKER_REGISTRIES_EMPTY_LIST(org.folio.okapi.service.impl.DockerModuleHandle.DOCKER_REGISTRIES_EMPTY_LIST) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) AdditionalAnswers(org.mockito.AdditionalAnswers) JsonArray(io.vertx.core.json.JsonArray) Mockito(org.mockito.Mockito) Base64(java.util.Base64) Logger(org.apache.logging.log4j.Logger) AnyDescriptor(org.folio.okapi.bean.AnyDescriptor) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Assert(org.junit.Assert) EnvEntry(org.folio.okapi.bean.EnvEntry) HttpClient(io.vertx.core.http.HttpClient) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) Ports(org.folio.okapi.bean.Ports) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Test(org.junit.Test)

Example 5 with Ports

use of org.folio.okapi.bean.Ports in project okapi by folio-org.

the class DockerModuleHandleTest method testNoDockerAtPort.

@Test
public void testNoDockerAtPort(TestContext context) {
    Vertx vertx = Vertx.vertx();
    LaunchDescriptor ld = new LaunchDescriptor();
    ld.setDockerImage("folioci/mod-users:5.0.0-SNAPSHOT");
    ld.setWaitIterations(3);
    Ports ports = new Ports(9232, 9233);
    JsonObject conf = new JsonObject().put("dockerUrl", "tcp://localhost:9231");
    DockerModuleHandle dh = new DockerModuleHandle(vertx, ld, "mod-users-5.0.0-SNAPSHOT", ports, "localhost", 9232, conf);
    dh.start().onComplete(context.asyncAssertFailure(this::assertConnectionRefused));
    dh.stop().onComplete(context.asyncAssertFailure(this::assertConnectionRefused));
    dh.startContainer().onComplete(context.asyncAssertFailure(this::assertConnectionRefused));
    dh.stopContainer().onComplete(context.asyncAssertFailure(this::assertConnectionRefused));
    dh.deleteContainer().onComplete(context.asyncAssertFailure(this::assertConnectionRefused));
}
Also used : Ports(org.folio.okapi.bean.Ports) JsonObject(io.vertx.core.json.JsonObject) Vertx(io.vertx.core.Vertx) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Test(org.junit.Test)

Aggregations

Ports (org.folio.okapi.bean.Ports)8 LaunchDescriptor (org.folio.okapi.bean.LaunchDescriptor)7 JsonObject (io.vertx.core.json.JsonObject)6 Test (org.junit.Test)6 Vertx (io.vertx.core.Vertx)5 Logger (org.apache.logging.log4j.Logger)5 EnvEntry (org.folio.okapi.bean.EnvEntry)5 OkapiLogger (org.folio.okapi.common.OkapiLogger)5 Future (io.vertx.core.Future)4 Async (io.vertx.ext.unit.Async)4 TestContext (io.vertx.ext.unit.TestContext)4 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)4 AnyDescriptor (org.folio.okapi.bean.AnyDescriptor)4 Assume (org.junit.Assume)4 RunWith (org.junit.runner.RunWith)4 VertxOptions (io.vertx.core.VertxOptions)3 HttpClient (io.vertx.core.http.HttpClient)3 HttpMethod (io.vertx.core.http.HttpMethod)3 HttpServer (io.vertx.core.http.HttpServer)3 HttpServerOptions (io.vertx.core.http.HttpServerOptions)3