aweisberg commented on code in PR #4508: URL: https://github.com/apache/cassandra/pull/4508#discussion_r2590496689
########## test/unit/org/apache/cassandra/tcm/transformations/AdvanceMutationTrackingMigrationTest.java: ########## @@ -0,0 +1,197 @@ +/* + * 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.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.ServerTestUtils; +import org.apache.cassandra.config.CassandraRelevantProperties; +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.dht.IPartitioner; +import org.apache.cassandra.dht.Murmur3Partitioner; +import org.apache.cassandra.dht.Range; +import org.apache.cassandra.dht.Token; +import org.apache.cassandra.schema.TableId; +import org.apache.cassandra.service.replication.migration.KeyspaceMigrationInfo; +import org.apache.cassandra.service.replication.migration.MutationTrackingMigrationState; +import org.apache.cassandra.tcm.ClusterMetadata; +import org.apache.cassandra.tcm.Epoch; +import org.apache.cassandra.tcm.Transformation; + +import static org.junit.Assert.*; + +/** + * Tests for AdvanceMutationTrackingMigrationRanges transformation. + */ +public class AdvanceMutationTrackingMigrationTest +{ + private static IPartitioner partitioner; + private static TableId testTableId; + + @BeforeClass + public static void setup() throws Exception + { + System.setProperty(CassandraRelevantProperties.PARTITIONER.getKey(), Murmur3Partitioner.class.getName()); + ServerTestUtils.prepareServerNoRegister(); + partitioner = DatabaseDescriptor.getPartitioner(); + assertTrue(partitioner instanceof Murmur3Partitioner); + testTableId = TableId.generate(); + } + + @Test + public void testAdvanceRangesForMigratingKeyspace() + { + Epoch epoch1 = Epoch.create(1); + + // Create initial state with migrating keyspace (TO_TRACKED) + MutationTrackingMigrationState initialState = MutationTrackingMigrationState.EMPTY + .withKeyspaceMigrating("test_ks", Collections.singletonList(testTableId), epoch1); + + ClusterMetadata metadata = new ClusterMetadata(partitioner); + ClusterMetadata prev = metadata.forceEpoch(epoch1).transformer() + .with(initialState) + .build().metadata; + + // Create ranges to mark as completed + Collection<Range<Token>> completedRanges = createTestRanges(); + + // Apply transformation (with TableId) + AdvanceMutationTrackingMigration transformation = + new AdvanceMutationTrackingMigration("test_ks", testTableId, completedRanges); + + Transformation.Result result = transformation.execute(prev); + + // Verify success + assertTrue(result.isSuccess()); + + ClusterMetadata updated = result.success().metadata; + KeyspaceMigrationInfo info = updated.mutationTrackingMigrationState.getKeyspaceInfo("test_ks"); + + // Verify ranges were subtracted from pending + assertNotNull(info); + } + + @Test + public void testAdvanceRangesCompleteMigration() + { + Epoch epoch1 = Epoch.create(1); + + // Create initial state with migrating keyspace (TO_TRACKED) + MutationTrackingMigrationState initialState = MutationTrackingMigrationState.EMPTY + .withKeyspaceMigrating("test_ks", Collections.singletonList(testTableId), epoch1); + + ClusterMetadata metadata = new ClusterMetadata(partitioner); + ClusterMetadata prev = metadata.forceEpoch(epoch1).transformer() + .with(initialState) + .build().metadata; + + // Complete the full ring + Range<Token> fullRing = new Range<>(partitioner.getMinimumToken(), partitioner.getMinimumToken()); + Collection<Range<Token>> completedRanges = Collections.singleton(fullRing); + + // Apply transformation (with TableId) + AdvanceMutationTrackingMigration transformation = + new AdvanceMutationTrackingMigration("test_ks", testTableId, completedRanges); + + Transformation.Result result = transformation.execute(prev); + + // Verify success + assertTrue(result.isSuccess()); + + ClusterMetadata updated = result.success().metadata; + + // Verify migration was auto-completed (keyspace removed from state) + assertFalse(updated.mutationTrackingMigrationState.hasMigratingKeyspaces()); + assertNull(updated.mutationTrackingMigrationState.getKeyspaceInfo("test_ks")); + } + + @Test + public void testAdvanceRangesForNonMigratingKeyspace() + { + Epoch epoch1 = Epoch.create(1); + + // Create state without any migrating keyspaces + MutationTrackingMigrationState initialState = MutationTrackingMigrationState.EMPTY; + + ClusterMetadata metadata = new ClusterMetadata(partitioner); + ClusterMetadata prev = metadata.forceEpoch(epoch1).transformer() + .with(initialState) + .build().metadata; + + // Try to advance ranges for non-migrating keyspace + Collection<Range<Token>> completedRanges = createTestRanges(); + + AdvanceMutationTrackingMigration transformation = + new AdvanceMutationTrackingMigration("test_ks", testTableId, completedRanges); + + Transformation.Result result = transformation.execute(prev); + + // Verify rejection + assertTrue(result.isRejected()); + assertTrue(result.rejected().reason.contains("not migrating")); + } + + @Test + public void testAdvanceMultipleRanges() Review Comment: This test appears 100% identical to `testAdvanceRangesForMigratingKeyspace` -- 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]

