diff --git a/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/FRL.java b/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/FRL.java index d7c3d139dc..7ff7244ed9 100644 --- a/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/FRL.java +++ b/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/FRL.java @@ -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; @@ -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); diff --git a/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/InProcessRelationalServer.java b/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/InProcessRelationalServer.java index b4b7c33538..69fb74fc8e 100644 --- a/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/InProcessRelationalServer.java +++ b/fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/InProcessRelationalServer.java @@ -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; @@ -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() { @@ -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); } diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java index b715341509..58f1307585 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlTestExtension.java @@ -64,11 +64,21 @@ public class YamlTestExtension implements TestTemplateInvocationContextProvider, private List testConfigs; private List maintainConfigs; private List 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); @@ -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(); } @@ -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)) { @@ -109,7 +121,7 @@ private Stream 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)); } } @@ -124,10 +136,10 @@ private Stream 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)))); } } diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/EmbeddedConfig.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/EmbeddedConfig.java index 0dc78f9ddd..f07f3565bb 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/EmbeddedConfig.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/EmbeddedConfig.java @@ -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 { @@ -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 diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCInProcessConfig.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCInProcessConfig.java index 4e09353d72..cc7887e843 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCInProcessConfig.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCInProcessConfig.java @@ -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); } diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCMultiServerConfig.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCMultiServerConfig.java index afa5caadc5..90b8fe6c00 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCMultiServerConfig.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/JDBCMultiServerConfig.java @@ -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; /** @@ -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; } diff --git a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/ExternalServer.java b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/ExternalServer.java index b86ba86938..b5e02f76d7 100644 --- a/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/ExternalServer.java +++ b/yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/ExternalServer.java @@ -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; @@ -43,18 +44,22 @@ 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); } /** @@ -62,10 +67,12 @@ public ExternalServer(final int grpcPort, final int httpPort) { * * @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 { @@ -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"); diff --git a/yaml-tests/src/test/java/InitialVersionTest.java b/yaml-tests/src/test/java/InitialVersionTest.java index af247c76aa..84f85fae23 100644 --- a/yaml-tests/src/test/java/InitialVersionTest.java +++ b/yaml-tests/src/test/java/InitialVersionTest.java @@ -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 { diff --git a/yaml-tests/src/test/java/SupportedVersionTest.java b/yaml-tests/src/test/java/SupportedVersionTest.java index b1739f1b12..c98230d4ed 100644 --- a/yaml-tests/src/test/java/SupportedVersionTest.java +++ b/yaml-tests/src/test/java/SupportedVersionTest.java @@ -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 { diff --git a/yaml-tests/src/test/java/YamlTestBase.java b/yaml-tests/src/test/java/YamlTestBase.java index d59c67805d..3073ab2d16 100644 --- a/yaml-tests/src/test/java/YamlTestBase.java +++ b/yaml-tests/src/test/java/YamlTestBase.java @@ -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