Skip to content

Commit eea43ed

Browse files
authored
Speed up PostgreSQL builds (#1650)
Backport of #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 3880181 commit eea43ed

22 files changed

+177
-134
lines changed

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

Lines changed: 2 additions & 2 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
@@ -21,7 +21,7 @@
2121
public class PgMetricsTest extends MetricsTestBase {
2222

2323
@ClassRule
24-
public static ContainerPgRule rule = new ContainerPgRule();
24+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
2525

2626
@Override
2727
protected SqlConnectOptions connectOptions() {

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
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.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;
18+
import io.vertx.pgclient.junit.ContainerPgRule;
2219
import org.junit.After;
2320
import org.junit.Before;
2421
import org.junit.ClassRule;
2522
import org.junit.Test;
2623
import org.junit.runner.RunWith;
2724

28-
import io.vertx.core.Vertx;
29-
import io.vertx.ext.unit.Async;
30-
import io.vertx.ext.unit.TestContext;
31-
import io.vertx.ext.unit.junit.VertxUnitRunner;
32-
import io.vertx.pgclient.junit.ContainerPgRule;
25+
import static org.junit.Assume.assumeTrue;
3326

3427
@RunWith(VertxUnitRunner.class)
3528
public class PgScramConnectionTest {
3629

3730
@ClassRule
38-
public static ContainerPgRule rule = new ContainerPgRule();
31+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
3932

4033
private Vertx vertx;
4134

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

Lines changed: 7 additions & 13 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.pgclient;
@@ -37,7 +31,7 @@ public abstract class PgTestBase {
3731
protected static final String ERRCODE_QUERY_CANCELED = "57014";
3832

3933
@ClassRule
40-
public static ContainerPgRule rule = new ContainerPgRule();
34+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
4135

4236
protected PgConnectOptions options;
4337
protected PoolOptions poolOptions;

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

Lines changed: 14 additions & 7 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.pgclient.data;
213

14+
import io.vertx.ext.unit.Async;
15+
import io.vertx.ext.unit.TestContext;
316
import io.vertx.pgclient.PgConnection;
417
import io.vertx.sqlclient.ColumnChecker;
518
import io.vertx.sqlclient.Row;
619
import io.vertx.sqlclient.Tuple;
7-
import io.vertx.ext.unit.Async;
8-
import io.vertx.ext.unit.TestContext;
920
import org.junit.Test;
1021

1122
public class EnumeratedTypesExtendedCodecTest extends ExtendedQueryDataTypeCodecTestBase {
@@ -116,7 +127,7 @@ public void testEncodeEnumArrayMultipleValues(TestContext ctx) {
116127
public void testEncodeEnumArrayEmptyValues(TestContext ctx) {
117128
Async async = ctx.async();
118129
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
119-
conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\", \"Boolean\"",
130+
conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"",
120131
ctx.asyncAssertSuccess(p -> {
121132
p.query().execute(Tuple.tuple()
122133
.addArrayOfString(new String[]{})
@@ -126,10 +137,6 @@ public void testEncodeEnumArrayEmptyValues(TestContext ctx) {
126137
.returns(Tuple::getValue, Row::getValue, new String[]{})
127138
.returns(Tuple::getArrayOfStrings, Row::getArrayOfStrings, new String[]{})
128139
.forRow(result.iterator().next());
129-
ColumnChecker.checkColumn(1, "Boolean")
130-
.returns(Tuple::getValue, Row::getValue, new Boolean[]{true})
131-
.returns(Tuple::getArrayOfBooleans, Row::getArrayOfBooleans, new Boolean[]{true})
132-
.forRow(result.iterator().next());
133140
async.complete();
134141
}));
135142
}));

vertx-pg-client/src/test/java/io/vertx/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.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/pgclient/junit/ContainerPgRule.java

Lines changed: 9 additions & 13 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.pgclient.junit;
1812

@@ -38,6 +32,8 @@ public class ContainerPgRule extends ExternalResource {
3832
private static final String tlsConnectionUri = System.getProperty("tls.connection.uri");
3933
private static final String tlsForceConnectionUri = System.getProperty("tls.force.connection.uri");
4034

35+
public static final ContainerPgRule SHARED_INSTANCE = new ContainerPgRule();
36+
4137
private ServerContainer<?> server;
4238
private PgConnectOptions options;
4339
private String databaseVersion;
@@ -174,7 +170,7 @@ public static boolean isAtLeastPg10() {
174170

175171
@Override
176172
protected void after() {
177-
if (!isTestingWithExternalDatabase()) {
173+
if (!isTestingWithExternalDatabase() && this != SHARED_INSTANCE) {
178174
try {
179175
stopServer();
180176
} catch (Exception e) {

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

Lines changed: 2 additions & 2 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
@@ -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/pgclient/tck/PgBinaryDataTypeEncodeTest.java

Lines changed: 2 additions & 2 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
@@ -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/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.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.pgclient.tck;
513

614
import io.vertx.ext.unit.junit.VertxUnitRunner;
715
import io.vertx.pgclient.junit.ContainerPgRule;
816
import io.vertx.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() {

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

Lines changed: 2 additions & 2 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
@@ -23,7 +23,7 @@
2323
@RunWith(VertxUnitRunner.class)
2424
public class PgConnectionAutoRetryTest extends ConnectionAutoRetryTestBase {
2525
@ClassRule
26-
public static ContainerPgRule rule = new ContainerPgRule();
26+
public static final ContainerPgRule rule = ContainerPgRule.SHARED_INSTANCE;
2727

2828
@Override
2929
public void setUp() throws Exception {

0 commit comments

Comments
 (0)