dcapwell commented on code in PR #3835:
URL: https://github.com/apache/cassandra/pull/3835#discussion_r1931178735
##########
test/unit/org/apache/cassandra/utils/CassandraGenerators.java:
##########
@@ -183,29 +214,304 @@ public static Gen<String> sstableFormatNames()
return SourceDSL.arbitrary().pick("big", "bti");
}
+ public static Gen<SSTableFormat<?, ?>> sstableFormat()
+ {
+ // make sure ordering is determanstic, else repeatability breaks
+ NavigableMap<String, SSTableFormat<?, ?>> formats = new
TreeMap<>(DatabaseDescriptor.getSSTableFormats());
+ return SourceDSL.arbitrary().pick(new ArrayList<>(formats.values()));
+ }
+
+ public static class AbstractReplicationStrategyBuilder
+ {
+ public enum Strategy
+ {
+ Simple(true),
+ NetworkTopology(true),
+ Local(false),
+ Meta(false);
+
+ public final boolean userAllowed;
+
+ Strategy(boolean userAllowed)
+ {
+ this.userAllowed = userAllowed;
+ }
+ }
+
+ private Gen<Strategy> strategyGen =
SourceDSL.arbitrary().enumValues(Strategy.class);
+ private Gen<String> keyspaceNameGen = KEYSPACE_NAME_GEN;
+ private Gen<Integer> rfGen = SourceDSL.integers().between(1, 3);
+ private Gen<List<String>> networkTopologyDCGen = rs -> {
+ Gen<Integer> numDcsGen = SourceDSL.integers().between(1, 3);
+ Gen<String> nameGen = IDENTIFIER_GEN;
+ Set<String> dcs = new HashSet<>();
+ int targetSize = numDcsGen.generate(rs);
+ while (dcs.size() != targetSize)
+ dcs.add(nameGen.generate(rs));
+ List<String> ordered = new ArrayList<>(dcs);
+ ordered.sort(Comparator.naturalOrder());
+ return ordered;
+ };
+
+ public AbstractReplicationStrategyBuilder withKeyspace(Gen<String>
keyspaceNameGen)
+ {
+ this.keyspaceNameGen = keyspaceNameGen;
+ return this;
+ }
+
+ public AbstractReplicationStrategyBuilder withKeyspace(String keyspace)
+ {
+ this.keyspaceNameGen = i -> keyspace;
+ return this;
+ }
+
+ public AbstractReplicationStrategyBuilder withUserAllowed()
+ {
+ List<Strategy> allowed = Stream.of(Strategy.values()).filter(s ->
s.userAllowed).collect(Collectors.toList());
+ strategyGen = SourceDSL.arbitrary().pick(allowed);
+ return this;
+ }
+
+ public AbstractReplicationStrategyBuilder withRf(Gen<Integer> rfGen)
+ {
+ this.rfGen = rfGen;
+ return this;
+ }
+
+ public AbstractReplicationStrategyBuilder withRf(int rf)
+ {
+ this.rfGen = i -> rf;
+ return this;
+ }
+
+ public AbstractReplicationStrategyBuilder
withDatacenters(Gen<List<String>> networkTopologyDCGen)
+ {
+ this.networkTopologyDCGen = networkTopologyDCGen;
+ return this;
+ }
+
+ public AbstractReplicationStrategyBuilder withDatacenters(String
first, String... rest)
+ {
+ if (rest.length == 0)
+ {
+ this.networkTopologyDCGen = i ->
Collections.singletonList(first);
+ }
+ else
+ {
+ List<String> all = new ArrayList<>(rest.length + 1);
+ all.add(first);
+ all.addAll(Arrays.asList(rest));
+ this.networkTopologyDCGen = i -> all;
+ }
+ return this;
+ }
+
+ public Gen<AbstractReplicationStrategy> build()
+ {
+ return rs -> {
+ Strategy strategy = strategyGen.generate(rs);
+ switch (strategy)
+ {
+ case Simple:
+ return new SimpleStrategy(keyspaceNameGen.generate(rs),
+
ImmutableMap.of(SimpleStrategy.REPLICATION_FACTOR,
rfGen.generate(rs).toString()));
+ case NetworkTopology:
+ ImmutableMap.Builder<String, String> builder =
ImmutableMap.builder();
+ List<String> names = networkTopologyDCGen.generate(rs);
+ for (String name : names)
+ builder.put(name, rfGen.generate(rs).toString());
+ ImmutableMap<String, String> map = builder.build();
+ return new
TestableNetworkTopologyStrategy(keyspaceNameGen.generate(rs), map);
+ case Meta:
+ return new MetaStrategy(keyspaceNameGen.generate(rs),
ImmutableMap.of());
+ case Local:
+ return new LocalStrategy(keyspaceNameGen.generate(rs),
ImmutableMap.of());
+ default:
+ throw new
UnsupportedOperationException(strategy.name());
+ }
+ };
+ }
+ }
+
+ public static class TestableNetworkTopologyStrategy extends
NetworkTopologyStrategy
Review Comment:
`NetworkTopologyStrategy` validates the datacenters match a config, but that
makes it a bit harder to use in some contexts... so this one avoids validating
datacenters!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]