jacek-lewandowski commented on code in PR #1804:
URL: https://github.com/apache/cassandra/pull/1804#discussion_r960536452


##########
test/distributed/org/apache/cassandra/distributed/test/SchemaTest.java:
##########
@@ -95,25 +107,54 @@ private void selectSilent(Cluster cluster, String name)
     @Test
     public void schemaReset() throws Throwable
     {
+        CassandraRelevantProperties.MIGRATION_DELAY.setLong(10000);
+        CassandraRelevantProperties.SCHEMA_PULL_INTERVAL.setLong(10000);
         try (Cluster cluster = init(Cluster.build(2).withConfig(cfg -> 
cfg.with(Feature.GOSSIP, Feature.NETWORK)).start()))
         {
             cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (pk INT 
PRIMARY KEY, v TEXT)");
 
             assertTrue(cluster.get(1).callOnInstance(() -> 
Schema.instance.getTableMetadata(KEYSPACE, "tbl") != null));
             assertTrue(cluster.get(2).callOnInstance(() -> 
Schema.instance.getTableMetadata(KEYSPACE, "tbl") != null));
 
+            // now we have a table tbl in the schema of both nodes
+
             cluster.get(2).shutdown().get();
 
-            // when schema is removed and there is no other node to fetch it 
from, node 1 should be left with clean schema
-            cluster.get(1).runOnInstance(() -> 
Schema.instance.resetLocalSchema());
+            Awaitility.await().atMost(Duration.ofSeconds(30)) // wait until 
node 1 notices that node 2 is dead
+                      .until(() -> cluster.get(1).callOnInstance(() -> 
Gossiper.instance.getLiveMembers().stream().allMatch(e -> 
e.equals(FBUtilities.getBroadcastAddressAndPort()))));
+
+            // when there is no node to fetch the schema from, reset local 
schema should immediately fail
+            
Assertions.assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
+                cluster.get(1).runOnInstance(() -> 
Schema.instance.resetLocalSchema());
+            }).withMessageContaining("Cannot reset local schema when there are 
no other live nodes");
+
+            // now, let's make a disagreement, the shutdown node 2 has a 
definition of tbl, while the running node 1 does not
+            cluster.get(1).runOnInstance(() -> {
+                Schema.instance.transform(current -> 
Schema.instance.distributedKeyspaces().without(KEYSPACE), false);
+             });
+
             assertTrue(cluster.get(1).callOnInstance(() -> 
Schema.instance.getTableMetadata(KEYSPACE, "tbl") == null));
 
+            // clear will wait until it receives schema from some other node
+            // also if we start the node2 first, schema of node2 will be 
synced to schema of node1 because node1 has the newest change (dropping the 
table)
+            // if we run clean on node1 first, it will advertise empty schema 
to node2 and apply the schema from it without merging
+            CompletableFuture<Boolean> clear1 = 
CompletableFuture.supplyAsync(() -> cluster.get(1).callOnInstance(() -> 
Schema.instance.updateHandler.clear().awaitUninterruptibly(1, 
TimeUnit.MINUTES)));

Review Comment:
   again, the formatting rules does not allow for make it nicely to my knowledge



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