jacek-lewandowski commented on a change in pull request #1276:
URL: https://github.com/apache/cassandra/pull/1276#discussion_r768992431



##########
File path: 
test/distributed/org/apache/cassandra/distributed/test/SSTableIdGenerationTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.distributed.test;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.UntypedResultSet;
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
+import org.apache.cassandra.db.compaction.DateTieredCompactionStrategy;
+import org.apache.cassandra.db.compaction.LeveledCompactionStrategy;
+import org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy;
+import org.apache.cassandra.db.compaction.TimeWindowCompactionStrategy;
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.shared.ClusterUtils;
+import org.apache.cassandra.io.sstable.Descriptor;
+import org.apache.cassandra.io.sstable.SequenceBasedSSTableId;
+import org.apache.cassandra.io.sstable.UUIDBasedSSTableId;
+import org.apache.cassandra.metrics.RestorableMeter;
+import org.apache.cassandra.tools.SystemExitException;
+import org.apache.cassandra.utils.UUIDGen;
+import org.assertj.core.api.Assertions;
+import org.assertj.core.data.Offset;
+
+import static org.apache.cassandra.cql3.QueryProcessor.executeInternal;
+import static org.apache.cassandra.db.SystemKeyspace.LEGACY_SSTABLE_ACTIVITY;
+import static org.apache.cassandra.db.SystemKeyspace.SSTABLE_ACTIVITY_V2;
+import static org.apache.cassandra.distributed.shared.FutureUtils.waitOn;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SSTableIdGenerationTest extends TestBaseImpl
+{
+    private final static String ENABLE_UUID_FIELD_NAME = 
"enable_uuid_generation_identifiers";
+
+    private volatile int cnt;
+
+    @BeforeClass
+    public static void beforeClass() throws Throwable
+    {
+        TestBaseImpl.beforeClass();
+        ClusterUtils.preventSystemExit();
+    }
+
+    private void createSSTable(Cluster cluster, String tableName)
+    {
+        cluster.get(1).executeInternal(String.format("INSERT INTO %s.%s (pk, 
v) values (?,?)", KEYSPACE, tableName), cnt++, cnt++);
+        cluster.get(1).flush(KEYSPACE);
+    }
+
+    private void assertSSTablesCount(Cluster cluster, String tableName, int 
expectedSeqGenIds, int expectedUUIDGenIds)
+    {
+        try
+        {
+            cluster.get(1).runOnInstance(() -> {
+                Set<Descriptor> descs = Keyspace.open(KEYSPACE)
+                                                
.getColumnFamilyStore(tableName)
+                                                .getLiveSSTables()
+                                                .stream()
+                                                .map(sstr -> sstr.descriptor)
+                                                .collect(Collectors.toSet());
+                assertThat(descs.stream().filter(desc -> desc.generation 
instanceof SequenceBasedSSTableId).count()).isEqualTo(expectedSeqGenIds);
+                assertThat(descs.stream().filter(desc -> desc.generation 
instanceof UUIDBasedSSTableId).count()).isEqualTo(expectedUUIDGenIds);
+            });
+        }
+        catch (Throwable t)
+        {
+            throw new AssertionError(t);
+        }
+    }
+
+    @Test
+    public void testRestartWithUUIDEnabled() throws IOException
+    {
+        try (Cluster cluster = init(Cluster.build(1).withConfig(config -> 
config.set(ENABLE_UUID_FIELD_NAME, false)).start()))
+        {
+            cluster.disableAutoCompaction(KEYSPACE);
+            cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (pk int, v 
int, primary key (pk))");
+            createSSTable(cluster, "tbl");
+            createSSTable(cluster, "tbl");
+            assertSSTablesCount(cluster, "tbl", 2, 0);
+            verfiySSTableActivity(cluster, true);
+
+            waitOn(cluster.get(1).shutdown());
+            cluster.get(1).config().set(ENABLE_UUID_FIELD_NAME, true);
+            cluster.get(1).startup();
+
+            createSSTable(cluster, "tbl");
+            createSSTable(cluster, "tbl");
+
+            assertSSTablesCount(cluster, "tbl", 2, 3);
+
+            
assertThat(cluster.get(1).executeInternalWithResult(String.format("SELECT * 
FROM %s.%s", KEYSPACE, "tbl")).toObjectArrays()).hasSize(4);
+        }
+    }
+
+    @Test
+    public void testRestartWithUUIDDisabled() throws IOException
+    {
+        try (Cluster cluster = init(Cluster.build(1).withConfig(config -> 
config.set(ENABLE_UUID_FIELD_NAME, true)).start()))
+        {
+            cluster.disableAutoCompaction(KEYSPACE);
+            cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (pk int, v 
int, primary key (pk))");
+            createSSTable(cluster, "tbl");
+            createSSTable(cluster, "tbl");
+            assertSSTablesCount(cluster, "tbl", 0, 2);
+            verfiySSTableActivity(cluster, false);
+
+            waitOn(cluster.get(1).shutdown(true));
+            cluster.get(1).config().set(ENABLE_UUID_FIELD_NAME, false);
+
+            Assertions.assertThatExceptionOfType(RuntimeException.class)
+                      .isThrownBy(() -> cluster.get(1).startup())
+                      .withCauseInstanceOf(SystemExitException.class);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testCompactionStrategiesWithMixedSSTables() throws Exception
+    {
+        
testCompactionStrategiesWithMixedSSTables(SizeTieredCompactionStrategy.class, 
DateTieredCompactionStrategy.class, TimeWindowCompactionStrategy.class, 
LeveledCompactionStrategy.class);
+    }
+
+    @SuppressWarnings("unchecked")
+    private void testCompactionStrategiesWithMixedSSTables(Class<? extends 
AbstractCompactionStrategy>... compactionStrategyClasses) throws Exception

Review comment:
       heh, the Java's requirement for a private method to be final is a bit odd




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