You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "quantranhong1999 (via GitHub)" <gi...@apache.org> on 2023/11/01 10:22:00 UTC
[PR] JAMES-2586 Introduce PostgresExtension [james-project]
quantranhong1999 opened a new pull request, #1772:
URL: https://github.com/apache/james-project/pull/1772
resolve https://github.com/linagora/james-project/issues/4894
TODO: replace TestContainer in `PostgresTableManagerTest` to `PostgresExtension`, polish...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on PR #1772:
URL: https://github.com/apache/james-project/pull/1772#issuecomment-1794381500
Green.
Well, I guess I have some CI luck (than somebody else) :p
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on PR #1772:
URL: https://github.com/apache/james-project/pull/1772#issuecomment-1794019317
rebased on top of the latest `PostgresTableManager`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "vttranlina (via GitHub)" <gi...@apache.org>.
vttranlina commented on code in PR #1772:
URL: https://github.com/apache/james-project/pull/1772#discussion_r1379731819
##########
backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java:
##########
@@ -0,0 +1,143 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.backends.postgres;
+
+import java.util.UUID;
+
+import org.apache.james.GuiceModuleTestExtension;
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.containers.output.OutputFrame;
+
+import com.google.inject.Module;
+
+import io.r2dbc.postgresql.PostgresqlConnectionConfiguration;
+import io.r2dbc.postgresql.PostgresqlConnectionFactory;
+import io.r2dbc.spi.Connection;
+import reactor.core.publisher.Mono;
+
+public class PostgresExtension implements GuiceModuleTestExtension {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PostgresExtension.class);
+
+ private static void displayDockerLog(OutputFrame outputFrame) {
+ LOGGER.info(outputFrame.getUtf8String().trim());
+ }
+
+ private final PostgreSQLContainer postgresContainer;
+ private final PostgresModule postgresModule;
+ private PostgresqlConnectionFactory connectionFactory;
+ private PostgresExecutor postgresExecutor;
+ private PostgresTableManager postgresTableManager;
+
+ public PostgresExtension(PostgresModule postgresModule) {
+ this.postgresContainer = new PostgreSQLContainer<>(PostgresFixture.IMAGE)
+ .withDatabaseName(PostgresFixture.Database.DB_NAME)
+ .withUsername(PostgresFixture.Database.DB_USER)
+ .withPassword(PostgresFixture.Database.DB_PASSWORD)
+ .withLogConsumer(PostgresExtension::displayDockerLog)
+ .withCreateContainerCmdModifier(cmd -> cmd.withName("james-postgres-test-" + UUID.randomUUID()));
+
+ this.postgresModule = postgresModule;
+ }
+
+ public PostgresExtension() {
+ this.postgresContainer = new PostgreSQLContainer<>(PostgresFixture.IMAGE)
+ .withDatabaseName(PostgresFixture.Database.DB_NAME)
+ .withUsername(PostgresFixture.Database.DB_USER)
+ .withPassword(PostgresFixture.Database.DB_PASSWORD)
+ .withLogConsumer(PostgresExtension::displayDockerLog)
+ .withCreateContainerCmdModifier(cmd -> cmd.withName("james-postgres-test-" + UUID.randomUUID()));
+
+ this.postgresModule = PostgresModule.EMPTY_MODULE;
+ }
+
+ @Override
+ public void beforeAll(ExtensionContext extensionContext) {
+ if (!postgresContainer.isRunning()) {
+ postgresContainer.start();
+ initPostgresSession();
+ }
+ }
+
+ private void initPostgresSession() {
+ connectionFactory = new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder()
+ .host(getHost())
+ .port(getMappedPort())
+ .username(PostgresFixture.Database.DB_USER)
+ .password(PostgresFixture.Database.DB_PASSWORD)
+ .database(PostgresFixture.Database.DB_NAME)
+ .schema(PostgresFixture.Database.SCHEMA)
+ .build());
+
+ postgresExecutor = new PostgresExecutor(connectionFactory.create()
+ .cast(Connection.class));
+ }
+
+ @Override
+ public void afterAll(ExtensionContext extensionContext) {
+ disposePostgresSession();
+ postgresContainer.stop();
+ }
+
+ private void disposePostgresSession() {
+ postgresExecutor.dispose().block();
+ }
+
+ @Override
+ public void beforeEach(ExtensionContext extensionContext) {
+ initTablesAndIndexes();
+ }
+
+ @Override
+ public void afterEach(ExtensionContext extensionContext) {
+ truncateTablesAndIndexes();
Review Comment:
Should we DROP SCHEMA, and RE-CREATE SCHEMA?
// For table with enable RLS, we need drop POLICY (truncate table and index is not enough for this case)
Code ex:
```java
Flux.usingWhen(postgresExtension.getConnection()
.map(c -> (PostgresqlConnection) c),
connection -> Mono.from(connection.createStatement("DROP SCHEMA " + PostgresFixture.Database.SCHEMA + " CASCADE").execute())
.then(Mono.from(connection.createStatement("CREATE SCHEMA " + PostgresFixture.Database.SCHEMA).execute()))
.flatMap(PostgresqlResult::getRowsUpdated),
Connection::close)
.collectList()
.block();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #1772:
URL: https://github.com/apache/james-project/pull/1772#issuecomment-1797963231
Please rebase
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on PR #1772:
URL: https://github.com/apache/james-project/pull/1772#issuecomment-1788829599
Can we have build time statistics?
- What is the overhead per test?
- What is the overhead per test class ? From what I could see we do not recycle PG containers, and start a new one each time...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "vttranlina (via GitHub)" <gi...@apache.org>.
vttranlina commented on PR #1772:
URL: https://github.com/apache/james-project/pull/1772#issuecomment-1790053790
Could you remove un-used `org.apache.james.backends.postgres.PostgresClusterExtension` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on PR #1772:
URL: https://github.com/apache/james-project/pull/1772#issuecomment-1790312565
> Can we have build time statistics?
Reuse Postgres container across test classes fasten almost x3 the test runtime. Thank for you suggestion.

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael merged PR #1772:
URL: https://github.com/apache/james-project/pull/1772
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-2586 Introduce PostgresExtension [james-project]
Posted by "vttranlina (via GitHub)" <gi...@apache.org>.
vttranlina commented on code in PR #1772:
URL: https://github.com/apache/james-project/pull/1772#discussion_r1379509092
##########
backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java:
##########
@@ -0,0 +1,143 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.backends.postgres;
+
+import java.util.UUID;
+
+import org.apache.james.GuiceModuleTestExtension;
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.containers.output.OutputFrame;
+
+import com.google.inject.Module;
+
+import io.r2dbc.postgresql.PostgresqlConnectionConfiguration;
+import io.r2dbc.postgresql.PostgresqlConnectionFactory;
+import io.r2dbc.spi.Connection;
+import reactor.core.publisher.Mono;
+
+public class PostgresExtension implements GuiceModuleTestExtension {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PostgresExtension.class);
+
+ private static void displayDockerLog(OutputFrame outputFrame) {
+ LOGGER.info(outputFrame.getUtf8String().trim());
+ }
+
+ private final PostgreSQLContainer postgresContainer;
+ private final PostgresModule postgresModule;
+ private PostgresqlConnectionFactory connectionFactory;
+ private PostgresExecutor postgresExecutor;
+ private PostgresTableManager postgresTableManager;
+
+ public PostgresExtension(PostgresModule postgresModule) {
+ this.postgresContainer = new PostgreSQLContainer<>(PostgresFixture.IMAGE)
+ .withDatabaseName(PostgresFixture.Database.DB_NAME)
+ .withUsername(PostgresFixture.Database.DB_USER)
+ .withPassword(PostgresFixture.Database.DB_PASSWORD)
+ .withLogConsumer(PostgresExtension::displayDockerLog)
+ .withCreateContainerCmdModifier(cmd -> cmd.withName("james-postgres-test-" + UUID.randomUUID()));
+
+ this.postgresModule = postgresModule;
+ }
+
+ public PostgresExtension() {
+ this.postgresContainer = new PostgreSQLContainer<>(PostgresFixture.IMAGE)
Review Comment:
Reuse above constructor ? `this(PostgresModule.EMPTY_MODULE);`
##########
backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java:
##########
@@ -0,0 +1,143 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.backends.postgres;
+
+import java.util.UUID;
+
+import org.apache.james.GuiceModuleTestExtension;
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.containers.output.OutputFrame;
+
+import com.google.inject.Module;
+
+import io.r2dbc.postgresql.PostgresqlConnectionConfiguration;
+import io.r2dbc.postgresql.PostgresqlConnectionFactory;
+import io.r2dbc.spi.Connection;
+import reactor.core.publisher.Mono;
+
+public class PostgresExtension implements GuiceModuleTestExtension {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PostgresExtension.class);
+
+ private static void displayDockerLog(OutputFrame outputFrame) {
+ LOGGER.info(outputFrame.getUtf8String().trim());
+ }
+
+ private final PostgreSQLContainer postgresContainer;
+ private final PostgresModule postgresModule;
+ private PostgresqlConnectionFactory connectionFactory;
+ private PostgresExecutor postgresExecutor;
+ private PostgresTableManager postgresTableManager;
+
+ public PostgresExtension(PostgresModule postgresModule) {
+ this.postgresContainer = new PostgreSQLContainer<>(PostgresFixture.IMAGE)
Review Comment:
Can we re-use `PostgresFixture.PG_CONTAINER.get()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org