Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying a custom cluster file to FRL and YamlTestExtension #3251

Merged
merged 3 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import com.apple.foundationdb.relational.recordlayer.ddl.RecordLayerMetadataOperationsFactory;
import com.apple.foundationdb.relational.recordlayer.query.cache.RelationalPlanCache;
import com.apple.foundationdb.relational.recordlayer.util.ExceptionUtil;
import com.apple.foundationdb.relational.util.SpotBugsSuppressWarnings;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -81,14 +80,16 @@ public class FRL implements AutoCloseable {
private final RelationalDriver driver;
private boolean registeredJDBCEmbedDriver;

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

@SpotBugsSuppressWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Should consider refactoring but throwing exceptions for now")
public FRL(@Nonnull Options options) throws RelationalException {
final FDBDatabase fdbDb = FDBDatabaseFactory.instance().getDatabase();
this(options, null);
}

public FRL(@Nonnull Options options, @Nullable String clusterFile) throws RelationalException {
final FDBDatabase fdbDb = FDBDatabaseFactory.instance().getDatabase(clusterFile);
final Long asyncToSyncTimeout = options.getOption(Options.Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS);
if (asyncToSyncTimeout > 0) {
fdbDb.setAsyncToSyncTimeout(asyncToSyncTimeout, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

import com.apple.foundationdb.annotation.API;

import com.apple.foundationdb.relational.api.Options;
import com.apple.foundationdb.relational.api.exceptions.RelationalException;
import com.apple.foundationdb.relational.server.jdbc.v1.JDBCService;

import io.grpc.Server;
import io.grpc.inprocess.InProcessServerBuilder;

import javax.annotation.Nullable;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
Expand All @@ -46,13 +48,20 @@ public class InProcessRelationalServer implements Closeable {
private Server grpcInProcessServer;
private FRL frl;
private final String serverName;
@Nullable
private final String clusterFile;

public InProcessRelationalServer() {
this(InProcessServerBuilder.generateName());
this(InProcessServerBuilder.generateName(), null);
}

InProcessRelationalServer(String serverName) {
public InProcessRelationalServer(@Nullable final String clusterFile) {
this(InProcessServerBuilder.generateName(), clusterFile);
}

InProcessRelationalServer(String serverName, @Nullable final String clusterFile) {
this.serverName = serverName;
this.clusterFile = clusterFile;
}

public String getServerName() {
Expand All @@ -68,7 +77,7 @@ public InProcessRelationalServer start() throws IOException {
// Create access to backing database.
// TODO: Make this multi-query/-tenant/-database!
try {
this.frl = new FRL();
this.frl = new FRL(Options.NONE, clusterFile);
} catch (RelationalException ve) {
throw new IOException(ve);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,21 @@ public class YamlTestExtension implements TestTemplateInvocationContextProvider,
private List<YamlTestConfig> testConfigs;
private List<YamlTestConfig> maintainConfigs;
private List<ExternalServer> servers;
@Nullable
private final String clusterFile;

public YamlTestExtension() {
this.clusterFile = null; // it will get it from the environment
}

public YamlTestExtension(@Nullable final String clusterFile) {
this.clusterFile = clusterFile;
}

@Override
public void beforeAll(final ExtensionContext context) throws Exception {
if (Boolean.parseBoolean(System.getProperty("tests.runQuick", "false"))) {
testConfigs = List.of(new EmbeddedConfig());
testConfigs = List.of(new EmbeddedConfig(clusterFile));
maintainConfigs = List.of();
} else {
AtomicInteger serverPort = new AtomicInteger(1111);
Expand All @@ -78,7 +88,9 @@ public void beforeAll(final ExtensionContext context) throws Exception {
// Potentially, we can relax this a little if all tests are disabled for multi-server execution, but this is
// not a likely scenario.
Assertions.assertFalse(jars.isEmpty(), "There are no external servers available to run");
servers = jars.stream().map(jar -> new ExternalServer(jar, serverPort.getAndIncrement(), serverPort.getAndIncrement())).collect(Collectors.toList());
servers = jars.stream()
.map(jar -> new ExternalServer(jar, serverPort.getAndIncrement(), serverPort.getAndIncrement(), clusterFile))
.collect(Collectors.toList());
for (ExternalServer server : servers) {
server.start();
}
Expand All @@ -94,10 +106,10 @@ public void beforeAll(final ExtensionContext context) throws Exception {
externalServerConfigs).collect(Collectors.toList());

maintainConfigs = List.of(
new CorrectExplains(new EmbeddedConfig()),
new CorrectMetrics(new EmbeddedConfig()),
new CorrectExplainsAndMetrics(new EmbeddedConfig()),
new ShowPlanOnDiff(new EmbeddedConfig())
new CorrectExplains(new EmbeddedConfig(clusterFile)),
new CorrectMetrics(new EmbeddedConfig(clusterFile)),
new CorrectExplainsAndMetrics(new EmbeddedConfig(clusterFile)),
new ShowPlanOnDiff(new EmbeddedConfig(clusterFile))
);
}
for (final YamlTestConfig testConfig : Iterables.concat(testConfigs, maintainConfigs)) {
Expand All @@ -109,7 +121,7 @@ private Stream<YamlTestConfig> localConfigs(final boolean mixedModeOnly, final b
if (mixedModeOnly || singleExternalVersionOnly) {
return Stream.of();
} else {
return Stream.of(new EmbeddedConfig(), new JDBCInProcessConfig());
return Stream.of(new EmbeddedConfig(clusterFile), new JDBCInProcessConfig(clusterFile));
}
}

Expand All @@ -124,10 +136,10 @@ private Stream<YamlTestConfig> externalServerConfigs(final boolean singleExterna
} else {
return servers.stream().flatMap(server ->
// (4 configs for each server available)
Stream.of(new JDBCMultiServerConfig(0, server),
new ForceContinuations(new JDBCMultiServerConfig(0, server)),
new JDBCMultiServerConfig(1, server),
new ForceContinuations(new JDBCMultiServerConfig(1, server))));
Stream.of(new JDBCMultiServerConfig(0, server, clusterFile),
new ForceContinuations(new JDBCMultiServerConfig(0, server, clusterFile)),
new JDBCMultiServerConfig(1, server, clusterFile),
new ForceContinuations(new JDBCMultiServerConfig(1, server, clusterFile))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@
import com.apple.foundationdb.relational.yamltests.connectionfactory.EmbeddedYamlConnectionFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Run directly against an instance of {@link FRL}.
*/
public class EmbeddedConfig implements YamlTestConfig {
private FRL frl;
@Nullable
private final String clusterFile;

public EmbeddedConfig() {
this(null);
}

public EmbeddedConfig(@Nullable final String clusterFile) {
this.clusterFile = clusterFile;
}

@Override
public void beforeAll() throws Exception {
Expand All @@ -42,7 +53,7 @@ public void beforeAll() throws Exception {
.withOption(Options.Name.PLAN_CACHE_TERTIARY_TIME_TO_LIVE_MILLIS, 3_600_000L)
.withOption(Options.Name.PLAN_CACHE_PRIMARY_MAX_ENTRIES, 10)
.build();
frl = new FRL(options);
frl = new FRL(options, clusterFile);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@
public class JDBCInProcessConfig implements YamlTestConfig {
@Nullable
private InProcessRelationalServer server;
@Nullable
private final String clusterFile;

public JDBCInProcessConfig() {
this(null);
}

public JDBCInProcessConfig(@Nullable final String clusterFile) {
this.clusterFile = clusterFile;
}

@Override
public void beforeAll() throws Exception {
try {
server = new InProcessRelationalServer().start();
server = new InProcessRelationalServer(clusterFile).start();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.apple.foundationdb.relational.yamltests.connectionfactory.MultiServerConnectionFactory;
import com.apple.foundationdb.relational.yamltests.server.ExternalServer;

import javax.annotation.Nullable;
import java.util.List;

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

public JDBCMultiServerConfig(final int initialConnection, ExternalServer externalServer) {
super();
this(initialConnection, externalServer, null);
}

public JDBCMultiServerConfig(final int initialConnection, ExternalServer externalServer,
@Nullable final String clusterFile) {
super(clusterFile);
this.initialConnection = initialConnection;
this.externalServer = externalServer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Assertions;

import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
Expand All @@ -43,29 +44,35 @@ public class ExternalServer {
public static final String EXTERNAL_SERVER_PROPERTY_NAME = "yaml_testing_external_server";
private static final boolean SAVE_SERVER_OUTPUT = false;

@Nullable
private final File serverJar;
private final int grpcPort;
private final int httpPort;
private SemanticVersion version;
private Process serverProcess;
@Nullable
private final String clusterFile;

/**
* Create a new instance that will run latest released version of the server, as downloaded by gradle.
* This assumes only one server exists in the download directory.
* Create a new instance that will run a specific jar.
*
* @param serverJar the path to the jar to run
*/
public ExternalServer(final int grpcPort, final int httpPort) {
this(null, grpcPort, httpPort);
public ExternalServer(@Nullable File serverJar, final int grpcPort, final int httpPort) {
this(serverJar, grpcPort, httpPort, null);
}

/**
* Create a new instance that will run a specific jar.
*
* @param serverJar the path to the jar to run
*/
public ExternalServer(File serverJar, final int grpcPort, final int httpPort) {
public ExternalServer(@Nullable File serverJar, final int grpcPort, final int httpPort,
@Nullable final String clusterFile) {
this.serverJar = serverJar;
this.grpcPort = grpcPort;
this.httpPort = httpPort;
this.clusterFile = clusterFile;
}

static {
Expand Down Expand Up @@ -129,6 +136,9 @@ public void start() throws Exception {
ProcessBuilder.Redirect.DISCARD;
processBuilder.redirectOutput(out);
processBuilder.redirectError(err);
if (clusterFile != null) {
processBuilder.environment().put("FDB_CLUSTER_FILE", clusterFile);
}

if (!startServer(processBuilder)) {
Assertions.fail("Failed to start the external server");
Expand Down
2 changes: 1 addition & 1 deletion yaml-tests/src/test/java/InitialVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class InitialVersionTest {
private static final SemanticVersion VERSION = SemanticVersion.parse("3.0.18.0");
private static final EmbeddedConfig config = new EmbeddedConfig();
private static final EmbeddedConfig config = new EmbeddedConfig(null);

@BeforeAll
static void beforeAll() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion yaml-tests/src/test/java/SupportedVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public class SupportedVersionTest {

private static final SemanticVersion VERSION = SemanticVersion.parse("3.0.18.0");
private static final EmbeddedConfig config = new EmbeddedConfig();
private static final EmbeddedConfig config = new EmbeddedConfig(null);

@BeforeAll
static void beforeAll() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion yaml-tests/src/test/java/YamlTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void beforeAll() throws RelationalException, SQLException {
.withOption(Options.Name.PLAN_CACHE_SECONDARY_TIME_TO_LIVE_MILLIS, 3_600_000L)
.withOption(Options.Name.PLAN_CACHE_TERTIARY_TIME_TO_LIVE_MILLIS, 3_600_000L)
.build();
frl = new FRL(options);
frl = new FRL(options, null);
}

@AfterAll
Expand Down