aweisberg commented on code in PR #4508: URL: https://github.com/apache/cassandra/pull/4508#discussion_r2611407842
########## test/unit/org/apache/cassandra/tcm/transformations/AlterSchemaMutationTrackingTest.java: ########## @@ -0,0 +1,246 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.tcm.transformations; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.ServerTestUtils; +import org.apache.cassandra.replication.MutationJournal; +import org.apache.cassandra.service.replication.migration.KeyspaceMigrationInfo; +import org.apache.cassandra.tcm.ClusterMetadata; + +import static org.apache.cassandra.cql3.CQLTester.schemaChange; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +/** + * Tests for AlterSchema auto-starting mutation tracking migration when replication type changes. + */ +public class AlterSchemaMutationTrackingTest +{ + private static final AtomicInteger ksCounter = new AtomicInteger(); + + @BeforeClass + public static void setUpClass() throws Exception + { + ServerTestUtils.daemonInitialization(); + ServerTestUtils.prepareServer(); + MutationJournal.instance.start(); + } + + private static String nextKsName() + { + return "ks" + ksCounter.incrementAndGet(); + } + + @Test + public void testAutoStartToTrackedMigration() throws Throwable + { + String ksName = nextKsName(); + // untracked replication + schemaChange( "CREATE KEYSPACE " + ksName + + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} " + + "AND replication_type = 'untracked'" + ); + schemaChange(String.format("CREATE TABLE %s.tbl (pk int PRIMARY KEY, val int)", ksName)); + + ClusterMetadata metadata = ClusterMetadata.current(); + assertNull(metadata.mutationTrackingMigrationState.getKeyspaceInfo(ksName)); + + // Alter tracked replication + schemaChange(String.format("ALTER KEYSPACE %s WITH replication_type = 'tracked'", ksName)); + + metadata = ClusterMetadata.current(); + KeyspaceMigrationInfo migrationInfo = metadata.mutationTrackingMigrationState.getKeyspaceInfo(ksName); + assertNotNull(migrationInfo); + assertFalse(migrationInfo.isComplete()); + } + + @Test + public void testAutoStartToUntrackedMigration() throws Throwable + { + String ksName = nextKsName(); + // tracked replication + schemaChange("CREATE KEYSPACE " + ksName + + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} " + + "AND replication_type = 'tracked'" + ); + + schemaChange(String.format("CREATE TABLE %s.tbl (pk int PRIMARY KEY, val int)", ksName)); + + ClusterMetadata metadata = ClusterMetadata.current(); + assertNull(metadata.mutationTrackingMigrationState.getKeyspaceInfo(ksName)); + + // Alter keyspace to untracked + schemaChange(String.format("ALTER KEYSPACE %s WITH replication_type = 'untracked'", ksName)); + + metadata = ClusterMetadata.current(); + KeyspaceMigrationInfo migrationInfo = metadata.mutationTrackingMigrationState.getKeyspaceInfo(ksName); + assertNotNull(migrationInfo); Review Comment: This should really assert it is as expected, tables, ranges, epoch etc to make sure nothing is mangled from AlterSchema. I know a lot of this is already tested in KeyspaceMigrationInfoTest, but this does the end to end part with AlterSchema. -- 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]

