Skip to content

Commit 982badb

Browse files
authored
Create a yaml test config that runs two servers with the same version (#3217)
This PR adds a test configuration that runs two servers of the same version (no embedded in the loop). In order to do this, a slight refactoring of the config structure was done, moving all the `create*ConnectionFactory` into a base class. A new Gradle test config was added so that one can run the new config from the IDE. No automated way to run the config is being introduced (this can be added in the future as needed). Running all the tests (this downloads all recent external servers and runs a single config on each) takes about 4 minutes. This seems OK, but if needed we can reduce the scope to one server only.
1 parent 363a435 commit 982badb

13 files changed

+325
-89
lines changed

gradle/testing.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ task quickTest(type: Test) {
5858
}
5959
}
6060

61+
// Tests that run a single version on multiple external servers
62+
task singleVersionTest(type: Test) {
63+
systemProperties["tests.singleVersion"] = true
64+
useJUnitPlatform {
65+
excludeTags 'WipesFDB'
66+
}
67+
}
68+
6169
def getMixedModeVersion(descriptor) {
6270
while (descriptor != null) {
6371
// don't display this or any of the parents. Let's assume that nobody ever

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
import com.apple.foundationdb.relational.yamltests.configs.CorrectExplainsAndMetrics;
2525
import com.apple.foundationdb.relational.yamltests.configs.CorrectMetrics;
2626
import com.apple.foundationdb.relational.yamltests.configs.EmbeddedConfig;
27+
import com.apple.foundationdb.relational.yamltests.configs.ExternalMultiServerConfig;
2728
import com.apple.foundationdb.relational.yamltests.configs.ForceContinuations;
2829
import com.apple.foundationdb.relational.yamltests.configs.JDBCInProcessConfig;
29-
import com.apple.foundationdb.relational.yamltests.configs.MultiServerConfig;
30+
import com.apple.foundationdb.relational.yamltests.configs.JDBCMultiServerConfig;
3031
import com.apple.foundationdb.relational.yamltests.configs.ShowPlanOnDiff;
3132
import com.apple.foundationdb.relational.yamltests.configs.YamlTestConfig;
3233
import com.apple.foundationdb.relational.yamltests.server.ExternalServer;
@@ -82,19 +83,15 @@ public void beforeAll(final ExtensionContext context) throws Exception {
8283
server.start();
8384
}
8485
final boolean mixedModeOnly = Boolean.parseBoolean(System.getProperty("tests.mixedModeOnly", "false"));
85-
final Stream<YamlTestConfig> localTestingConfigs = mixedModeOnly ?
86-
Stream.of() :
87-
Stream.of(new EmbeddedConfig(), new JDBCInProcessConfig());
86+
final boolean singleExternalVersionOnly = Boolean.parseBoolean(System.getProperty("tests.singleVersion", "false"));
87+
Stream<YamlTestConfig> localTestingConfigs = localConfigs(mixedModeOnly, singleExternalVersionOnly);
88+
Stream<YamlTestConfig> externalServerConfigs = externalServerConfigs(singleExternalVersionOnly);
89+
8890
testConfigs = Stream.concat(
8991
// The configs for local testing (single server)
9092
localTestingConfigs,
91-
// The configs for multi-server testing (4 configs for each server available)
92-
servers.stream().flatMap(server ->
93-
Stream.of(new MultiServerConfig(0, server),
94-
new ForceContinuations(new MultiServerConfig(0, server)),
95-
new MultiServerConfig(1, server),
96-
new ForceContinuations(new MultiServerConfig(1, server)))
97-
)).collect(Collectors.toList());
93+
// The configs for multi-server testing
94+
externalServerConfigs).collect(Collectors.toList());
9895

9996
maintainConfigs = List.of(
10097
new CorrectExplains(new EmbeddedConfig()),
@@ -108,6 +105,32 @@ public void beforeAll(final ExtensionContext context) throws Exception {
108105
}
109106
}
110107

108+
private Stream<YamlTestConfig> localConfigs(final boolean mixedModeOnly, final boolean singleExternalVersionOnly) {
109+
if (mixedModeOnly || singleExternalVersionOnly) {
110+
return Stream.of();
111+
} else {
112+
return Stream.of(new EmbeddedConfig(), new JDBCInProcessConfig());
113+
}
114+
}
115+
116+
private Stream<YamlTestConfig> externalServerConfigs(final boolean singleExternalVersionOnly) {
117+
if (singleExternalVersionOnly) {
118+
return servers.stream()
119+
// Create an ExternalServer config with two servers of the same version for each server
120+
// (with and without forced continuations)
121+
.flatMap(server ->
122+
Stream.of(new ExternalMultiServerConfig(0, server, server),
123+
new ForceContinuations(new ExternalMultiServerConfig(0, server, server))));
124+
} else {
125+
return servers.stream().flatMap(server ->
126+
// (4 configs for each server available)
127+
Stream.of(new JDBCMultiServerConfig(0, server),
128+
new ForceContinuations(new JDBCMultiServerConfig(0, server)),
129+
new JDBCMultiServerConfig(1, server),
130+
new ForceContinuations(new JDBCMultiServerConfig(1, server))));
131+
}
132+
}
133+
111134
@Override
112135
@SuppressWarnings("PMD.UnnecessaryLocalBeforeReturn") // It complains about the local variable `e` being returned
113136
public void afterAll(final ExtensionContext context) throws Exception {

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/EmbeddedConfig.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@
2222

2323
import com.apple.foundationdb.relational.api.Options;
2424
import com.apple.foundationdb.relational.server.FRL;
25-
import com.apple.foundationdb.relational.yamltests.SimpleYamlConnection;
26-
import com.apple.foundationdb.relational.yamltests.YamlConnection;
2725
import com.apple.foundationdb.relational.yamltests.YamlConnectionFactory;
2826
import com.apple.foundationdb.relational.yamltests.YamlExecutionContext;
29-
import com.apple.foundationdb.relational.yamltests.server.SemanticVersion;
27+
import com.apple.foundationdb.relational.yamltests.connectionfactory.EmbeddedYamlConnectionFactory;
3028

3129
import javax.annotation.Nonnull;
32-
import java.net.URI;
33-
import java.sql.DriverManager;
34-
import java.sql.SQLException;
35-
import java.util.Set;
3630

3731
/**
3832
* Run directly against an instance of {@link FRL}.
@@ -61,18 +55,7 @@ public void afterAll() throws Exception {
6155

6256
@Override
6357
public YamlConnectionFactory createConnectionFactory() {
64-
return new YamlConnectionFactory() {
65-
@Override
66-
public YamlConnection getNewConnection(@Nonnull URI connectPath) throws SQLException {
67-
return new SimpleYamlConnection(DriverManager.getConnection(connectPath.toString()), SemanticVersion.current());
68-
}
69-
70-
@Override
71-
public Set<SemanticVersion> getVersionsUnderTest() {
72-
return Set.of(SemanticVersion.current());
73-
}
74-
75-
};
58+
return new EmbeddedYamlConnectionFactory();
7659
}
7760

7861
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* MultiServerConfig.java
3+
*
4+
* This source file is part of the FoundationDB open source project
5+
*
6+
* Copyright 2015-2025 Apple Inc. and the FoundationDB project authors
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package com.apple.foundationdb.relational.yamltests.configs;
22+
23+
import com.apple.foundationdb.relational.yamltests.YamlConnectionFactory;
24+
import com.apple.foundationdb.relational.yamltests.YamlExecutionContext;
25+
import com.apple.foundationdb.relational.yamltests.connectionfactory.ExternalServerYamlConnectionFactory;
26+
import com.apple.foundationdb.relational.yamltests.connectionfactory.MultiServerConnectionFactory;
27+
import com.apple.foundationdb.relational.yamltests.server.ExternalServer;
28+
29+
import javax.annotation.Nonnull;
30+
import java.util.List;
31+
32+
/**
33+
* Run against multiple external servers, alternating commands that go against each.
34+
*/
35+
public class ExternalMultiServerConfig implements YamlTestConfig {
36+
37+
private final int initialConnection;
38+
private final ExternalServer server0;
39+
private final ExternalServer server1;
40+
41+
public ExternalMultiServerConfig(final int initialConnection, ExternalServer server0, ExternalServer server1) {
42+
super();
43+
this.initialConnection = initialConnection;
44+
this.server0 = server0;
45+
this.server1 = server1;
46+
}
47+
48+
@Override
49+
public void beforeAll() throws Exception {
50+
}
51+
52+
@Override
53+
public void afterAll() throws Exception {
54+
}
55+
56+
@Override
57+
public YamlConnectionFactory createConnectionFactory() {
58+
return new MultiServerConnectionFactory(
59+
MultiServerConnectionFactory.ConnectionSelectionPolicy.ALTERNATE,
60+
initialConnection,
61+
new ExternalServerYamlConnectionFactory(server0),
62+
List.of(new ExternalServerYamlConnectionFactory(server1)));
63+
}
64+
65+
@Override
66+
public String toString() {
67+
if (initialConnection == 0) {
68+
return "MultiServer (" + server0.getVersion() + " then " + server1.getVersion() + ")";
69+
} else {
70+
return "MultiServer (" + server1.getVersion() + " then " + server0.getVersion() + ")";
71+
}
72+
}
73+
74+
@Override
75+
public @Nonnull YamlExecutionContext.ContextOptions getRunnerOptions() {
76+
return YamlExecutionContext.ContextOptions.EMPTY_OPTIONS;
77+
}
78+
79+
}

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCInProcessConfig.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,18 @@
2020

2121
package com.apple.foundationdb.relational.yamltests.configs;
2222

23-
import com.apple.foundationdb.relational.jdbc.JDBCURI;
2423
import com.apple.foundationdb.relational.server.InProcessRelationalServer;
25-
import com.apple.foundationdb.relational.yamltests.SimpleYamlConnection;
26-
import com.apple.foundationdb.relational.yamltests.YamlConnection;
2724
import com.apple.foundationdb.relational.yamltests.YamlConnectionFactory;
2825
import com.apple.foundationdb.relational.yamltests.YamlExecutionContext;
29-
import com.apple.foundationdb.relational.yamltests.server.SemanticVersion;
30-
import org.apache.logging.log4j.LogManager;
31-
import org.apache.logging.log4j.Logger;
26+
import com.apple.foundationdb.relational.yamltests.connectionfactory.JDBCInProcessYamlConnectionFactory;
3227

3328
import javax.annotation.Nonnull;
3429
import javax.annotation.Nullable;
35-
import java.net.URI;
36-
import java.sql.DriverManager;
37-
import java.sql.SQLException;
38-
import java.util.Set;
3930

4031
/**
4132
* Run against an embedded JDBC server.
4233
*/
4334
public class JDBCInProcessConfig implements YamlTestConfig {
44-
private static final Logger LOG = LogManager.getLogger(JDBCInProcessConfig.class);
45-
4635
@Nullable
4736
private InProcessRelationalServer server;
4837

@@ -65,22 +54,7 @@ public void afterAll() throws Exception {
6554

6655
@Override
6756
public YamlConnectionFactory createConnectionFactory() {
68-
return new YamlConnectionFactory() {
69-
@Override
70-
public YamlConnection getNewConnection(@Nonnull URI connectPath) throws SQLException {
71-
// Add name of the in-process running server to the connectPath.
72-
URI connectPathPlusServerName = JDBCURI.addQueryParameter(connectPath, JDBCURI.INPROCESS_URI_QUERY_SERVERNAME_KEY, server.getServerName());
73-
String uriStr = connectPathPlusServerName.toString().replaceFirst("embed:", "relational://");
74-
LOG.info("Rewrote {} as {}", connectPath, uriStr);
75-
return new SimpleYamlConnection(DriverManager.getConnection(uriStr), SemanticVersion.current());
76-
}
77-
78-
@Override
79-
public Set<SemanticVersion> getVersionsUnderTest() {
80-
return Set.of(SemanticVersion.current());
81-
}
82-
83-
};
57+
return new JDBCInProcessYamlConnectionFactory(server);
8458
}
8559

8660
@Override

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/MultiServerConfig.java renamed to yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCMultiServerConfig.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,22 @@
2020

2121
package com.apple.foundationdb.relational.yamltests.configs;
2222

23-
import com.apple.foundationdb.relational.yamltests.MultiServerConnectionFactory;
24-
import com.apple.foundationdb.relational.yamltests.SimpleYamlConnection;
25-
import com.apple.foundationdb.relational.yamltests.YamlConnection;
2623
import com.apple.foundationdb.relational.yamltests.YamlConnectionFactory;
24+
import com.apple.foundationdb.relational.yamltests.connectionfactory.ExternalServerYamlConnectionFactory;
25+
import com.apple.foundationdb.relational.yamltests.connectionfactory.MultiServerConnectionFactory;
2726
import com.apple.foundationdb.relational.yamltests.server.ExternalServer;
28-
import com.apple.foundationdb.relational.yamltests.server.SemanticVersion;
2927

30-
import javax.annotation.Nonnull;
31-
import java.net.URI;
32-
import java.sql.DriverManager;
33-
import java.sql.SQLException;
3428
import java.util.List;
35-
import java.util.Set;
3629

3730
/**
3831
* Run against an embedded JDBC driver, and an external server, alternating commands that go against each.
3932
*/
40-
public class MultiServerConfig extends JDBCInProcessConfig {
33+
public class JDBCMultiServerConfig extends JDBCInProcessConfig {
4134

4235
private final ExternalServer externalServer;
4336
private final int initialConnection;
4437

45-
public MultiServerConfig(final int initialConnection, ExternalServer externalServer) {
38+
public JDBCMultiServerConfig(final int initialConnection, ExternalServer externalServer) {
4639
super();
4740
this.initialConnection = initialConnection;
4841
this.externalServer = externalServer;
@@ -59,23 +52,7 @@ public YamlConnectionFactory createConnectionFactory() {
5952
MultiServerConnectionFactory.ConnectionSelectionPolicy.ALTERNATE,
6053
initialConnection,
6154
super.createConnectionFactory(),
62-
List.of(createExternalServerConnection()));
63-
}
64-
65-
YamlConnectionFactory createExternalServerConnection() {
66-
return new YamlConnectionFactory() {
67-
@Override
68-
public YamlConnection getNewConnection(@Nonnull URI connectPath) throws SQLException {
69-
String uriStr = connectPath.toString().replaceFirst("embed:", "relational://localhost:" + externalServer.getPort());
70-
return new SimpleYamlConnection(DriverManager.getConnection(uriStr), externalServer.getVersion());
71-
}
72-
73-
@Override
74-
public Set<SemanticVersion> getVersionsUnderTest() {
75-
return Set.of(externalServer.getVersion());
76-
}
77-
78-
};
55+
List.of(new ExternalServerYamlConnectionFactory(externalServer)));
7956
}
8057

8158
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* EmbeddedYamlConnectionFactory.java
3+
*
4+
* This source file is part of the FoundationDB open source project
5+
*
6+
* Copyright 2015-2025 Apple Inc. and the FoundationDB project authors
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package com.apple.foundationdb.relational.yamltests.connectionfactory;
22+
23+
import com.apple.foundationdb.relational.yamltests.SimpleYamlConnection;
24+
import com.apple.foundationdb.relational.yamltests.YamlConnection;
25+
import com.apple.foundationdb.relational.yamltests.YamlConnectionFactory;
26+
import com.apple.foundationdb.relational.yamltests.server.SemanticVersion;
27+
28+
import javax.annotation.Nonnull;
29+
import java.net.URI;
30+
import java.sql.DriverManager;
31+
import java.sql.SQLException;
32+
import java.util.Set;
33+
34+
public class EmbeddedYamlConnectionFactory implements YamlConnectionFactory {
35+
@Override
36+
public YamlConnection getNewConnection(@Nonnull URI connectPath) throws SQLException {
37+
return new SimpleYamlConnection(DriverManager.getConnection(connectPath.toString()), SemanticVersion.current());
38+
}
39+
40+
@Override
41+
public Set<SemanticVersion> getVersionsUnderTest() {
42+
return Set.of(SemanticVersion.current());
43+
}
44+
45+
}

0 commit comments

Comments
 (0)