michaelsembwever commented on code in PR #3168: URL: https://github.com/apache/cassandra/pull/3168#discussion_r1536820989
########## test/distributed/org/apache/cassandra/distributed/test/SSTableCompressionTest.java: ########## @@ -0,0 +1,469 @@ +/* + * 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.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import org.junit.Test; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.Keyspace; +import org.apache.cassandra.distributed.Cluster; +import org.apache.cassandra.distributed.api.IInstanceConfig; +import org.apache.cassandra.distributed.api.IInvokableInstance; +import org.apache.cassandra.io.compress.DeflateCompressor; +import org.apache.cassandra.io.compress.LZ4Compressor; +import org.apache.cassandra.io.compress.NoopCompressor; +import org.apache.cassandra.io.compress.SnappyCompressor; +import org.apache.cassandra.io.compress.ZstdCompressor; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.service.StorageService; + +import static com.google.common.base.Charsets.UTF_8; +import static java.lang.String.format; +import static org.apache.cassandra.distributed.api.Feature.GOSSIP; +import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL; +import static org.apache.cassandra.distributed.api.Feature.NETWORK; +import static org.apache.cassandra.distributed.test.ExecUtil.rethrow; +import static org.apache.cassandra.schema.SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES; +import static org.apache.cassandra.schema.SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMES; +import static org.apache.commons.io.FileUtils.readFileToString; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +public class SSTableCompressionTest +{ + static Cluster CLUSTER; + static String NODES; + static int NATIVE_PORT; + static int STORAGE_PORT; + static int SSL_STORAGE_PORT; + + private static final String FAST_PARAM = "WITH compression = {'class': 'SnappyCompressor'}"; + private static final String SLOW_PARAM = "WITH compression = {'class': 'DeflateCompressor'}"; + private static final String DEFAULT_PARAM = ""; + + private static final String KEYSPACE = "sstable_compression_test"; + + private static final Consumer<IInstanceConfig> DEFAULT_CONFIG = c -> { + c.with(NATIVE_PROTOCOL, NETWORK, GOSSIP); // need gossip to get hostid for Java driver + c.set("flush_compression", "fast"); // this is default + c.set("sstable_compression", ImmutableMap.builder().put("class_name", "lz4").build()); + }; + + private static final Consumer<IInstanceConfig> FAST_CONFIG = c -> { + c.with(NATIVE_PROTOCOL, NETWORK, GOSSIP); // need gossip to get hostid for Java driver + c.set("flush_compression", "fast"); // this is default + c.set("sstable_compression", ImmutableMap.builder().put("class_name", "snappy").build()); + }; + + private static final Consumer<IInstanceConfig> SLOW_CONFIG = c -> { + c.with(NATIVE_PROTOCOL, NETWORK, GOSSIP); // need gossip to get hostid for Java driver + c.set("flush_compression", "fast"); // this is default + c.set("sstable_compression", ImmutableMap.builder().put("class_name", "deflate").build()); + }; + + private static final Consumer<IInstanceConfig> ZSTD_CONFIG = c -> { + c.with(NATIVE_PROTOCOL, NETWORK, GOSSIP); // need gossip to get hostid for Java driver + c.set("flush_compression", "fast"); // this is default + c.set("sstable_compression", ImmutableMap.builder().put("class_name", "zstd").build()); + }; + + public static Path setupCluster(Consumer<IInstanceConfig> config, Path root) throws IOException + { + Cluster.Builder builder = Cluster.build().withNodes(1).withConfig(config); + + if (root != null) + builder.withRoot(root); + + CLUSTER = builder.start(); + NODES = CLUSTER.get(1).config().broadcastAddress().getHostString(); + NATIVE_PORT = CLUSTER.get(1).callOnInstance(DatabaseDescriptor::getNativeTransportPort); + STORAGE_PORT = CLUSTER.get(1).callOnInstance(DatabaseDescriptor::getStoragePort); + SSL_STORAGE_PORT = CLUSTER.get(1).callOnInstance(DatabaseDescriptor::getSSLStoragePort); + + return builder.getRootPath(); + } + + public static void tearDownCluster() + { + if (CLUSTER != null) + CLUSTER.close(); + } + + @Test + public void testCreation() throws IOException + { + // create clauster with lz4 compression Review Comment: typo -- 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]

