/* * 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 org.apache.cassandra.SchemaLoader; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.ConsistencyLevel; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.gms.Gossiper; import org.apache.cassandra.service.ClientState; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import static org.apache.cassandra.cql3.QueryProcessor.process; import static org.junit.Assert.assertEquals; public class AlterTableTest { private static final String KEYSPACE = "alter_table_test"; static ClientState clientState; @BeforeClass public static void setUpClass() throws Throwable { SchemaLoader.loadSchema(); executeSchemaChange("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}"); clientState = ClientState.forInternalCalls(); } @AfterClass public static void stopGossiper() { Gossiper.instance.stop(); } private static void executeSchemaChange(String query) throws Throwable { try { process(String.format(query, KEYSPACE), ConsistencyLevel.ONE); } catch (RuntimeException exc) { throw exc.getCause(); } } @Test // tests CASSANDRA-7976 public void testAlterIndexInterval() throws Throwable { executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.songs (id uuid, album text, artist text, data blob, PRIMARY KEY (id))"); ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore("songs"); executeSchemaChange("ALTER TABLE %s.songs WITH index_interval=256"); assertEquals(256, cfs.metadata.getIndexInterval()); executeSchemaChange("ALTER TABLE %s.songs WITH caching = 'none'"); assertEquals(256, cfs.metadata.getIndexInterval()); }}