This is an automated email from the ASF dual-hosted git repository.
ifesdjeen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git
The following commit(s) were added to refs/heads/master by this push:
new 43e6d54 Revert "Cluster builder should be provided to the factory and
expose state"
43e6d54 is described below
commit 43e6d54a0f396598ecbffc52d6fb2f4f17bd69c6
Author: Alex Petrov <[email protected]>
AuthorDate: Mon Apr 20 18:37:22 2020 +0200
Revert "Cluster builder should be provided to the factory and expose state"
This reverts commit 50fdfefa11248e7b93507b8e66322dc7a5056744.
---
.../shared/{AbstractBuilder.java => Builder.java} | 130 ++++++++++-----------
.../distributed/shared/DistributedTestBase.java | 2 +-
2 files changed, 65 insertions(+), 67 deletions(-)
diff --git
a/src/main/java/org/apache/cassandra/distributed/shared/AbstractBuilder.java
b/src/main/java/org/apache/cassandra/distributed/shared/Builder.java
similarity index 71%
rename from
src/main/java/org/apache/cassandra/distributed/shared/AbstractBuilder.java
rename to src/main/java/org/apache/cassandra/distributed/shared/Builder.java
index 993b8a3..b3b7db0 100644
--- a/src/main/java/org/apache/cassandra/distributed/shared/AbstractBuilder.java
+++ b/src/main/java/org/apache/cassandra/distributed/shared/Builder.java
@@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -37,14 +36,17 @@ import org.apache.cassandra.distributed.api.TokenSupplier;
import static
org.apache.cassandra.distributed.api.TokenSupplier.evenlyDistributedTokens;
-public abstract class AbstractBuilder<I extends IInstance, C extends ICluster,
B extends AbstractBuilder<I, C, B>>
+public abstract class Builder<I extends IInstance, C extends ICluster>
{
- public interface Factory<I extends IInstance, C extends ICluster, B
extends AbstractBuilder<I, C, B>>
+
+ private final int BROADCAST_PORT = 7012;
+
+ public interface Factory<I extends IInstance, C extends ICluster>
{
- C newCluster(B builder);
+ C newCluster(File root, Versions.Version version,
List<IInstanceConfig> configs, ClassLoader sharedClassLoader);
}
- private final Factory<I, C, B> factory;
+ private final Factory<I, C> factory;
private int nodeCount;
private int subnet;
private Map<Integer, NetworkTopology.DcAndRack> nodeIdTopology;
@@ -52,45 +54,12 @@ public abstract class AbstractBuilder<I extends IInstance,
C extends ICluster, B
private File root;
private Versions.Version version;
private Consumer<IInstanceConfig> configUpdater;
- private ClassLoader sharedClassLoader =
Thread.currentThread().getContextClassLoader();
- public AbstractBuilder(Factory<I, C, B> factory)
+ public Builder(Factory<I, C> factory)
{
this.factory = factory;
}
- public int getNodeCount() {
- return nodeCount;
- }
-
- public int getSubnet() {
- return subnet;
- }
-
- public Map<Integer, NetworkTopology.DcAndRack> getNodeIdTopology() {
- return nodeIdTopology;
- }
-
- public TokenSupplier getTokenSupplier() {
- return tokenSupplier;
- }
-
- public File getRoot() {
- return root;
- }
-
- public Versions.Version getVersion() {
- return version;
- }
-
- public Consumer<IInstanceConfig> getConfigUpdater() {
- return configUpdater;
- }
-
- public ClassLoader getSharedClassLoader() {
- return sharedClassLoader;
- }
-
public C start() throws IOException
{
C cluster = createWithoutStarting();
@@ -106,50 +75,79 @@ public abstract class AbstractBuilder<I extends IInstance,
C extends ICluster, B
if (nodeCount <= 0)
throw new IllegalStateException("Cluster must have at least one
node");
- root.mkdirs();
-
if (nodeIdTopology == null)
+ {
nodeIdTopology = IntStream.rangeClosed(1, nodeCount).boxed()
.collect(Collectors.toMap(nodeId ->
nodeId,
nodeId ->
NetworkTopology.dcAndRack(dcName(0), rackName(0))));
+ }
+
+ root.mkdirs();
+
+ ClassLoader sharedClassLoader =
Thread.currentThread().getContextClassLoader();
+
+ List<IInstanceConfig> configs = new ArrayList<>();
// TODO: make token allocation strategy configurable
if (tokenSupplier == null)
tokenSupplier = evenlyDistributedTokens(nodeCount);
- return factory.newCluster((B) this);
+ for (int i = 0; i < nodeCount; ++i)
+ {
+ int nodeNum = i + 1;
+ configs.add(createInstanceConfig(nodeNum));
+ }
+
+ return factory.newCluster(root, version, configs, sharedClassLoader);
}
- public B withSharedClassLoader(ClassLoader sharedClassLoader)
+ public IInstanceConfig newInstanceConfig(C cluster)
{
- this.sharedClassLoader = Objects.requireNonNull(sharedClassLoader,
"sharedClassLoader");
- return (B) this;
+ return createInstanceConfig(cluster.size() + 1);
}
- public B withTokenSupplier(TokenSupplier tokenSupplier)
+ protected IInstanceConfig createInstanceConfig(int nodeNum)
+ {
+ String ipPrefix = "127.0." + subnet + ".";
+ String seedIp = ipPrefix + "1";
+ String ipAddress = ipPrefix + nodeNum;
+ long token = tokenSupplier.token(nodeNum);
+
+ NetworkTopology topology = NetworkTopology.build(ipPrefix,
BROADCAST_PORT, nodeIdTopology);
+
+ IInstanceConfig config = generateConfig(nodeNum, ipAddress, topology,
root, String.valueOf(token), seedIp);
+ if (configUpdater != null)
+ configUpdater.accept(config);
+
+ return config;
+ }
+
+ protected abstract IInstanceConfig generateConfig(int nodeNum, String
ipAddress, NetworkTopology networkTopology, File root, String token, String
seedIp);
+
+ public Builder<I, C> withTokenSupplier(TokenSupplier tokenSupplier)
{
this.tokenSupplier = tokenSupplier;
- return (B) this;
+ return this;
}
- public B withSubnet(int subnet)
+ public Builder<I, C> withSubnet(int subnet)
{
this.subnet = subnet;
- return (B) this;
+ return this;
}
- public B withNodes(int nodeCount)
+ public Builder<I, C> withNodes(int nodeCount)
{
this.nodeCount = nodeCount;
- return (B) this;
+ return this;
}
- public B withDCs(int dcCount)
+ public Builder<I, C> withDCs(int dcCount)
{
return withRacks(dcCount, 1);
}
- public B withRacks(int dcCount, int racksPerDC)
+ public Builder<I, C> withRacks(int dcCount, int racksPerDC)
{
if (nodeCount == 0)
throw new IllegalStateException("Node count will be calculated. Do
not supply total node count in the builder");
@@ -159,7 +157,7 @@ public abstract class AbstractBuilder<I extends IInstance,
C extends ICluster, B
return withRacks(dcCount, racksPerDC, nodesPerRack);
}
- public B withRacks(int dcCount, int racksPerDC, int nodesPerRack)
+ public Builder<I, C> withRacks(int dcCount, int racksPerDC, int
nodesPerRack)
{
if (nodeIdTopology != null)
throw new IllegalStateException("Network topology already created.
Call withDCs/withRacks once or before withDC/withRack calls");
@@ -183,15 +181,15 @@ public abstract class AbstractBuilder<I extends
IInstance, C extends ICluster, B
dcCount, racksPerDC,
nodesPerRack, adjustedNodeCount));
nodeCount = adjustedNodeCount;
}
- return (B) this;
+ return this;
}
- public B withDC(String dcName, int nodeCount)
+ public Builder<I, C> withDC(String dcName, int nodeCount)
{
return withRack(dcName, rackName(1), nodeCount);
}
- public B withRack(String dcName, String rackName, int nodesInRack)
+ public Builder<I, C> withRack(String dcName, String rackName, int
nodesInRack)
{
if (nodeIdTopology == null)
{
@@ -204,11 +202,11 @@ public abstract class AbstractBuilder<I extends
IInstance, C extends ICluster, B
nodeIdTopology.put(nodeId, NetworkTopology.dcAndRack(dcName,
rackName));
nodeCount += nodesInRack;
- return (B) this;
+ return this;
}
// Map of node ids to dc and rack - must be contiguous with an entry
nodeId 1 to nodeCount
- public B withNodeIdTopology(Map<Integer, NetworkTopology.DcAndRack>
nodeIdTopology)
+ public Builder<I, C> withNodeIdTopology(Map<Integer,
NetworkTopology.DcAndRack> nodeIdTopology)
{
if (nodeIdTopology.isEmpty())
throw new IllegalStateException("Topology is empty. It must have
an entry for every nodeId.");
@@ -226,25 +224,25 @@ public abstract class AbstractBuilder<I extends
IInstance, C extends ICluster, B
this.nodeIdTopology = new HashMap<>(nodeIdTopology);
- return (B) this;
+ return this;
}
- public B withRoot(File root)
+ public Builder<I, C> withRoot(File root)
{
this.root = root;
- return (B) this;
+ return this;
}
- public B withVersion(Versions.Version version)
+ public Builder<I, C> withVersion(Versions.Version version)
{
this.version = version;
- return (B) this;
+ return this;
}
- public B withConfig(Consumer<IInstanceConfig> updater)
+ public Builder<I, C> withConfig(Consumer<IInstanceConfig> updater)
{
this.configUpdater = updater;
- return (B) this;
+ return this;
}
static String dcName(int index)
diff --git
a/src/main/java/org/apache/cassandra/distributed/shared/DistributedTestBase.java
b/src/main/java/org/apache/cassandra/distributed/shared/DistributedTestBase.java
index adcc306..3ec5426 100644
---
a/src/main/java/org/apache/cassandra/distributed/shared/DistributedTestBase.java
+++
b/src/main/java/org/apache/cassandra/distributed/shared/DistributedTestBase.java
@@ -34,7 +34,7 @@ public abstract class DistributedTestBase
ICluster.setup();
}
- public abstract <I extends IInstance, C extends ICluster, B extends
AbstractBuilder<I, C, B>> AbstractBuilder<I, C, B> builder();
+ public abstract <I extends IInstance, C extends ICluster> Builder<I, C>
builder();
public static String KEYSPACE = "distributed_test_keyspace";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]