dcapwell commented on code in PR #3789:
URL: https://github.com/apache/cassandra/pull/3789#discussion_r1918901780


##########
test/distributed/org/apache/cassandra/distributed/upgrade/ClusterMetadataUpgradeHarryTest.java:
##########
@@ -18,115 +18,135 @@
 
 package org.apache.cassandra.distributed.upgrade;
 
-import java.util.Collections;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
+import java.time.Duration;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
-import com.google.common.util.concurrent.Uninterruptibles;
-
-import org.apache.cassandra.harry.HarryHelper;
-import org.apache.cassandra.harry.core.Configuration;
-import org.apache.cassandra.harry.ddl.SchemaSpec;
-
-import org.apache.cassandra.harry.runner.FlaggedRunner;
-import org.apache.cassandra.harry.sut.injvm.ClusterState;
-import org.apache.cassandra.harry.sut.injvm.ExistingClusterSUT;
-
-import org.apache.cassandra.harry.visitors.MutatingVisitor;
-import org.apache.cassandra.harry.visitors.QueryLogger;
-import org.apache.cassandra.harry.visitors.RandomPartitionValidator;
-
 import org.junit.Test;
 
+import org.apache.cassandra.concurrent.Interruptible;
 import org.apache.cassandra.distributed.Constants;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
 import org.apache.cassandra.distributed.api.Feature;
+import org.apache.cassandra.harry.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ReplayingHistoryBuilder;
+import org.apache.cassandra.harry.execution.InJvmDTestVisitExecutor;
+import org.apache.cassandra.harry.gen.Generator;
+import org.apache.cassandra.harry.gen.Generators;
 import org.apache.cassandra.schema.SchemaConstants;
-import org.apache.cassandra.utils.concurrent.CountDownLatch;
-
+import org.apache.cassandra.utils.concurrent.UncheckedInterruptedException;
 
 import static java.util.Arrays.asList;
 import static 
org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory;
-import static 
org.apache.cassandra.harry.core.Configuration.VisitorPoolConfiguration.pool;
-import static org.apache.cassandra.harry.ddl.ColumnSpec.asciiType;
-import static org.apache.cassandra.harry.ddl.ColumnSpec.int64Type;
-import static org.apache.cassandra.harry.ddl.ColumnSpec.ck;
-import static org.apache.cassandra.harry.ddl.ColumnSpec.pk;
-import static org.apache.cassandra.harry.ddl.ColumnSpec.regularColumn;
-import static org.apache.cassandra.harry.ddl.ColumnSpec.staticColumn;
+import static 
org.apache.cassandra.concurrent.InfiniteLoopExecutor.SimulatorSafe.UNSAFE;
+import static org.apache.cassandra.harry.ColumnSpec.asciiType;
+import static org.apache.cassandra.harry.ColumnSpec.ck;
+import static org.apache.cassandra.harry.ColumnSpec.int64Type;
+import static org.apache.cassandra.harry.ColumnSpec.pk;
+import static org.apache.cassandra.harry.ColumnSpec.regularColumn;
+import static org.apache.cassandra.harry.ColumnSpec.staticColumn;
+import static org.apache.cassandra.harry.checker.TestHelper.withRandom;
 import static org.apache.cassandra.tcm.log.SystemKeyspaceStorage.NAME;
 import static org.junit.Assert.assertEquals;
 
 public class ClusterMetadataUpgradeHarryTest extends UpgradeTestBase
 {
     @Test
-    public void simpleUpgradeTest() throws Throwable
+    public void simpleUpgradeTest()
     {
-        ExecutorService es = executorFactory().pooled("harry", 1);
+        AtomicReference<Interruptible> executor = new AtomicReference<>();
+        AtomicLong loops = new AtomicLong(0);
         Listener listener = new Listener();
-        CountDownLatch stopLatch = CountDownLatch.newCountDownLatch(1);
-        AtomicReference<Future<?>> harryRunner = new AtomicReference<>();
-        new UpgradeTestBase.TestCase()
-        .nodes(3)
-        .nodesToUpgrade(1, 2, 3)
-        .withConfig((cfg) -> cfg.with(Feature.NETWORK, Feature.GOSSIP)
-                                .set(Constants.KEY_DTEST_FULL_STARTUP, true))
-        .upgradesToCurrentFrom(v41)
-        .withUpgradeListener(listener)
-        .setup((cluster) -> {
-             SchemaSpec schema = new SchemaSpec("harry", "test_table",
-                                                asList(pk("pk1", asciiType), 
pk("pk2", int64Type)),
-                                                asList(ck("ck1", asciiType), 
ck("ck2", int64Type)),
-                                                
asList(regularColumn("regular1", asciiType), regularColumn("regular2", 
int64Type)),
-                                                asList(staticColumn("static1", 
asciiType), staticColumn("static2", int64Type)));
-
-            Configuration config = HarryHelper.defaultConfiguration()
-                                              
.setKeyspaceDdl(String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH 
replication = {'class': 'SimpleStrategy', 'replication_factor': %d};", 
schema.keyspace, 3))
-                                              .setSchemaProvider(new 
Configuration.FixedSchemaProviderConfiguration(schema))
-                                              .setDataTracker(new 
Configuration.LockingDataTrackerConfiguration(-1l, -1l, 
Collections.emptyList()))
-                                              .setSUT(new 
ExistingClusterSUT(cluster, listener))
-                                              .build();
-
-            Future<?> f = es.submit(() -> {
+        Runnable awaitHarryProgress = () -> {
+            long startingLoopCount = loops.get();
+            long deadline = startingLoopCount + 10;
+            long nowNanos = System.nanoTime();
+            boolean matched = false;
+            for (int i = 0; i < 20 && !(matched = loops.get() >= deadline); 
i++)
+            {
                 try
                 {
-                    new FlaggedRunner(config.createRun(),
-                                      config,
-                                      asList(pool("Writer", 1, 
MutatingVisitor::new),
-                                             pool("Reader", 1, (run) -> new 
RandomPartitionValidator(run, new Configuration.QuiescentCheckerConfig(), 
QueryLogger.NO_OP.NO_OP))),
-                                      stopLatch).run();
+                    TimeUnit.MILLISECONDS.sleep(500);
                 }
-                catch (Throwable e)
+                catch (InterruptedException e)
                 {
-                    throw new RuntimeException(e);
+                    Thread.currentThread().interrupt();
+                    throw new UncheckedInterruptedException(e);
                 }
-              });
-            harryRunner.set(f);
-            Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
-        })
-        .runAfterNodeUpgrade((cluster, node) -> {
-            Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); // 
make sure harry executes in mixed mode
-        })
-        .runAfterClusterUpgrade((cluster) -> {
-
-            // make sure we haven't persisted any events;
-            cluster.stream().forEach((i) -> {
-                Object[][] res = i.executeInternal(String.format("select * 
from %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, NAME));
-                assertEquals(0, res.length);
-            });
-
-            cluster.get(1).nodetoolResult("cms", 
"initialize").asserts().success();
-            cluster.get(1).nodetoolResult("cms", "reconfigure", 
"3").asserts().success();
-            cluster.schemaChange(withKeyspace("create table %s.xyz (id int 
primary key)"));
-            stopLatch.decrement();
-            harryRunner.get().get();
-        }).run();
+            }
+            if (!matched)
+                throw new AssertionError("Harry did not make enough progress 
within " + Duration.ofNanos(System.nanoTime() - nowNanos) + "; starting loops " 
+ startingLoopCount + ", ending loops " + loops.get());
+        };
+        withRandom(rng -> {
+            new TestCase()
+            .nodes(3)
+            .nodesToUpgrade(1, 2, 3)
+            .withConfig((cfg) -> cfg.with(Feature.NETWORK, Feature.GOSSIP)
+                                    .set(Constants.KEY_DTEST_FULL_STARTUP, 
true))
+            .upgradesToCurrentFrom(v41)
+            .withUpgradeListener(listener)
+            .setup((cluster) -> {
+                SchemaSpec schema = new SchemaSpec(rng.next(),
+                                                   10_000,
+                                                   "harry", "test_table",
+                                                   asList(pk("pk1", 
asciiType), pk("pk2", int64Type)),
+                                                   asList(ck("ck1", asciiType, 
false), ck("ck2", int64Type, false)),
+                                                   
asList(regularColumn("regular1", asciiType), regularColumn("regular2", 
int64Type)),
+                                                   
asList(staticColumn("static1", asciiType), staticColumn("static2", int64Type)));
+                cluster.schemaChange(String.format("CREATE KEYSPACE IF NOT 
EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 
%d};", schema.keyspace, 3));
+                cluster.schemaChange(schema.compile());
+
+                HistoryBuilder history = new 
ReplayingHistoryBuilder(schema.valueGenerators,
+                                                                     hb -> 
InJvmDTestVisitExecutor.builder()
+                                                                               
                   .retryPolicy(retry -> true)
+                                                                               
                   .nodeSelector(lts -> {
+                                                                               
                       while (true)
+                                                                               
                       {
+                                                                               
                           int node = rng.nextInt(0, cluster.size()) + 1;
+                                                                               
                           if (listener.isDown(node))
+                                                                               
                               continue;
+                                                                               
                           return node;
+                                                                               
                       }
+                                                                               
                   })
+                                                                               
                   .consistencyLevel(ConsistencyLevel.QUORUM)
+                                                                               
                   .build(schema, hb, cluster));
+
+                Generator<Integer> pkIdxGen = Generators.int32(0, 
Math.min(10_000, schema.valueGenerators.ckPopulation()));
+
+                executor.set(executorFactory().infiniteLoop("R/W Worload",
+                                                            () -> {
+                                                                
history.insert(pkIdxGen.generate(rng));
+                                                                
history.selectPartition(pkIdxGen.generate(rng));
+                                                                
loops.incrementAndGet();
+                                                            }, UNSAFE));
+
+                awaitHarryProgress.run();
+            })
+            .runAfterNodeUpgrade((cluster, node) -> {
+                awaitHarryProgress.run();

Review Comment:
   ```suggestion
                   awaitHarryProgress.run(); // make sure harry executes in 
mixed mode
   ```



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