aweisberg commented on code in PR #4508: URL: https://github.com/apache/cassandra/pull/4508#discussion_r2590466318
########## test/unit/org/apache/cassandra/service/replication/migration/MutationTrackingMigrationStateTest.java: ########## @@ -0,0 +1,231 @@ +/* + * 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.service.replication.migration; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.ServerTestUtils; +import org.apache.cassandra.dht.Murmur3Partitioner; +import org.apache.cassandra.dht.Range; +import org.apache.cassandra.dht.Token; +import org.apache.cassandra.io.util.DataInputBuffer; +import org.apache.cassandra.io.util.DataOutputBuffer; +import org.apache.cassandra.schema.TableId; +import org.apache.cassandra.tcm.Epoch; +import org.apache.cassandra.tcm.membership.NodeVersion; + +import static org.junit.Assert.*; + +public class MutationTrackingMigrationStateTest +{ + private static Murmur3Partitioner partitioner; + private static TableId testTableId; + + @BeforeClass + public static void setup() throws Exception + { + ServerTestUtils.prepareServerNoRegister(); + partitioner = Murmur3Partitioner.instance; + testTableId = TableId.generate(); + } + + @Test + public void testEmptyState() + { + MutationTrackingMigrationState state = MutationTrackingMigrationState.EMPTY; + assertNotNull(state); + assertEquals(Epoch.EMPTY, state.lastModified); + assertTrue(state.keyspaceInfo.isEmpty()); + assertFalse(state.hasMigratingKeyspaces()); + } + + @Test + public void testWithKeyspaceMigrating() + { + MutationTrackingMigrationState state = MutationTrackingMigrationState.EMPTY; + Epoch epoch = Epoch.create(1); + + MutationTrackingMigrationState updated = state.withKeyspaceMigrating( + "test_ks", + Collections.singletonList(testTableId), + epoch + ); + + assertNotSame(state, updated); + assertTrue(state.keyspaceInfo.isEmpty()); + + // Verify update + assertTrue(updated.hasMigratingKeyspaces()); + assertNotNull(updated.getKeyspaceInfo("test_ks")); + assertEquals("test_ks", updated.getKeyspaceInfo("test_ks").keyspace); + assertFalse(updated.getKeyspaceInfo("test_ks").getPendingRangesForTable(testTableId).isEmpty()); + } + + @Test + public void testStateTransitions() + { + MutationTrackingMigrationState state = MutationTrackingMigrationState.EMPTY; + List<Range<Token>> ranges = createTestRanges(); + Epoch epoch1 = Epoch.create(1); + Epoch epoch2 = Epoch.create(2); + + // Start migration (full ring is pending for testTableId) + state = state.withKeyspaceMigrating("test_ks", Collections.singletonList(testTableId), epoch1); + assertTrue(state.hasMigratingKeyspaces()); + assertNotNull(state.getKeyspaceInfo("test_ks")); + assertFalse(state.getKeyspaceInfo("test_ks").isComplete()); + + // Subtract migrated ranges for specific table + state = state.withRangesRepairedForTable("test_ks", testTableId, ranges, epoch2); + KeyspaceMigrationInfo info = state.getKeyspaceInfo("test_ks"); + // After subtracting ranges, pending should be smaller (not necessarily empty) + assertNotNull(info); Review Comment: This only assertsNotNull? -- 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]

