Skip to content

Commit cadc509

Browse files
committed
Allow specifying a custom cluster file to YamlTestExtension
This allows running yamsql tests with a custom cluster file that is not specified via the environment variable. This doesn't add support for doing this with the @yamltest annotation.
1 parent 3b7138a commit cadc509

File tree

10 files changed

+59
-33
lines changed

10 files changed

+59
-33
lines changed

fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/FRL.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public class FRL implements AutoCloseable {
8383

8484
@SpotBugsSuppressWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Should consider refactoring but throwing exceptions for now")
8585
public FRL() throws RelationalException {
86-
this(Options.NONE);
86+
this(Options.NONE, null);
8787
}
8888

8989
@SpotBugsSuppressWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Should consider refactoring but throwing exceptions for now")
90-
public FRL(@Nonnull Options options) throws RelationalException {
91-
final FDBDatabase fdbDb = FDBDatabaseFactory.instance().getDatabase();
90+
public FRL(@Nonnull Options options, @Nullable String clusterFile) throws RelationalException {
91+
final FDBDatabase fdbDb = FDBDatabaseFactory.instance().getDatabase(clusterFile);
9292
final Long asyncToSyncTimeout = options.getOption(Options.Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS);
9393
if (asyncToSyncTimeout > 0) {
9494
fdbDb.setAsyncToSyncTimeout(asyncToSyncTimeout, TimeUnit.MILLISECONDS);

fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/InProcessRelationalServer.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222

2323
import com.apple.foundationdb.annotation.API;
2424

25+
import com.apple.foundationdb.relational.api.Options;
2526
import com.apple.foundationdb.relational.api.exceptions.RelationalException;
2627
import com.apple.foundationdb.relational.server.jdbc.v1.JDBCService;
2728

2829
import io.grpc.Server;
2930
import io.grpc.inprocess.InProcessServerBuilder;
3031

32+
import javax.annotation.Nullable;
3133
import java.io.Closeable;
3234
import java.io.IOException;
3335
import java.io.InterruptedIOException;
@@ -46,13 +48,20 @@ public class InProcessRelationalServer implements Closeable {
4648
private Server grpcInProcessServer;
4749
private FRL frl;
4850
private final String serverName;
51+
@Nullable
52+
private final String clusterFile;
4953

5054
public InProcessRelationalServer() {
51-
this(InProcessServerBuilder.generateName());
55+
this(InProcessServerBuilder.generateName(), null);
5256
}
5357

54-
InProcessRelationalServer(String serverName) {
58+
public InProcessRelationalServer(@Nullable final String clusterFile) {
59+
this(InProcessServerBuilder.generateName(), clusterFile);
60+
}
61+
62+
InProcessRelationalServer(String serverName, @Nullable final String clusterFile) {
5563
this.serverName = serverName;
64+
this.clusterFile = clusterFile;
5665
}
5766

5867
public String getServerName() {
@@ -68,7 +77,7 @@ public InProcessRelationalServer start() throws IOException {
6877
// Create access to backing database.
6978
// TODO: Make this multi-query/-tenant/-database!
7079
try {
71-
this.frl = new FRL();
80+
this.frl = new FRL(Options.NONE, clusterFile);
7281
} catch (RelationalException ve) {
7382
throw new IOException(ve);
7483
}

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

+22-11
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ public class YamlTestExtension implements TestTemplateInvocationContextProvider,
6464
private List<YamlTestConfig> testConfigs;
6565
private List<YamlTestConfig> maintainConfigs;
6666
private List<ExternalServer> servers;
67+
private final String clusterFile;
68+
69+
public YamlTestExtension() {
70+
this.clusterFile = System.getenv("FDB_CLUSTER_FILE");
71+
}
72+
73+
public YamlTestExtension(final String clusterFile) {
74+
this.clusterFile = clusterFile;
75+
}
6776

6877
@Override
6978
public void beforeAll(final ExtensionContext context) throws Exception {
7079
if (Boolean.parseBoolean(System.getProperty("tests.runQuick", "false"))) {
71-
testConfigs = List.of(new EmbeddedConfig());
80+
testConfigs = List.of(new EmbeddedConfig(clusterFile));
7281
maintainConfigs = List.of();
7382
} else {
7483
AtomicInteger serverPort = new AtomicInteger(1111);
@@ -78,7 +87,9 @@ public void beforeAll(final ExtensionContext context) throws Exception {
7887
// Potentially, we can relax this a little if all tests are disabled for multi-server execution, but this is
7988
// not a likely scenario.
8089
Assertions.assertFalse(jars.isEmpty(), "There are no external servers available to run");
81-
servers = jars.stream().map(jar -> new ExternalServer(jar, serverPort.getAndIncrement(), serverPort.getAndIncrement())).collect(Collectors.toList());
90+
servers = jars.stream()
91+
.map(jar -> new ExternalServer(jar, serverPort.getAndIncrement(), serverPort.getAndIncrement(), clusterFile))
92+
.collect(Collectors.toList());
8293
for (ExternalServer server : servers) {
8394
server.start();
8495
}
@@ -94,10 +105,10 @@ public void beforeAll(final ExtensionContext context) throws Exception {
94105
externalServerConfigs).collect(Collectors.toList());
95106

96107
maintainConfigs = List.of(
97-
new CorrectExplains(new EmbeddedConfig()),
98-
new CorrectMetrics(new EmbeddedConfig()),
99-
new CorrectExplainsAndMetrics(new EmbeddedConfig()),
100-
new ShowPlanOnDiff(new EmbeddedConfig())
108+
new CorrectExplains(new EmbeddedConfig(clusterFile)),
109+
new CorrectMetrics(new EmbeddedConfig(clusterFile)),
110+
new CorrectExplainsAndMetrics(new EmbeddedConfig(clusterFile)),
111+
new ShowPlanOnDiff(new EmbeddedConfig(clusterFile))
101112
);
102113
}
103114
for (final YamlTestConfig testConfig : Iterables.concat(testConfigs, maintainConfigs)) {
@@ -109,7 +120,7 @@ private Stream<YamlTestConfig> localConfigs(final boolean mixedModeOnly, final b
109120
if (mixedModeOnly || singleExternalVersionOnly) {
110121
return Stream.of();
111122
} else {
112-
return Stream.of(new EmbeddedConfig(), new JDBCInProcessConfig());
123+
return Stream.of(new EmbeddedConfig(clusterFile), new JDBCInProcessConfig(clusterFile));
113124
}
114125
}
115126

@@ -124,10 +135,10 @@ private Stream<YamlTestConfig> externalServerConfigs(final boolean singleExterna
124135
} else {
125136
return servers.stream().flatMap(server ->
126137
// (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))));
138+
Stream.of(new JDBCMultiServerConfig(0, server, clusterFile),
139+
new ForceContinuations(new JDBCMultiServerConfig(0, server, clusterFile)),
140+
new JDBCMultiServerConfig(1, server, clusterFile),
141+
new ForceContinuations(new JDBCMultiServerConfig(1, server, clusterFile))));
131142
}
132143
}
133144

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
*/
3434
public class EmbeddedConfig implements YamlTestConfig {
3535
private FRL frl;
36+
private final String clusterFile;
37+
38+
public EmbeddedConfig(final String clusterFile) {
39+
this.clusterFile = clusterFile;
40+
}
3641

3742
@Override
3843
public void beforeAll() throws Exception {
@@ -42,7 +47,7 @@ public void beforeAll() throws Exception {
4247
.withOption(Options.Name.PLAN_CACHE_TERTIARY_TIME_TO_LIVE_MILLIS, 3_600_000L)
4348
.withOption(Options.Name.PLAN_CACHE_PRIMARY_MAX_ENTRIES, 10)
4449
.build();
45-
frl = new FRL(options);
50+
frl = new FRL(options, clusterFile);
4651
}
4752

4853
@Override

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@
3434
public class JDBCInProcessConfig implements YamlTestConfig {
3535
@Nullable
3636
private InProcessRelationalServer server;
37+
@Nullable
38+
private final String clusterFile;
39+
40+
public JDBCInProcessConfig(@Nullable final String clusterFile) {
41+
this.clusterFile = clusterFile;
42+
}
3743

3844
@Override
3945
public void beforeAll() throws Exception {
4046
try {
41-
server = new InProcessRelationalServer().start();
47+
server = new InProcessRelationalServer(clusterFile).start();
4248
} catch (Exception e) {
4349
throw new RuntimeException(e);
4450
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class JDBCMultiServerConfig extends JDBCInProcessConfig {
3535
private final ExternalServer externalServer;
3636
private final int initialConnection;
3737

38-
public JDBCMultiServerConfig(final int initialConnection, ExternalServer externalServer) {
39-
super();
38+
public JDBCMultiServerConfig(final int initialConnection, ExternalServer externalServer, final String clusterFile) {
39+
super(clusterFile);
4040
this.initialConnection = initialConnection;
4141
this.externalServer = externalServer;
4242
}

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,18 @@ public class ExternalServer {
4848
private final int httpPort;
4949
private SemanticVersion version;
5050
private Process serverProcess;
51-
52-
/**
53-
* Create a new instance that will run latest released version of the server, as downloaded by gradle.
54-
* This assumes only one server exists in the download directory.
55-
*/
56-
public ExternalServer(final int grpcPort, final int httpPort) {
57-
this(null, grpcPort, httpPort);
58-
}
51+
private String clusterFile;
5952

6053
/**
6154
* Create a new instance that will run a specific jar.
6255
*
6356
* @param serverJar the path to the jar to run
6457
*/
65-
public ExternalServer(File serverJar, final int grpcPort, final int httpPort) {
58+
public ExternalServer(File serverJar, final int grpcPort, final int httpPort, final String clusterFile) {
6659
this.serverJar = serverJar;
6760
this.grpcPort = grpcPort;
6861
this.httpPort = httpPort;
62+
this.clusterFile = clusterFile;
6963
}
7064

7165
static {
@@ -129,6 +123,7 @@ public void start() throws Exception {
129123
ProcessBuilder.Redirect.DISCARD;
130124
processBuilder.redirectOutput(out);
131125
processBuilder.redirectError(err);
126+
processBuilder.environment().put("FDB_CLUSTER_FILE", clusterFile);
132127

133128
if (!startServer(processBuilder)) {
134129
Assertions.fail("Failed to start the external server");

yaml-tests/src/test/java/InitialVersionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*/
4545
public class InitialVersionTest {
4646
private static final SemanticVersion VERSION = SemanticVersion.parse("3.0.18.0");
47-
private static final EmbeddedConfig config = new EmbeddedConfig();
47+
private static final EmbeddedConfig config = new EmbeddedConfig(null);
4848

4949
@BeforeAll
5050
static void beforeAll() throws Exception {

yaml-tests/src/test/java/SupportedVersionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public class SupportedVersionTest {
4646

4747
private static final SemanticVersion VERSION = SemanticVersion.parse("3.0.18.0");
48-
private static final EmbeddedConfig config = new EmbeddedConfig();
48+
private static final EmbeddedConfig config = new EmbeddedConfig(null);
4949

5050
@BeforeAll
5151
static void beforeAll() throws Exception {

yaml-tests/src/test/java/YamlTestBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void beforeAll() throws RelationalException, SQLException {
3737
.withOption(Options.Name.PLAN_CACHE_SECONDARY_TIME_TO_LIVE_MILLIS, 3_600_000L)
3838
.withOption(Options.Name.PLAN_CACHE_TERTIARY_TIME_TO_LIVE_MILLIS, 3_600_000L)
3939
.build();
40-
frl = new FRL(options);
40+
frl = new FRL(options, null);
4141
}
4242

4343
@AfterAll

0 commit comments

Comments
 (0)