Skip to content

Commit 3d0acdc

Browse files
authored
Speed up PostgreSQL builds (#1649)
Create a shared rule instance in ContainerPgRule. This instance is used where we don't need particular customization (SSL, different user, ...etc.). In ContainerPgRule#after method, we skip stopping the server if the method is called on the SHARED instance. Therefore, we avoid starting/stopping the PostgreSQL container before/after each test class. On my box, the builds takes 1-2 minutes instead of 5-6 minutes. This behavior is aligned with MySQL, MSSQL and Oracle clients testing. Also, modified EnumeratedTypesExtendedCodecTest#testEncodeEnumArrayEmptyValues. It checked a column that had nothing to do with enum array. Without this change, we cannot use a shared rule. Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent 5efe7c6 commit 3d0acdc

23 files changed

+190
-150
lines changed

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/PgMetricsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2020 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -12,17 +12,17 @@
1212
package io.vertx.tests.pgclient;
1313

1414
import io.vertx.pgclient.PgBuilder;
15-
import io.vertx.tests.pgclient.junit.ContainerPgRule;
1615
import io.vertx.sqlclient.ClientBuilder;
1716
import io.vertx.sqlclient.Pool;
1817
import io.vertx.sqlclient.SqlConnectOptions;
18+
import io.vertx.tests.pgclient.junit.ContainerPgRule;
1919
import io.vertx.tests.sqlclient.tck.MetricsTestBase;
2020
import org.junit.ClassRule;
2121

2222
public class PgMetricsTest extends MetricsTestBase {
2323

2424
@ClassRule
25-
public static ContainerPgRule rule = new ContainerPgRule();
25+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
2626

2727
@Override
2828
protected SqlConnectOptions connectOptions() {

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/PgScramConnectionTest.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
/*
2-
* Copyright (C) 2017 Julien Viet
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
158
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1610
*/
1711

1812
package io.vertx.tests.pgclient;
1913

20-
import static org.junit.Assume.assumeTrue;
21-
14+
import io.vertx.core.Vertx;
15+
import io.vertx.ext.unit.Async;
16+
import io.vertx.ext.unit.TestContext;
17+
import io.vertx.ext.unit.junit.VertxUnitRunner;
2218
import io.vertx.pgclient.PgConnectOptions;
2319
import io.vertx.pgclient.PgConnection;
20+
import io.vertx.tests.pgclient.junit.ContainerPgRule;
2421
import org.junit.After;
2522
import org.junit.Before;
2623
import org.junit.ClassRule;
2724
import org.junit.Test;
2825
import org.junit.runner.RunWith;
2926

30-
import io.vertx.core.Vertx;
31-
import io.vertx.ext.unit.Async;
32-
import io.vertx.ext.unit.TestContext;
33-
import io.vertx.ext.unit.junit.VertxUnitRunner;
34-
import io.vertx.tests.pgclient.junit.ContainerPgRule;
27+
import static org.junit.Assume.assumeTrue;
3528

3629
@RunWith(VertxUnitRunner.class)
3730
public class PgScramConnectionTest {
3831

3932
@ClassRule
40-
public static ContainerPgRule rule = new ContainerPgRule();
33+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
4134

4235
private Vertx vertx;
4336

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/PgTestBase.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
/*
2-
* Copyright (C) 2017 Julien Viet
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
158
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1610
*/
1711

1812
package io.vertx.tests.pgclient;
@@ -21,9 +15,9 @@
2115
import io.vertx.ext.unit.junit.VertxUnitRunner;
2216
import io.vertx.pgclient.PgConnectOptions;
2317
import io.vertx.pgclient.PgException;
24-
import io.vertx.tests.pgclient.junit.ContainerPgRule;
2518
import io.vertx.sqlclient.PoolOptions;
2619
import io.vertx.sqlclient.SqlClient;
20+
import io.vertx.tests.pgclient.junit.ContainerPgRule;
2721
import org.junit.ClassRule;
2822
import org.junit.runner.RunWith;
2923

@@ -39,7 +33,7 @@ public abstract class PgTestBase {
3933
protected static final String ERRCODE_QUERY_CANCELED = "57014";
4034

4135
@ClassRule
42-
public static ContainerPgRule rule = new ContainerPgRule();
36+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
4337

4438
protected PgConnectOptions options;
4539
protected PoolOptions poolOptions;

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/UnixDomainSocketTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class UnixDomainSocketTest {
3434

3535
@ClassRule
36-
public static ContainerPgRule rule = new ContainerPgRule();
36+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
3737
private Pool client;
3838
private PgConnectOptions options;
3939
private Vertx vertx;

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/data/EnumeratedTypesExtendedCodecTest.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
/*
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
112
package io.vertx.tests.pgclient.data;
213

14+
import io.vertx.ext.unit.Async;
15+
import io.vertx.ext.unit.TestContext;
316
import io.vertx.pgclient.PgConnection;
4-
import io.vertx.tests.sqlclient.ColumnChecker;
517
import io.vertx.sqlclient.Row;
618
import io.vertx.sqlclient.Tuple;
7-
import io.vertx.ext.unit.Async;
8-
import io.vertx.ext.unit.TestContext;
19+
import io.vertx.tests.sqlclient.ColumnChecker;
920
import org.junit.Test;
1021

1122
public class EnumeratedTypesExtendedCodecTest extends ExtendedQueryDataTypeCodecTestBase {
@@ -122,7 +133,7 @@ public void testEncodeEnumArrayEmptyValues(TestContext ctx) {
122133
PgConnection
123134
.connect(vertx, options)
124135
.onComplete(ctx.asyncAssertSuccess(conn -> {
125-
conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\", \"Boolean\"")
136+
conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"")
126137
.onComplete(ctx.asyncAssertSuccess(p -> {
127138
p.query()
128139
.execute(Tuple.tuple().addArrayOfString(new String[]{}).addInteger(2))
@@ -131,10 +142,6 @@ public void testEncodeEnumArrayEmptyValues(TestContext ctx) {
131142
.returns(Tuple::getValue, Row::getValue, new String[]{})
132143
.returns(Tuple::getArrayOfStrings, Row::getArrayOfStrings, new String[]{})
133144
.forRow(result.iterator().next());
134-
ColumnChecker.checkColumn(1, "Boolean")
135-
.returns(Tuple::getValue, Row::getValue, new Boolean[]{true})
136-
.returns(Tuple::getArrayOfBooleans, Row::getArrayOfBooleans, new Boolean[]{true})
137-
.forRow(result.iterator().next());
138145
async.complete();
139146
}));
140147
}));

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/it/MissingScramTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
112
package io.vertx.tests.pgclient.it;
213

314
import io.vertx.core.Vertx;
@@ -19,7 +30,7 @@
1930
public class MissingScramTest {
2031

2132
@ClassRule
22-
public static ContainerPgRule rule = new ContainerPgRule();
33+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
2334

2435
private Vertx vertx;
2536

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/junit/ContainerPgRule.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
/*
2-
* Copyright (C) 2017 Julien Viet
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
158
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1610
*/
1711
package io.vertx.tests.pgclient.junit;
1812

@@ -28,11 +22,8 @@
2822
import java.nio.file.Files;
2923
import java.time.Duration;
3024
import java.time.temporal.ChronoUnit;
31-
import java.util.ArrayList;
32-
import java.util.List;
3325

3426
import static io.vertx.pgclient.PgConnectOptions.DEFAULT_PORT;
35-
import static org.junit.Assert.assertTrue;
3627

3728
/**
3829
* Postgresql test database based on https://www.testcontainers.org
@@ -47,6 +38,8 @@ public class ContainerPgRule extends ExternalResource {
4738
private static final String tlsConnectionUri = System.getProperty("tls.connection.uri");
4839
private static final String tlsForceConnectionUri = System.getProperty("tls.force.connection.uri");
4940

41+
public static final ContainerPgRule SHARED_INSTANCE = new ContainerPgRule();
42+
5043
private ServerContainer<?> server;
5144
private PgConnectOptions options;
5245
private String databaseVersion;
@@ -209,7 +202,7 @@ public static boolean isAtLeastPg10() {
209202

210203
@Override
211204
protected void after() {
212-
if (!isTestingWithExternalDatabase()) {
205+
if (!isTestingWithExternalDatabase() && this != SHARED_INSTANCE) {
213206
try {
214207
stopServer();
215208
} catch (Exception e) {

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/tck/PgBinaryDataTypeDecodeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -12,8 +12,8 @@
1212
package io.vertx.tests.pgclient.tck;
1313

1414
import io.vertx.ext.unit.junit.VertxUnitRunner;
15-
import io.vertx.tests.pgclient.junit.ContainerPgRule;
1615
import io.vertx.sqlclient.data.Numeric;
16+
import io.vertx.tests.pgclient.junit.ContainerPgRule;
1717
import io.vertx.tests.sqlclient.tck.BinaryDataTypeDecodeTestBase;
1818
import org.junit.ClassRule;
1919
import org.junit.runner.RunWith;
@@ -23,7 +23,7 @@
2323
@RunWith(VertxUnitRunner.class)
2424
public class PgBinaryDataTypeDecodeTest extends BinaryDataTypeDecodeTestBase {
2525
@ClassRule
26-
public static ContainerPgRule rule = new ContainerPgRule();
26+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
2727

2828
@Override
2929
protected JDBCType getNumericJDBCType() {

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/tck/PgBinaryDataTypeEncodeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -12,8 +12,8 @@
1212
package io.vertx.tests.pgclient.tck;
1313

1414
import io.vertx.ext.unit.junit.VertxUnitRunner;
15-
import io.vertx.tests.pgclient.junit.ContainerPgRule;
1615
import io.vertx.sqlclient.data.Numeric;
16+
import io.vertx.tests.pgclient.junit.ContainerPgRule;
1717
import io.vertx.tests.sqlclient.tck.BinaryDataTypeEncodeTestBase;
1818
import org.junit.ClassRule;
1919
import org.junit.runner.RunWith;
@@ -23,7 +23,7 @@
2323
@RunWith(VertxUnitRunner.class)
2424
public class PgBinaryDataTypeEncodeTest extends BinaryDataTypeEncodeTestBase {
2525
@ClassRule
26-
public static ContainerPgRule rule = new ContainerPgRule();
26+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
2727

2828
@Override
2929
protected JDBCType getNumericJDBCType() {

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/tck/PgCollectorTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
package io.vertx.tests.pgclient.tck;
1+
/*
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
211

3-
import org.junit.ClassRule;
4-
import org.junit.runner.RunWith;
12+
package io.vertx.tests.pgclient.tck;
513

614
import io.vertx.ext.unit.junit.VertxUnitRunner;
715
import io.vertx.tests.pgclient.junit.ContainerPgRule;
816
import io.vertx.tests.sqlclient.tck.CollectorTestBase;
17+
import org.junit.ClassRule;
18+
import org.junit.runner.RunWith;
919

1020
@RunWith(VertxUnitRunner.class)
1121
public class PgCollectorTest extends CollectorTestBase {
1222
@ClassRule
13-
public static ContainerPgRule rule = new ContainerPgRule();
23+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
1424

1525
@Override
1626
protected void initConnector() {

0 commit comments

Comments
 (0)