Skip to content

Commit ec701ee

Browse files
authored
Merge pull request #1370 from myronkscott/fix_galvan
fix galvan to be more flexible in alternate uses
2 parents 1c461d1 + 1a8ee8e commit ec701ee

File tree

8 files changed

+48
-47
lines changed

8 files changed

+48
-47
lines changed

galvan-support/src/main/java/org/terracotta/testing/config/DefaultStartupCommandBuilder.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.ArrayList;
2828
import java.util.List;
2929
import java.util.Properties;
30-
import org.terracotta.testing.api.ConfigBuilder;
30+
import org.terracotta.testing.common.Assert;
3131

3232
public class DefaultStartupCommandBuilder implements StartupCommandBuilder, Cloneable {
3333
private StripeConfiguration stripeConfig;
@@ -38,10 +38,7 @@ public class DefaultStartupCommandBuilder implements StartupCommandBuilder, Clon
3838
private String stripeName;
3939
private String[] builtCommand;
4040

41-
private final ConfigBuilder builder;
42-
43-
public DefaultStartupCommandBuilder(ConfigBuilder builder) {
44-
this.builder = builder;
41+
public DefaultStartupCommandBuilder() {
4542
}
4643

4744
public DefaultStartupCommandBuilder copy() {
@@ -89,12 +86,8 @@ public StartupCommandBuilder logConfigExtension(String logConfigExt) {
8986
}
9087

9188
protected Path installServer() throws IOException {
92-
// Create a copy of the server for this installation.
93-
Files.createDirectories(stripeWorkingDir);
94-
Files.createDirectories(serverWorkingDir);
95-
// build the tc-config file
96-
builder.withStripeConfiguration(stripeConfig);
97-
Path tcConfig = builder.createConfig(stripeWorkingDir);
89+
Path tcConfig = stripeWorkingDir.resolve("tc-config.xml");
90+
Assert.assertTrue(tcConfig.toFile().exists());
9891
//Copy a custom logback configuration
9992
Files.copy(this.getClass().getResourceAsStream("/tc-logback.xml"), serverWorkingDir.resolve("logback-test.xml"), REPLACE_EXISTING);
10093
Properties props = new Properties();

galvan-support/src/main/java/org/terracotta/testing/master/BasicHarnessEntry.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected void runOneConfiguration(VerboseManager verboseManager, DebugOptions d
7171

7272
String stripeName = "stripe1";
7373
Path stripeInstallationDir = harnessOptions.configTestDir.resolve(stripeName);
74-
Files.createDirectory(stripeInstallationDir);
74+
Files.createDirectories(stripeInstallationDir);
7575

7676
VerboseManager stripeVerboseManager = verboseManager.createComponentManager("[" + stripeName + "]");
7777

@@ -84,7 +84,14 @@ protected void runOneConfiguration(VerboseManager verboseManager, DebugOptions d
8484
TestStateManager stateManager = new TestStateManager();
8585
StateInterlock interlock = new StateInterlock(verboseManager.createComponentManager("[Interlock]").createHarnessLogger(), stateManager);
8686
StripeInstaller stripeInstaller = new StripeInstaller(interlock, stateManager, stripeVerboseManager);
87-
// Configure and install each server in the stripe.
87+
88+
DefaultLegacyConfigBuilder config = new DefaultLegacyConfigBuilder();
89+
config.withNamespaceFragment(harnessOptions.namespaceFragment);
90+
config.withServiceFragment(harnessOptions.serviceFragment);
91+
config.withStripeConfiguration(stripeConfig);
92+
Path tcConfig = config.createConfig(stripeInstallationDir);
93+
94+
// Configure and install each server in the stripe.
8895
for (int i = 0; i < stripeSize; ++i) {
8996
String serverName = stripeConfig.getServerNames().get(i);
9097
Path serverWorkingDir = stripeInstallationDir.resolve(serverName);
@@ -94,10 +101,9 @@ protected void runOneConfiguration(VerboseManager verboseManager, DebugOptions d
94101
"\nkitLocationRelative:" + kitLocationRelative);
95102
// Determine if we want a debug port.
96103
int debugPort = stripeConfig.getServerDebugPorts().get(i);
97-
DefaultLegacyConfigBuilder config = new DefaultLegacyConfigBuilder();
98-
config.withNamespaceFragment(harnessOptions.namespaceFragment);
99-
config.withServiceFragment(harnessOptions.serviceFragment);
100-
StartupCommandBuilder builder = new DefaultStartupCommandBuilder(config)
104+
105+
Files.createDirectories(serverWorkingDir);
106+
StartupCommandBuilder builder = new DefaultStartupCommandBuilder()
101107
.stripeConfiguration(stripeConfig)
102108
.serverName(serverName)
103109
.stripeName(stripeName)

galvan-support/src/main/java/org/terracotta/testing/rules/BasicExternalCluster.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.function.Supplier;
4646
import static java.util.stream.Collectors.toList;
4747
import java.util.stream.IntStream;
48+
import org.terracotta.testing.api.ConfigBuilder;
4849
import org.terracotta.testing.common.Assert;
4950
import org.terracotta.testing.config.ClusterInfo;
5051
import org.terracotta.testing.master.InlineServer;
@@ -67,11 +68,13 @@ public class BasicExternalCluster extends Cluster {
6768
private final int reconnectWindow;
6869
private final int voters;
6970
private final boolean consistent;
71+
private final boolean inline;
7072

7173
private final String logConfigExt;
7274
private final int serverHeapSize;
7375
private final int serverDebugPortStart;
7476
private final OutputStream parentOutput;
77+
private final ConfigBuilder configBuilder;
7578
private final Supplier<StartupCommandBuilder> startupBuilder;
7679

7780
private String displayName;
@@ -87,8 +90,8 @@ public class BasicExternalCluster extends Cluster {
8790
private boolean isSafe;
8891

8992
public BasicExternalCluster(Path clusterDirectory, int stripeSize, Path server, int serverHeapSize,
90-
Properties systemProperties, Properties tcProps, int reconnect, int voters, boolean consistent, int serverDebugPort,
91-
String logConfigExt, OutputStream parentOutput, Supplier<StartupCommandBuilder> startupBuilder) {
93+
Properties systemProperties, Properties tcProps, int reconnect, int voters, boolean consistent, boolean inline, int serverDebugPort,
94+
String logConfigExt, OutputStream parentOutput, ConfigBuilder config, Supplier<StartupCommandBuilder> startupBuilder) {
9295
boolean didCreateDirectories = clusterDirectory.toFile().mkdirs();
9396
if (Files.exists(clusterDirectory)) {
9497
if (Files.isRegularFile(clusterDirectory)) {
@@ -106,10 +109,12 @@ public BasicExternalCluster(Path clusterDirectory, int stripeSize, Path server,
106109
this.reconnectWindow = reconnect;
107110
this.voters = voters;
108111
this.consistent = consistent;
112+
this.inline = inline;
109113
this.serverDebugPortStart = serverDebugPort;
110114
this.logConfigExt = logConfigExt;
111115
this.serverHeapSize = serverHeapSize;
112116
this.parentOutput = parentOutput;
117+
this.configBuilder = config;
113118
this.startupBuilder = startupBuilder;
114119
this.clientThread = Thread.currentThread();
115120
}
@@ -208,7 +213,7 @@ private void internalStart(CompletableFuture<Void> checker) throws Throwable {
208213

209214
String stripeName = "stripe1";
210215
Path stripeInstallationDir = testParentDir.toPath().resolve(stripeName);
211-
Files.createDirectory(stripeInstallationDir);
216+
Files.createDirectories(stripeInstallationDir);
212217

213218
VerboseManager stripeVerboseManager = displayVerboseManager.createComponentManager("[" + stripeName + "]");
214219

@@ -219,10 +224,15 @@ private void internalStart(CompletableFuture<Void> checker) throws Throwable {
219224

220225
// Configure and install each server in the stripe.
221226
System.setProperty("tc.install-root", server.toString());
227+
systemProperties.setProperty("tc.install-root", server.toString());
228+
229+
configBuilder.withStripeConfiguration(stripeConfig);
230+
Path tcConfig = configBuilder.createConfig(stripeInstallationDir);
222231

223232
for (int i = 0; i < stripeSize; ++i) {
224233
String serverName = serverNames.get(i);
225234
Path serverWorkingDir = stripeInstallationDir.resolve(serverName);
235+
Files.createDirectories(serverWorkingDir);
226236
// Determine if we want a debug port.
227237
int debugPort = stripeConfig.getServerDebugPorts().get(i);
228238

@@ -234,11 +244,7 @@ private void internalStart(CompletableFuture<Void> checker) throws Throwable {
234244
.serverWorkingDir(serverWorkingDir)
235245
.logConfigExtension(logConfigExt);
236246

237-
if (serverHeapSize <= 0) {
238-
System.setProperty("com.tc.tc.messages.packup.enabled", "false");
239-
}
240-
241-
ServerInstance serverProcess = serverHeapSize > 0 ?
247+
ServerInstance serverProcess = !inline ?
242248
new ServerProcess(serverName, server, serverWorkingDir, serverHeapSize, debugPort, systemProperties, parentOutput, builder.build())
243249
:
244250
new InlineServer(serverName, server, serverWorkingDir, systemProperties, parentOutput, builder.build());

galvan-support/src/main/java/org/terracotta/testing/rules/BasicExternalClusterBuilder.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public class BasicExternalClusterBuilder {
4545
private int reconnectWindow = ConfigConstants.DEFAULT_CLIENT_RECONNECT_WINDOW;
4646
private int voters = ConfigConstants.DEFAULT_VOTER_COUNT;
4747
private boolean consistent = false;
48+
private boolean inline = true;
4849

4950
private String logConfigExt = "logback-ext.xml";
5051
private int serverHeapSize = DEFAULT_SERVER_HEAP_MB;
51-
private int customHeapSize = DEFAULT_SERVER_HEAP_MB;
5252
private ConfigBuilder configBuilder;
5353
private ServerDeploymentBuilder serverBuilder = new ServerDeploymentBuilder();
5454
private Supplier<StartupCommandBuilder> startupBuilder;
@@ -138,7 +138,6 @@ public BasicExternalClusterBuilder withSystemProperty(String key, String value)
138138

139139
public BasicExternalClusterBuilder withServerHeap(int heapSize) {
140140
this.serverHeapSize = heapSize;
141-
this.customHeapSize = heapSize;
142141
return this;
143142
}
144143

@@ -163,11 +162,11 @@ public BasicExternalClusterBuilder startupBuilder(Supplier<StartupCommandBuilder
163162
}
164163

165164
public BasicExternalClusterBuilder inline(boolean yes) {
165+
inline = yes;
166166
if (yes) {
167167
this.serverHeapSize = -1;
168168
tcProperties.put("tc.messages.packup.enabled", false);
169169
} else {
170-
this.serverHeapSize = customHeapSize;
171170
tcProperties.put("tc.messages.packup.enabled", true);
172171
}
173172
return this;
@@ -201,9 +200,9 @@ public Cluster build() {
201200
int serverDebugStartPort = debugPortString != null ? Integer.parseInt(debugPortString) : 0;
202201

203202
return new BasicExternalCluster(clusterDirectory, stripeSize, this.serverBuilder.deploy(), serverHeapSize, systemProperties, tcProperties,
204-
this.reconnectWindow, this.voters, this.consistent, serverDebugStartPort,
205-
logConfigExt, parentStream,
206-
Optional.ofNullable(startupBuilder).orElse(()-> new DefaultStartupCommandBuilder(Optional.ofNullable(configBuilder).orElse(new DefaultLegacyConfigBuilder()))));
203+
this.reconnectWindow, this.voters, this.consistent, this.inline, serverDebugStartPort,
204+
logConfigExt, parentStream,Optional.ofNullable(configBuilder).orElse(new DefaultLegacyConfigBuilder()),
205+
Optional.ofNullable(startupBuilder).orElse(DefaultStartupCommandBuilder::new));
207206

208207
}
209208
}

galvan-support/src/test/java/org/terracotta/functional/ExtendedServerIT.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@
3131
*
3232
*/
3333
public class ExtendedServerIT {
34-
static {
35-
System.setProperty("tc.server-jar", "extended-server");
36-
}
37-
3834
@Rule
3935
public final Cluster CLUSTER = BasicExternalClusterBuilder.newCluster(1).withClientReconnectWindowTime(30)
36+
.inline(false)
4037
.build();
4138

4239
@Test

galvan-support/src/test/java/org/terracotta/functional/ReflectorFunctionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ReflectorFunctionIT {
3737
@Rule
3838
public final Cluster CLUSTER = BasicExternalClusterBuilder.newCluster(2)
3939
.inline(false)
40-
.startupBuilder(()->new DefaultStartupCommandBuilder(new DefaultLegacyConfigBuilder()) {
40+
.startupBuilder(()->new DefaultStartupCommandBuilder() {
4141
@Override
4242
public String[] build() {
4343
List<String> def = new ArrayList<>();

server-bootstrap/src/main/java/com/tc/server/Directories.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,21 @@ public static Path getServerJar() throws FileNotFoundException {
9393
if (jar == null) {
9494
jar = "tc-server.*\\.jar";
9595
}
96-
Path jarFile = searchForServerJar(getInstallationRoot(), jar);
97-
98-
return jarFile;
96+
Path path = getInstallationRoot();
97+
try {
98+
return searchForServerJar(path, jar);
99+
} catch (NoSuchElementException no) {
100+
throw new FileNotFoundException("searching:" + path + " jar:" + jar);
101+
}
99102
}
100103

101-
private static Path searchForServerJar(Path directory, String name) {
104+
private static Path searchForServerJar(Path directory, String name) throws NoSuchElementException {
102105
try {
103106
Optional<Path> possible = Files.find(directory, 5, (path, o)->{
104107
return path.getFileName().toString().matches(name); }
105108
).findAny();
106-
return possible.orElse(null);
107-
} catch (IOException | NoSuchElementException io) {
109+
return possible.orElseThrow();
110+
} catch (IOException io) {
108111
return null;
109112
}
110113
}

terracotta/src/main/java/com/tc/server/TCServerMain.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,15 @@ public static Future<Boolean> createServer(List<String> args, OutputStream conso
6060
try {
6161
Path serverJar = Directories.getServerJar();
6262

63-
if (serverJar != null) {
64-
ClassLoader serverClassLoader = new URLClassLoader(new URL[] {serverJar.toUri().toURL()}, TCServerMain.class.getClassLoader());
63+
ClassLoader serverClassLoader = new URLClassLoader(new URL[] {serverJar.toUri().toURL()}, TCServerMain.class.getClassLoader());
6564

66-
return ServerFactory.createServer(args, console, serverClassLoader);
67-
}
65+
return ServerFactory.createServer(args, console, serverClassLoader);
6866
} catch (RuntimeException t) {
6967
throw t;
7068
} catch (IOException io) {
7169
throw new UncheckedIOException(io);
7270
} catch (Exception e) {
7371
throw new RuntimeException(e);
7472
}
75-
throw new RuntimeException("server libraries not found");
7673
}
7774
}

0 commit comments

Comments
 (0)