From 2eae565954773ce06baeeb335a680f6ad69184a1 Mon Sep 17 00:00:00 2001 From: jbahire Date: Wed, 21 Apr 2021 14:20:11 +0530 Subject: [PATCH 1/7] chore: use testcontainers for integration test --- entity-service/build.gradle.kts | 40 +++++-------------- .../EntityDataServiceRelationshipsTest.java | 37 +++++++++++++++-- .../service/EntityDataServiceTest.java | 27 +++++++++++-- .../service/EntityQueryServiceTest.java | 34 ++++++++++++++-- .../service/EntityTypeServiceTest.java | 29 ++++++++++++-- .../service/v2/EntityTypeServiceTest.java | 27 ++++++++++++- .../configs/entity-service/application.conf | 2 + 7 files changed, 150 insertions(+), 46 deletions(-) diff --git a/entity-service/build.gradle.kts b/entity-service/build.gradle.kts index bd8ee17c..8cbc82e5 100644 --- a/entity-service/build.gradle.kts +++ b/entity-service/build.gradle.kts @@ -1,7 +1,3 @@ -import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer -import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer -import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer -import com.bmuschko.gradle.docker.tasks.image.DockerPullImage import com.bmuschko.gradle.docker.tasks.network.DockerCreateNetwork import com.bmuschko.gradle.docker.tasks.network.DockerRemoveNetwork @@ -23,34 +19,8 @@ tasks.register("removeIntegrationTestNetwork") { networkId.set("entity-svc-int-test") } -tasks.register("pullMongoImage") { - image.set("mongo:4.4.0") -} - -tasks.register("createMongoContainer") { - dependsOn("createIntegrationTestNetwork") - dependsOn("pullMongoImage") - targetImageId(tasks.getByName("pullMongoImage").image) - containerName.set("mongo-local") - hostConfig.network.set(tasks.getByName("createIntegrationTestNetwork").networkId) - hostConfig.portBindings.set(listOf("27017:27017")) - hostConfig.autoRemove.set(true) -} - -tasks.register("startMongoContainer") { - dependsOn("createMongoContainer") - targetContainerId(tasks.getByName("createMongoContainer").containerId) -} - -tasks.register("stopMongoContainer") { - targetContainerId(tasks.getByName("createMongoContainer").containerId) - finalizedBy("removeIntegrationTestNetwork") -} - tasks.integrationTest { useJUnitPlatform() - dependsOn("startMongoContainer") - finalizedBy("stopMongoContainer") } dependencies { @@ -82,6 +52,16 @@ dependencies { integrationTestImplementation("org.hypertrace.core.grpcutils:grpc-context-utils:0.4.0") integrationTestImplementation("org.junit.jupiter:junit-jupiter:5.7.1") integrationTestImplementation("org.hypertrace.core.serviceframework:integrationtest-service-framework:0.1.23") + integrationTestImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2") + integrationTestImplementation("org.junit.jupiter:junit-jupiter-params:5.6.2") + integrationTestImplementation("org.junit.jupiter:junit-jupiter-engine:5.6.2") + integrationTestImplementation("org.testcontainers:testcontainers:1.15.2") + integrationTestImplementation("org.testcontainers:junit-jupiter:1.15.2") + integrationTestImplementation("org.testcontainers:testcontainers:1.15.2") + integrationTestImplementation("org.testcontainers:junit-jupiter:1.15.2") + integrationTestImplementation("org.apache.avro:avro:1.10.1") + integrationTestImplementation("org.hypertrace.core.datamodel:data-model:0.1.12") + integrationTestImplementation("com.github.stefanbirkner:system-lambda:1.2.0") } application { diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java index 835f8971..093a7c9c 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java @@ -1,5 +1,7 @@ package org.hypertrace.entity.service.service; +import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; + import io.grpc.Channel; import io.grpc.ClientInterceptors; import io.grpc.ManagedChannelBuilder; @@ -24,17 +26,41 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; /** Test case for testing relationships CRUD with {@link EntityDataServiceClient} */ +@Testcontainers public class EntityDataServiceRelationshipsTest { - private static EntityDataServiceClient entityDataServiceClient; private static final String TENANT_ID = "__testTenant__" + EntityDataServiceTest.class.getSimpleName(); + private static final int CONTAINER_STARTUP_ATTEMPTS = 5; + + private static Network network; + private static GenericContainer mongo; @BeforeAll - public static void setUp() { - IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + public static void setUp() throws Exception { + network = Network.newNetwork(); + + mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo.start(); + + withEnvironmentVariable( + "MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> + IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); + EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); Channel channel = ClientInterceptors.intercept( @@ -43,11 +69,13 @@ public static void setUp() { .build()); entityDataServiceClient = new EntityDataServiceClient(channel); setupEntityTypes(); + + } @AfterAll public static void teardown() { - IntegrationTestServerUtil.shutdownServices(); + mongo.stop(); } private static void setupEntityTypes() { @@ -84,6 +112,7 @@ private static void setupEntityTypes() { .build()); } + @Test public void testCreateAndGetEntityRelationship() { // Create two different relationships. diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java index 6ce57160..5058f2ff 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java @@ -1,5 +1,6 @@ package org.hypertrace.entity.service.service; +import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -60,19 +61,38 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; /** Test case for {@link EntityDataServiceClient} */ public class EntityDataServiceTest { - private static final String TENANT_ID = "__testTenant__" + EntityDataServiceTest.class.getSimpleName(); private static final String TEST_ENTITY_TYPE_V2 = "TEST_ENTITY"; private static EntityDataServiceClient entityDataServiceClient; private static ManagedChannel channel; + private static final int CONTAINER_STARTUP_ATTEMPTS = 5; + private static Network network; + private static GenericContainer mongo; @BeforeAll - public static void setUp() { - IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + public static void setUp() throws Exception { + network = Network.newNetwork(); + mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo.start(); + + withEnvironmentVariable( + "MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> + IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); channel = ManagedChannelBuilder.forAddress(esConfig.getHost(), esConfig.getPort()) @@ -86,6 +106,7 @@ public static void setUp() { public static void teardown() { channel.shutdown(); IntegrationTestServerUtil.shutdownServices(); + mongo.stop(); } private static void setupEntityTypes(Channel channel, String tenant) { diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java index 4df833d0..16e88334 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java @@ -1,5 +1,6 @@ package org.hypertrace.entity.service.service; +import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; import static org.hypertrace.entity.service.constants.EntityCollectionConstants.ENTITY_TYPES_COLLECTION; import static org.hypertrace.entity.service.constants.EntityCollectionConstants.RAW_ENTITIES_COLLECTION; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -54,6 +55,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; /** Test for {@link org.hypertrace.entity.query.service.client.EntityQueryServiceClient} */ public class EntityQueryServiceTest { @@ -74,10 +79,26 @@ public class EntityQueryServiceTest { // attributes defined in application.conf in attribute map private static final String API_DISCOVERY_STATE_ATTR = "API.apiDiscoveryState"; private static final String API_HTTP_METHOD_ATTR = "API.httpMethod"; + private static final int CONTAINER_STARTUP_ATTEMPTS = 5; + private static Network network; + private static GenericContainer mongo; @BeforeAll - public static void setUp() { - IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + public static void setUp() throws Exception { + network = Network.newNetwork(); + mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo.start(); + + withEnvironmentVariable( + "MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> + IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); channel = ClientInterceptors.intercept( @@ -86,6 +107,7 @@ public static void setUp() { .build()); entityQueryServiceClient = new EntityQueryServiceClient(channel); entityDataServiceClient = new EntityDataServiceClient(channel); + datastore = getDatastore(); Map> attributesMap = getAttributesMap(); @@ -96,7 +118,6 @@ public static void setUp() { public void clearCollections() { clearCollection(ENTITY_TYPES_COLLECTION); clearCollection(RAW_ENTITIES_COLLECTION); - setupEntityTypes(channel); } @@ -108,6 +129,7 @@ private static void clearCollection(String collName) { @AfterAll public static void teardown() { IntegrationTestServerUtil.shutdownServices(); + mongo.stop(); } private static void setupEntityTypes(Channel channel) { @@ -541,9 +563,13 @@ private static Datastore getDatastore() { Config config = ConfigFactory.parseResources("configs/entity-service/application.conf"); EntityServiceConfig entityServiceConfig = new EntityServiceConfig(config.getConfig("entity.service.config")); + Map mongoConfig = new HashMap<>(); + mongoConfig.putIfAbsent("host", mongo.getHost()); + mongoConfig.putIfAbsent("port", mongo.getMappedPort(27017).toString()); + Config dataStoreConfig = ConfigFactory.parseMap(mongoConfig); String dataStoreType = entityServiceConfig.getDataStoreType(); return DatastoreProvider.getDatastore( - dataStoreType, entityServiceConfig.getDataStoreConfig(dataStoreType)); + dataStoreType, dataStoreConfig); } private static Map> getAttributesMap() { diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java index c7d4aed7..920af2bb 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java @@ -1,5 +1,7 @@ package org.hypertrace.entity.service.service; +import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; + import io.grpc.Channel; import io.grpc.ClientInterceptors; import io.grpc.ManagedChannelBuilder; @@ -19,18 +21,38 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; /** Integration test for testing {@link EntityTypeServiceClient} */ public class EntityTypeServiceTest { - private static final String TENANT_ID = "__testTenant__" + EntityTypeServiceTest.class.getSimpleName(); private static EntityTypeServiceClient client; + private static final int CONTAINER_STARTUP_ATTEMPTS = 5; + private static Network network; + private static GenericContainer mongo; + @BeforeAll - public static void setUp() { - IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + public static void setUp() throws Exception { + network = Network.newNetwork(); + mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo.start(); + + withEnvironmentVariable( + "MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> + IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); Channel channel = ClientInterceptors.intercept( ManagedChannelBuilder.forAddress( @@ -44,6 +66,7 @@ public static void setUp() { @AfterAll public static void teardown() { IntegrationTestServerUtil.shutdownServices(); + mongo.stop(); } @BeforeEach diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java index 1f05bc14..a2b6f208 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java @@ -1,5 +1,7 @@ package org.hypertrace.entity.type.service.v2; +import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; + import io.grpc.Channel; import io.grpc.ClientInterceptors; import io.grpc.ManagedChannelBuilder; @@ -12,6 +14,10 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; /** Integration test for testing {@link EntityTypeServiceImpl} */ public class EntityTypeServiceTest { @@ -19,10 +25,26 @@ public class EntityTypeServiceTest { "__testTenant__" + EntityTypeServiceTest.class.getSimpleName(); private static EntityTypeServiceClient client; + private static final int CONTAINER_STARTUP_ATTEMPTS = 5; + private static Network network; + private static GenericContainer mongo; @BeforeAll - public static void setUp() { - IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + public static void setUp() throws Exception { + network = Network.newNetwork(); + mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo.start(); + + withEnvironmentVariable( + "MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> + IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); Channel channel = ClientInterceptors.intercept( ManagedChannelBuilder.forAddress( @@ -36,6 +58,7 @@ public static void setUp() { @AfterAll public static void teardown() { IntegrationTestServerUtil.shutdownServices(); + mongo.stop(); } @BeforeEach diff --git a/entity-service/src/integrationTest/resources/configs/entity-service/application.conf b/entity-service/src/integrationTest/resources/configs/entity-service/application.conf index 0adf4aaa..36e4a978 100644 --- a/entity-service/src/integrationTest/resources/configs/entity-service/application.conf +++ b/entity-service/src/integrationTest/resources/configs/entity-service/application.conf @@ -7,7 +7,9 @@ entity.service.config = { dataStoreType = mongo mongo { host = localhost + host = ${?MONGO_HOST} port = 27017 + port = ${?MONGO_PORT} } } } From 76c37906d95fd1970e71c26bbb9bbc0aefe28e9d Mon Sep 17 00:00:00 2001 From: jbahire Date: Wed, 21 Apr 2021 14:34:19 +0530 Subject: [PATCH 2/7] chore: apply spotless --- .../EntityDataServiceRelationshipsTest.java | 24 ++++++++----------- .../service/EntityDataServiceTest.java | 21 ++++++++-------- .../service/EntityQueryServiceTest.java | 24 +++++++++---------- .../service/EntityTypeServiceTest.java | 21 ++++++++-------- .../service/v2/EntityTypeServiceTest.java | 21 ++++++++-------- 5 files changed, 51 insertions(+), 60 deletions(-) diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java index 093a7c9c..647fc825 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java @@ -47,19 +47,18 @@ public class EntityDataServiceRelationshipsTest { public static void setUp() throws Exception { network = Network.newNetwork(); - mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") - .withExposedPorts(27017) - .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo = + new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); mongo.start(); - withEnvironmentVariable( - "MONGO_HOST", mongo.getHost()) - .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> - IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); + withEnvironmentVariable("MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); Channel channel = @@ -69,8 +68,6 @@ public static void setUp() throws Exception { .build()); entityDataServiceClient = new EntityDataServiceClient(channel); setupEntityTypes(); - - } @AfterAll @@ -112,7 +109,6 @@ private static void setupEntityTypes() { .build()); } - @Test public void testCreateAndGetEntityRelationship() { // Create two different relationships. diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java index 5058f2ff..56f5fd30 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java @@ -80,19 +80,18 @@ public class EntityDataServiceTest { @BeforeAll public static void setUp() throws Exception { network = Network.newNetwork(); - mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") - .withExposedPorts(27017) - .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo = + new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); mongo.start(); - withEnvironmentVariable( - "MONGO_HOST", mongo.getHost()) - .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> - IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); + withEnvironmentVariable("MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); channel = ManagedChannelBuilder.forAddress(esConfig.getHost(), esConfig.getPort()) diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java index 16e88334..bc6b1114 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java @@ -86,19 +86,18 @@ public class EntityQueryServiceTest { @BeforeAll public static void setUp() throws Exception { network = Network.newNetwork(); - mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") - .withExposedPorts(27017) - .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo = + new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); mongo.start(); - withEnvironmentVariable( - "MONGO_HOST", mongo.getHost()) - .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> - IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); + withEnvironmentVariable("MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); channel = ClientInterceptors.intercept( @@ -568,8 +567,7 @@ private static Datastore getDatastore() { mongoConfig.putIfAbsent("port", mongo.getMappedPort(27017).toString()); Config dataStoreConfig = ConfigFactory.parseMap(mongoConfig); String dataStoreType = entityServiceConfig.getDataStoreType(); - return DatastoreProvider.getDatastore( - dataStoreType, dataStoreConfig); + return DatastoreProvider.getDatastore(dataStoreType, dataStoreConfig); } private static Map> getAttributesMap() { diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java index 920af2bb..3c9276ae 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java @@ -40,19 +40,18 @@ public class EntityTypeServiceTest { @BeforeAll public static void setUp() throws Exception { network = Network.newNetwork(); - mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") - .withExposedPorts(27017) - .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo = + new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); mongo.start(); - withEnvironmentVariable( - "MONGO_HOST", mongo.getHost()) - .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> - IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); + withEnvironmentVariable("MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); Channel channel = ClientInterceptors.intercept( ManagedChannelBuilder.forAddress( diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java index a2b6f208..50357c1e 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java @@ -32,19 +32,18 @@ public class EntityTypeServiceTest { @BeforeAll public static void setUp() throws Exception { network = Network.newNetwork(); - mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") - .withExposedPorts(27017) - .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + mongo = + new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) + .withNetwork(network) + .withNetworkAliases("mongo") + .withExposedPorts(27017) + .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) + .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); mongo.start(); - withEnvironmentVariable( - "MONGO_HOST", mongo.getHost()) - .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> - IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); + withEnvironmentVariable("MONGO_HOST", mongo.getHost()) + .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) + .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); Channel channel = ClientInterceptors.intercept( ManagedChannelBuilder.forAddress( From 886b4c29b1464ed8fc75373fa5d0a82c8ef2da4a Mon Sep 17 00:00:00 2001 From: rish691 Date: Thu, 20 May 2021 23:42:31 +0530 Subject: [PATCH 3/7] Fix build failure --- .../EntityDataServiceRelationshipsTest.java | 53 ++++++++++--------- .../service/EntityDataServiceTest.java | 26 +++++---- .../service/EntityQueryServiceTest.java | 42 +++++++++------ .../service/EntityTypeServiceTest.java | 40 ++++++++------ .../service/v2/EntityTypeServiceTest.java | 40 ++++++++------ 5 files changed, 118 insertions(+), 83 deletions(-) diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java index 647fc825..bbba97c9 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceRelationshipsTest.java @@ -2,8 +2,8 @@ import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; -import io.grpc.Channel; -import io.grpc.ClientInterceptors; +import com.typesafe.config.ConfigFactory; +import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.ArrayList; import java.util.Collections; @@ -26,64 +26,65 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; /** Test case for testing relationships CRUD with {@link EntityDataServiceClient} */ -@Testcontainers public class EntityDataServiceRelationshipsTest { + + private static final Logger LOG = + LoggerFactory.getLogger(EntityDataServiceRelationshipsTest.class); + private static final Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOG); + private static EntityDataServiceClient entityDataServiceClient; private static final String TENANT_ID = "__testTenant__" + EntityDataServiceTest.class.getSimpleName(); private static final int CONTAINER_STARTUP_ATTEMPTS = 5; - private static Network network; private static GenericContainer mongo; + private static ManagedChannel channel; @BeforeAll public static void setUp() throws Exception { - network = Network.newNetwork(); mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") .withExposedPorts(27017) .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + .waitingFor(Wait.forListeningPort()) + .withLogConsumer(logConsumer); mongo.start(); withEnvironmentVariable("MONGO_HOST", mongo.getHost()) .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); - - EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); - Channel channel = - ClientInterceptors.intercept( - ManagedChannelBuilder.forAddress(esConfig.getHost(), esConfig.getPort()) - .usePlaintext() - .build()); + .execute( + () -> { + ConfigFactory.invalidateCaches(); + IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + }); + EntityServiceClientConfig entityServiceTestConfig = EntityServiceTestConfig.getClientConfig(); + channel = + ManagedChannelBuilder.forAddress( + entityServiceTestConfig.getHost(), entityServiceTestConfig.getPort()) + .usePlaintext() + .build(); + entityDataServiceClient = new EntityDataServiceClient(channel); setupEntityTypes(); } @AfterAll public static void teardown() { + channel.shutdown(); + IntegrationTestServerUtil.shutdownServices(); mongo.stop(); } private static void setupEntityTypes() { - Channel channel = - ClientInterceptors.intercept( - ManagedChannelBuilder.forAddress( - EntityServiceTestConfig.getClientConfig().getHost(), - EntityServiceTestConfig.getClientConfig().getPort()) - .usePlaintext() - .build()); - EntityTypeServiceClient entityTypeServiceClient = new EntityTypeServiceClient(channel); entityTypeServiceClient.upsertEntityType( TENANT_ID, diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java index 56f5fd30..154bab0a 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityDataServiceTest.java @@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; +import com.typesafe.config.ConfigFactory; import io.grpc.Channel; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -61,42 +62,49 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; /** Test case for {@link EntityDataServiceClient} */ public class EntityDataServiceTest { + private static final Logger LOG = LoggerFactory.getLogger(EntityDataServiceTest.class); + private static final Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOG); + private static final String TENANT_ID = "__testTenant__" + EntityDataServiceTest.class.getSimpleName(); private static final String TEST_ENTITY_TYPE_V2 = "TEST_ENTITY"; private static EntityDataServiceClient entityDataServiceClient; private static ManagedChannel channel; private static final int CONTAINER_STARTUP_ATTEMPTS = 5; - private static Network network; private static GenericContainer mongo; @BeforeAll public static void setUp() throws Exception { - network = Network.newNetwork(); mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") .withExposedPorts(27017) .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + .waitingFor(Wait.forListeningPort()) + .withLogConsumer(logConsumer); mongo.start(); withEnvironmentVariable("MONGO_HOST", mongo.getHost()) .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); - EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); + .execute( + () -> { + ConfigFactory.invalidateCaches(); + IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + }); + EntityServiceClientConfig entityServiceTestConfig = EntityServiceTestConfig.getClientConfig(); channel = - ManagedChannelBuilder.forAddress(esConfig.getHost(), esConfig.getPort()) + ManagedChannelBuilder.forAddress("localhost", entityServiceTestConfig.getPort()) .usePlaintext() .build(); + entityDataServiceClient = new EntityDataServiceClient(channel); setupEntityTypes(channel, TENANT_ID); } diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java index bc6b1114..1deb5045 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java @@ -12,7 +12,7 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; import io.grpc.Channel; -import io.grpc.ClientInterceptors; +import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.time.Instant; import java.util.ArrayList; @@ -51,22 +51,28 @@ import org.hypertrace.entity.type.service.v1.AttributeType; import org.hypertrace.entity.v1.entitytype.EntityType; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; /** Test for {@link org.hypertrace.entity.query.service.client.EntityQueryServiceClient} */ public class EntityQueryServiceTest { + + private static final Logger LOG = LoggerFactory.getLogger(EntityQueryServiceTest.class); + private static final Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOG); + private static EntityQueryServiceClient entityQueryServiceClient; // needed to create entities private static EntityDataServiceClient entityDataServiceClient; - private static Channel channel; + private static ManagedChannel channel; private static Datastore datastore; private static final String TENANT_ID = @@ -80,30 +86,32 @@ public class EntityQueryServiceTest { private static final String API_DISCOVERY_STATE_ATTR = "API.apiDiscoveryState"; private static final String API_HTTP_METHOD_ATTR = "API.httpMethod"; private static final int CONTAINER_STARTUP_ATTEMPTS = 5; - private static Network network; private static GenericContainer mongo; @BeforeAll public static void setUp() throws Exception { - network = Network.newNetwork(); mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") .withExposedPorts(27017) .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + .waitingFor(Wait.forListeningPort()) + .withLogConsumer(logConsumer); mongo.start(); withEnvironmentVariable("MONGO_HOST", mongo.getHost()) .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); - EntityServiceClientConfig esConfig = EntityServiceTestConfig.getClientConfig(); + .execute( + () -> { + ConfigFactory.invalidateCaches(); + IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + }); + + EntityServiceClientConfig entityServiceTestConfig = EntityServiceTestConfig.getClientConfig(); channel = - ClientInterceptors.intercept( - ManagedChannelBuilder.forAddress(esConfig.getHost(), esConfig.getPort()) - .usePlaintext() - .build()); + ManagedChannelBuilder.forAddress( + entityServiceTestConfig.getHost(), entityServiceTestConfig.getPort()) + .usePlaintext() + .build(); entityQueryServiceClient = new EntityQueryServiceClient(channel); entityDataServiceClient = new EntityDataServiceClient(channel); @@ -113,7 +121,7 @@ public static void setUp() throws Exception { apiAttributesMap = attributesMap.get(EntityType.API.name()); } - @BeforeEach + @AfterEach public void clearCollections() { clearCollection(ENTITY_TYPES_COLLECTION); clearCollection(RAW_ENTITIES_COLLECTION); @@ -127,6 +135,7 @@ private static void clearCollection(String collName) { @AfterAll public static void teardown() { + channel.shutdown(); IntegrationTestServerUtil.shutdownServices(); mongo.stop(); } @@ -454,6 +463,7 @@ public void testCreateAndGetEntities() { @Nested class TotalEntities { + @Test public void testTotal() { // creating an api entity with attributes diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java index 3c9276ae..c0174e64 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityTypeServiceTest.java @@ -2,11 +2,12 @@ import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; -import io.grpc.Channel; -import io.grpc.ClientInterceptors; +import com.typesafe.config.ConfigFactory; +import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.List; import org.hypertrace.core.serviceframework.IntegrationTestServerUtil; +import org.hypertrace.entity.service.client.config.EntityServiceClientConfig; import org.hypertrace.entity.service.client.config.EntityServiceTestConfig; import org.hypertrace.entity.type.service.client.EntityTypeServiceClient; import org.hypertrace.entity.type.service.v1.AttributeKind; @@ -21,49 +22,56 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; /** Integration test for testing {@link EntityTypeServiceClient} */ public class EntityTypeServiceTest { + private static final Logger LOG = LoggerFactory.getLogger(EntityTypeServiceTest.class); + private static final Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOG); + private static final String TENANT_ID = "__testTenant__" + EntityTypeServiceTest.class.getSimpleName(); private static EntityTypeServiceClient client; private static final int CONTAINER_STARTUP_ATTEMPTS = 5; - private static Network network; private static GenericContainer mongo; + private static ManagedChannel channel; @BeforeAll public static void setUp() throws Exception { - network = Network.newNetwork(); + mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") .withExposedPorts(27017) .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + .waitingFor(Wait.forListeningPort()) + .withLogConsumer(logConsumer); mongo.start(); withEnvironmentVariable("MONGO_HOST", mongo.getHost()) .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); - Channel channel = - ClientInterceptors.intercept( - ManagedChannelBuilder.forAddress( - EntityServiceTestConfig.getClientConfig().getHost(), - EntityServiceTestConfig.getClientConfig().getPort()) - .usePlaintext() - .build()); + .execute( + () -> { + ConfigFactory.invalidateCaches(); + IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + }); + EntityServiceClientConfig entityServiceTestConfig = EntityServiceTestConfig.getClientConfig(); + channel = + ManagedChannelBuilder.forAddress("localhost", entityServiceTestConfig.getPort()) + .usePlaintext() + .build(); client = new EntityTypeServiceClient(channel); } @AfterAll public static void teardown() { + channel.shutdown(); IntegrationTestServerUtil.shutdownServices(); mongo.stop(); } diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java index 50357c1e..3c9e5dfa 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/type/service/v2/EntityTypeServiceTest.java @@ -2,11 +2,12 @@ import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; -import io.grpc.Channel; -import io.grpc.ClientInterceptors; +import com.typesafe.config.ConfigFactory; +import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.List; import org.hypertrace.core.serviceframework.IntegrationTestServerUtil; +import org.hypertrace.entity.service.client.config.EntityServiceClientConfig; import org.hypertrace.entity.service.client.config.EntityServiceTestConfig; import org.hypertrace.entity.type.client.EntityTypeServiceClient; import org.junit.jupiter.api.AfterAll; @@ -14,48 +15,55 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; /** Integration test for testing {@link EntityTypeServiceImpl} */ public class EntityTypeServiceTest { + + private static final Logger LOG = LoggerFactory.getLogger(EntityTypeServiceTest.class); + private static final Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOG); + private static final String TENANT_ID = "__testTenant__" + EntityTypeServiceTest.class.getSimpleName(); private static EntityTypeServiceClient client; private static final int CONTAINER_STARTUP_ATTEMPTS = 5; - private static Network network; private static GenericContainer mongo; + private static ManagedChannel channel; @BeforeAll public static void setUp() throws Exception { - network = Network.newNetwork(); mongo = new GenericContainer<>(DockerImageName.parse("hypertrace/mongodb:main")) - .withNetwork(network) - .withNetworkAliases("mongo") .withExposedPorts(27017) .withStartupAttempts(CONTAINER_STARTUP_ATTEMPTS) - .waitingFor(Wait.forLogMessage(".*waiting for connections on port 27017.*", 1)); + .waitingFor(Wait.forListeningPort()) + .withLogConsumer(logConsumer); mongo.start(); withEnvironmentVariable("MONGO_HOST", mongo.getHost()) .and("MONGO_PORT", mongo.getMappedPort(27017).toString()) - .execute(() -> IntegrationTestServerUtil.startServices(new String[] {"entity-service"})); - Channel channel = - ClientInterceptors.intercept( - ManagedChannelBuilder.forAddress( - EntityServiceTestConfig.getClientConfig().getHost(), - EntityServiceTestConfig.getClientConfig().getPort()) - .usePlaintext() - .build()); + .execute( + () -> { + ConfigFactory.invalidateCaches(); + IntegrationTestServerUtil.startServices(new String[] {"entity-service"}); + }); + EntityServiceClientConfig entityServiceTestConfig = EntityServiceTestConfig.getClientConfig(); + channel = + ManagedChannelBuilder.forAddress("localhost", entityServiceTestConfig.getPort()) + .usePlaintext() + .build(); client = new EntityTypeServiceClient(channel); } @AfterAll public static void teardown() { + channel.shutdown(); IntegrationTestServerUtil.shutdownServices(); mongo.stop(); } From 3449619356542ea487ccf44e94413f7cb10f1b1d Mon Sep 17 00:00:00 2001 From: rish691 Date: Thu, 20 May 2021 23:53:07 +0530 Subject: [PATCH 4/7] . --- .../entity/service/service/EntityQueryServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java index 1deb5045..116a86f7 100644 --- a/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java +++ b/entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java @@ -51,8 +51,8 @@ import org.hypertrace.entity.type.service.v1.AttributeType; import org.hypertrace.entity.v1.entitytype.EntityType; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -121,7 +121,7 @@ public static void setUp() throws Exception { apiAttributesMap = attributesMap.get(EntityType.API.name()); } - @AfterEach + @BeforeEach public void clearCollections() { clearCollection(ENTITY_TYPES_COLLECTION); clearCollection(RAW_ENTITIES_COLLECTION); From 584cd6da8ac22d567f322b2bbf75c73ddfe02078 Mon Sep 17 00:00:00 2001 From: rish691 Date: Fri, 21 May 2021 00:02:41 +0530 Subject: [PATCH 5/7] . --- entity-service/build.gradle.kts | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/entity-service/build.gradle.kts b/entity-service/build.gradle.kts index 8cbc82e5..705f0aa1 100644 --- a/entity-service/build.gradle.kts +++ b/entity-service/build.gradle.kts @@ -1,6 +1,3 @@ -import com.bmuschko.gradle.docker.tasks.network.DockerCreateNetwork -import com.bmuschko.gradle.docker.tasks.network.DockerRemoveNetwork - plugins { java application @@ -11,14 +8,6 @@ plugins { id("org.hypertrace.jacoco-report-plugin") } -tasks.register("createIntegrationTestNetwork") { - networkName.set("entity-svc-int-test") -} - -tasks.register("removeIntegrationTestNetwork") { - networkId.set("entity-svc-int-test") -} - tasks.integrationTest { useJUnitPlatform() } @@ -49,18 +38,14 @@ dependencies { implementation("com.typesafe:config:1.4.1") integrationTestImplementation(project(":entity-service-client")) - integrationTestImplementation("org.hypertrace.core.grpcutils:grpc-context-utils:0.4.0") + integrationTestImplementation("org" + + ".hypertrace.core.grpcutils:grpc-context-utils:0.4.0") integrationTestImplementation("org.junit.jupiter:junit-jupiter:5.7.1") integrationTestImplementation("org.hypertrace.core.serviceframework:integrationtest-service-framework:0.1.23") - integrationTestImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2") - integrationTestImplementation("org.junit.jupiter:junit-jupiter-params:5.6.2") - integrationTestImplementation("org.junit.jupiter:junit-jupiter-engine:5.6.2") - integrationTestImplementation("org.testcontainers:testcontainers:1.15.2") - integrationTestImplementation("org.testcontainers:junit-jupiter:1.15.2") + //integrationTestImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2") + //integrationTestImplementation("org.junit.jupiter:junit-jupiter-params:5.6.2") integrationTestImplementation("org.testcontainers:testcontainers:1.15.2") - integrationTestImplementation("org.testcontainers:junit-jupiter:1.15.2") - integrationTestImplementation("org.apache.avro:avro:1.10.1") - integrationTestImplementation("org.hypertrace.core.datamodel:data-model:0.1.12") + //integrationTestImplementation("org.testcontainers:junit-jupiter:1.15.2") integrationTestImplementation("com.github.stefanbirkner:system-lambda:1.2.0") } @@ -84,4 +69,4 @@ hypertraceDocker { port.set(50061) } } -} +} \ No newline at end of file From a0479e6e4a169d865efcdcf0398fd9b339386c43 Mon Sep 17 00:00:00 2001 From: rish691 Date: Fri, 21 May 2021 00:04:27 +0530 Subject: [PATCH 6/7] . --- entity-service/build.gradle.kts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/entity-service/build.gradle.kts b/entity-service/build.gradle.kts index 705f0aa1..34cc514b 100644 --- a/entity-service/build.gradle.kts +++ b/entity-service/build.gradle.kts @@ -37,15 +37,12 @@ dependencies { // Config implementation("com.typesafe:config:1.4.1") + // integration test integrationTestImplementation(project(":entity-service-client")) - integrationTestImplementation("org" + - ".hypertrace.core.grpcutils:grpc-context-utils:0.4.0") + integrationTestImplementation("org.hypertrace.core.grpcutils:grpc-context-utils:0.4.0") integrationTestImplementation("org.junit.jupiter:junit-jupiter:5.7.1") integrationTestImplementation("org.hypertrace.core.serviceframework:integrationtest-service-framework:0.1.23") - //integrationTestImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2") - //integrationTestImplementation("org.junit.jupiter:junit-jupiter-params:5.6.2") integrationTestImplementation("org.testcontainers:testcontainers:1.15.2") - //integrationTestImplementation("org.testcontainers:junit-jupiter:1.15.2") integrationTestImplementation("com.github.stefanbirkner:system-lambda:1.2.0") } From da55f10df96aeb09d05d75f79ff893faa1c1cbb5 Mon Sep 17 00:00:00 2001 From: rish691 Date: Fri, 21 May 2021 00:05:42 +0530 Subject: [PATCH 7/7] . --- entity-service/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-service/build.gradle.kts b/entity-service/build.gradle.kts index 34cc514b..501a3af2 100644 --- a/entity-service/build.gradle.kts +++ b/entity-service/build.gradle.kts @@ -66,4 +66,4 @@ hypertraceDocker { port.set(50061) } } -} \ No newline at end of file +}