Adds test for CASSANDRA-7978
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/c2c9835f Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/c2c9835f Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/c2c9835f Branch: refs/heads/trunk Commit: c2c9835f7a431d4d267e501f6b31fdc7a7e0b5fc Parents: 3fd90ae Author: Jake Luciani <j...@apache.org> Authored: Tue Sep 23 12:42:11 2014 -0400 Committer: Jake Luciani <j...@apache.org> Committed: Tue Sep 23 12:42:11 2014 -0400 ---------------------------------------------------------------------- .../org/apache/cassandra/cql3/CQLTester.java | 2 +- .../cassandra/cql3/CrcCheckChanceTest.java | 70 ++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/c2c9835f/test/unit/org/apache/cassandra/cql3/CQLTester.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java index e776fc7..236a9ff 100644 --- a/test/unit/org/apache/cassandra/cql3/CQLTester.java +++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java @@ -54,7 +54,7 @@ public abstract class CQLTester { protected static final Logger logger = LoggerFactory.getLogger(CQLTester.class); - private static final String KEYSPACE = "cql_test_keyspace"; + public static final String KEYSPACE = "cql_test_keyspace"; private static final boolean USE_PREPARED_VALUES = Boolean.valueOf(System.getProperty("cassandra.test.use_prepared", "true")); private static final AtomicInteger seqNumber = new AtomicInteger(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/c2c9835f/test/unit/org/apache/cassandra/cql3/CrcCheckChanceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/CrcCheckChanceTest.java b/test/unit/org/apache/cassandra/cql3/CrcCheckChanceTest.java new file mode 100644 index 0000000..0cd9202 --- /dev/null +++ b/test/unit/org/apache/cassandra/cql3/CrcCheckChanceTest.java @@ -0,0 +1,70 @@ +/* + * 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.cql3; + +import junit.framework.Assert; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.Keyspace; +import org.junit.Test; + + +public class CrcCheckChanceTest extends CQLTester +{ + @Test + public void testChangingCrcCheckChance() throws Throwable + { + //Start with crc_check_chance of 99% + createTable("CREATE TABLE %s (p text, c text, v text, s text static, PRIMARY KEY (p, c)) WITH compression = {'sstable_compression': 'LZ4Compressor', 'crc_check_chance' : 0.99}"); + + execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1"); + execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2"); + execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2"); + + + ColumnFamilyStore cfs = Keyspace.open(CQLTester.KEYSPACE).getColumnFamilyStore(currentTable()); + cfs.forceBlockingFlush(); + + Assert.assertEquals(0.99, cfs.metadata.compressionParameters.getCrcCheckChance()); + Assert.assertEquals(0.99, cfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance()); + + assertRows(execute("SELECT * FROM %s WHERE p=?", "p1"), + row("p1", "k1", "sv1", "v1"), + row("p1", "k2", "sv1", "v2") + ); + + + //Verify when we alter the value the live sstable readers hold the new one + alterTable("ALTER TABLE %s WITH compression = {'sstable_compression': 'LZ4Compressor', 'crc_check_chance': 0.01}"); + + Assert.assertEquals( 0.01, cfs.metadata.compressionParameters.getCrcCheckChance()); + Assert.assertEquals( 0.01, cfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance()); + + assertRows(execute("SELECT * FROM %s WHERE p=?", "p1"), + row("p1", "k1", "sv1", "v1"), + row("p1", "k2", "sv1", "v2") + ); + + + //Verify the call used by JMX still works + cfs.setCrcCheckChance(0.03); + Assert.assertEquals( 0.03, cfs.metadata.compressionParameters.getCrcCheckChance()); + Assert.assertEquals( 0.03, cfs.getSSTables().iterator().next().getCompressionMetadata().parameters.getCrcCheckChance()); + + } +} +