Skip to content

Commit 2d5235a

Browse files
authored
Allow specifying a custom cluster file to FRL and YamlTestExtension (#3251)
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 bf6ec26 commit 2d5235a

File tree

10 files changed

+89
-30
lines changed

10 files changed

+89
-30
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.apple.foundationdb.relational.recordlayer.ddl.RecordLayerMetadataOperationsFactory;
5151
import com.apple.foundationdb.relational.recordlayer.query.cache.RelationalPlanCache;
5252
import com.apple.foundationdb.relational.recordlayer.util.ExceptionUtil;
53-
import com.apple.foundationdb.relational.util.SpotBugsSuppressWarnings;
5453

5554
import javax.annotation.Nonnull;
5655
import javax.annotation.Nullable;
@@ -81,14 +80,16 @@ public class FRL implements AutoCloseable {
8180
private final RelationalDriver driver;
8281
private boolean registeredJDBCEmbedDriver;
8382

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

89-
@SpotBugsSuppressWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Should consider refactoring but throwing exceptions for now")
9087
public FRL(@Nonnull Options options) throws RelationalException {
91-
final FDBDatabase fdbDb = FDBDatabaseFactory.instance().getDatabase();
88+
this(options, null);
89+
}
90+
91+
public FRL(@Nonnull Options options, @Nullable String clusterFile) throws RelationalException {
92+
final FDBDatabase fdbDb = FDBDatabaseFactory.instance().getDatabase(clusterFile);
9293
final Long asyncToSyncTimeout = options.getOption(Options.Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS);
9394
if (asyncToSyncTimeout > 0) {
9495
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

+23-11
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,21 @@ public class YamlTestExtension implements TestTemplateInvocationContextProvider,
6464
private List<YamlTestConfig> testConfigs;
6565
private List<YamlTestConfig> maintainConfigs;
6666
private List<ExternalServer> servers;
67+
@Nullable
68+
private final String clusterFile;
69+
70+
public YamlTestExtension() {
71+
this.clusterFile = null; // it will get it from the environment
72+
}
73+
74+
public YamlTestExtension(@Nullable final String clusterFile) {
75+
this.clusterFile = clusterFile;
76+
}
6777

6878
@Override
6979
public void beforeAll(final ExtensionContext context) throws Exception {
7080
if (Boolean.parseBoolean(System.getProperty("tests.runQuick", "false"))) {
71-
testConfigs = List.of(new EmbeddedConfig());
81+
testConfigs = List.of(new EmbeddedConfig(clusterFile));
7282
maintainConfigs = List.of();
7383
} else {
7484
AtomicInteger serverPort = new AtomicInteger(1111);
@@ -78,7 +88,9 @@ public void beforeAll(final ExtensionContext context) throws Exception {
7888
// Potentially, we can relax this a little if all tests are disabled for multi-server execution, but this is
7989
// not a likely scenario.
8090
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());
91+
servers = jars.stream()
92+
.map(jar -> new ExternalServer(jar, serverPort.getAndIncrement(), serverPort.getAndIncrement(), clusterFile))
93+
.collect(Collectors.toList());
8294
for (ExternalServer server : servers) {
8395
server.start();
8496
}
@@ -94,10 +106,10 @@ public void beforeAll(final ExtensionContext context) throws Exception {
94106
externalServerConfigs).collect(Collectors.toList());
95107

96108
maintainConfigs = List.of(
97-
new CorrectExplains(new EmbeddedConfig()),
98-
new CorrectMetrics(new EmbeddedConfig()),
99-
new CorrectExplainsAndMetrics(new EmbeddedConfig()),
100-
new ShowPlanOnDiff(new EmbeddedConfig())
109+
new CorrectExplains(new EmbeddedConfig(clusterFile)),
110+
new CorrectMetrics(new EmbeddedConfig(clusterFile)),
111+
new CorrectExplainsAndMetrics(new EmbeddedConfig(clusterFile)),
112+
new ShowPlanOnDiff(new EmbeddedConfig(clusterFile))
101113
);
102114
}
103115
for (final YamlTestConfig testConfig : Iterables.concat(testConfigs, maintainConfigs)) {
@@ -109,7 +121,7 @@ private Stream<YamlTestConfig> localConfigs(final boolean mixedModeOnly, final b
109121
if (mixedModeOnly || singleExternalVersionOnly) {
110122
return Stream.of();
111123
} else {
112-
return Stream.of(new EmbeddedConfig(), new JDBCInProcessConfig());
124+
return Stream.of(new EmbeddedConfig(clusterFile), new JDBCInProcessConfig(clusterFile));
113125
}
114126
}
115127

@@ -124,10 +136,10 @@ private Stream<YamlTestConfig> externalServerConfigs(final boolean singleExterna
124136
} else {
125137
return servers.stream().flatMap(server ->
126138
// (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))));
139+
Stream.of(new JDBCMultiServerConfig(0, server, clusterFile),
140+
new ForceContinuations(new JDBCMultiServerConfig(0, server, clusterFile)),
141+
new JDBCMultiServerConfig(1, server, clusterFile),
142+
new ForceContinuations(new JDBCMultiServerConfig(1, server, clusterFile))));
131143
}
132144
}
133145

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@
2727
import com.apple.foundationdb.relational.yamltests.connectionfactory.EmbeddedYamlConnectionFactory;
2828

2929
import javax.annotation.Nonnull;
30+
import javax.annotation.Nullable;
3031

3132
/**
3233
* Run directly against an instance of {@link FRL}.
3334
*/
3435
public class EmbeddedConfig implements YamlTestConfig {
3536
private FRL frl;
37+
@Nullable
38+
private final String clusterFile;
39+
40+
public EmbeddedConfig() {
41+
this(null);
42+
}
43+
44+
public EmbeddedConfig(@Nullable final String clusterFile) {
45+
this.clusterFile = clusterFile;
46+
}
3647

3748
@Override
3849
public void beforeAll() throws Exception {
@@ -42,7 +53,7 @@ public void beforeAll() throws Exception {
4253
.withOption(Options.Name.PLAN_CACHE_TERTIARY_TIME_TO_LIVE_MILLIS, 3_600_000L)
4354
.withOption(Options.Name.PLAN_CACHE_PRIMARY_MAX_ENTRIES, 10)
4455
.build();
45-
frl = new FRL(options);
56+
frl = new FRL(options, clusterFile);
4657
}
4758

4859
@Override

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

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

3848
@Override
3949
public void beforeAll() throws Exception {
4050
try {
41-
server = new InProcessRelationalServer().start();
51+
server = new InProcessRelationalServer(clusterFile).start();
4252
} catch (Exception e) {
4353
throw new RuntimeException(e);
4454
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.apple.foundationdb.relational.yamltests.connectionfactory.MultiServerConnectionFactory;
2626
import com.apple.foundationdb.relational.yamltests.server.ExternalServer;
2727

28+
import javax.annotation.Nullable;
2829
import java.util.List;
2930

3031
/**
@@ -36,7 +37,12 @@ public class JDBCMultiServerConfig extends JDBCInProcessConfig {
3637
private final int initialConnection;
3738

3839
public JDBCMultiServerConfig(final int initialConnection, ExternalServer externalServer) {
39-
super();
40+
this(initialConnection, externalServer, null);
41+
}
42+
43+
public JDBCMultiServerConfig(final int initialConnection, ExternalServer externalServer,
44+
@Nullable final String clusterFile) {
45+
super(clusterFile);
4046
this.initialConnection = initialConnection;
4147
this.externalServer = externalServer;
4248
}

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.logging.log4j.Logger;
2626
import org.junit.jupiter.api.Assertions;
2727

28+
import javax.annotation.Nullable;
2829
import java.io.File;
2930
import java.io.IOException;
3031
import java.util.Arrays;
@@ -43,29 +44,35 @@ public class ExternalServer {
4344
public static final String EXTERNAL_SERVER_PROPERTY_NAME = "yaml_testing_external_server";
4445
private static final boolean SAVE_SERVER_OUTPUT = false;
4546

47+
@Nullable
4648
private final File serverJar;
4749
private final int grpcPort;
4850
private final int httpPort;
4951
private SemanticVersion version;
5052
private Process serverProcess;
53+
@Nullable
54+
private final String clusterFile;
5155

5256
/**
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.
57+
* Create a new instance that will run a specific jar.
58+
*
59+
* @param serverJar the path to the jar to run
5560
*/
56-
public ExternalServer(final int grpcPort, final int httpPort) {
57-
this(null, grpcPort, httpPort);
61+
public ExternalServer(@Nullable File serverJar, final int grpcPort, final int httpPort) {
62+
this(serverJar, grpcPort, httpPort, null);
5863
}
5964

6065
/**
6166
* Create a new instance that will run a specific jar.
6267
*
6368
* @param serverJar the path to the jar to run
6469
*/
65-
public ExternalServer(File serverJar, final int grpcPort, final int httpPort) {
70+
public ExternalServer(@Nullable File serverJar, final int grpcPort, final int httpPort,
71+
@Nullable final String clusterFile) {
6672
this.serverJar = serverJar;
6773
this.grpcPort = grpcPort;
6874
this.httpPort = httpPort;
75+
this.clusterFile = clusterFile;
6976
}
7077

7178
static {
@@ -129,6 +136,9 @@ public void start() throws Exception {
129136
ProcessBuilder.Redirect.DISCARD;
130137
processBuilder.redirectOutput(out);
131138
processBuilder.redirectError(err);
139+
if (clusterFile != null) {
140+
processBuilder.environment().put("FDB_CLUSTER_FILE", clusterFile);
141+
}
132142

133143
if (!startServer(processBuilder)) {
134144
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)