maedhroz commented on code in PR #3474:
URL: https://github.com/apache/cassandra/pull/3474#discussion_r1722444117


##########
test/unit/org/apache/cassandra/cql3/CQLTester.java:
##########
@@ -2990,6 +3002,105 @@ public boolean equals(Object o)
         }
     }
 
+    /**
+     * Enhances {@link CQLTester} to make it easier for tests to leverage 
randomness.  This class is not the best way to
+     * leverage randomness as it won't run the tests against multiple seeds 
(so could take a long time to find faults)
+     *
+     * The main use case for this class is to take existing tests or tests 
patterns people wish to write, and make it easy
+     * and safe to add randomness.  One main advantage is that the node spun 
up has non-static configs, meaning that each
+     * test run can explore different spaces and avoid having to create a new 
yaml/CI pipeline to test different configs.
+     *
+     * When possible {@link Property#qt()} should be leveraged as it will 
rerun the test many times with different seeds.
+     */
+    public static abstract class Fuzzed extends CQLTester
+    {
+        private static RandomSource RANDOM;
+        private static long SEED;
+        private static String CONFIG = null;
+        protected static Gen<Map<String, Object>> CONFIG_GEN = null;
+
+        @Rule
+        public FailureWatcher failureRule = new FailureWatcher();
+
+        @BeforeClass
+        public static void setUpClass()
+        {
+            setupSeed();
+            try
+            {
+                prePrepareServer();
+                updateConfigs();
+
+                // Once per-JVM is enough
+                prepareServer();
+            }
+            catch (Throwable t)
+            {
+                throwPropertyError(t);
+            }
+        }
+
+        protected static RandomSource random()
+        {
+            if (RANDOM == null)
+                setupSeed();
+            return RANDOM;
+        }
+
+        protected static long seed()
+        {
+            return SEED;
+        }
+
+        private static void setupSeed()
+        {
+            if (RANDOM != null) return;
+            SEED = TEST_RANDOM_SEED.getLong(new DefaultRandom().nextLong());
+            RANDOM = new DefaultRandom(SEED);
+        }
+
+        @Before
+        public void resetSeed()
+        {
+            RANDOM.setSeed(SEED);
+        }
+
+        protected static void updateConfigs()
+        {
+            if (CONFIG_GEN == null)
+                CONFIG_GEN = new ConfigGenBuilder().build();
+            Map<String, Object> config = CONFIG_GEN.next(RANDOM);
+            CONFIG = YamlConfigurationLoader.toYaml(config);
+
+            Config c = DatabaseDescriptor.loadConfig();
+            YamlConfigurationLoader.updateFromMap(config, true, c);
+

Review Comment:
   Since the default is `periodic` now, we'd need some way to remove any 
lingering config incompatible w/ `batch` here:
   
   ```
   if (c.commitlog_sync != Config.CommitLogSync.periodic)
       c.commitlog_sync_period = null;
   ```



-- 
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]

Reply via email to