|
22 | 22 | import org.junit.runner.RunWith;
|
23 | 23 | import org.junit.runners.Parameterized;
|
24 | 24 |
|
| 25 | +import com.datastax.driver.core.exceptions.InvalidQueryException; |
25 | 26 | import org.apache.cassandra.cql3.CQLTester;
|
26 | 27 | import org.apache.cassandra.exceptions.ConfigurationException;
|
| 28 | +import org.apache.cassandra.index.sai.disk.format.Version; |
| 29 | +import org.apache.cassandra.schema.SchemaConstants; |
27 | 30 |
|
28 | 31 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 32 | +import static org.junit.Assert.assertEquals; |
29 | 33 |
|
30 | 34 | @RunWith(Parameterized.class)
|
31 | 35 | public class IndexNameTest extends CQLTester
|
@@ -121,4 +125,51 @@ public void failOnBadCharIndexName()
|
121 | 125 | assertThatThrownBy(() -> execute(String.format(createIndexQuery, "\"unacceptable index name\"", "%s", columnName)))
|
122 | 126 | .isInstanceOf(ConfigurationException.class);
|
123 | 127 | }
|
| 128 | + |
| 129 | + @Test |
| 130 | + public void testTooLongNamesInternal() throws Throwable |
| 131 | + { |
| 132 | + String longName = "a".repeat(183); |
| 133 | + |
| 134 | + createTable("CREATE TABLE %s (" + |
| 135 | + "key int PRIMARY KEY," + |
| 136 | + "value int)" |
| 137 | + ); |
| 138 | + createIndex(String.format(createIndexQuery, longName, "%s", "value")); |
| 139 | + execute(String.format("INSERT INTO %%s (\"key\", %s) VALUES (1, 1)", "value")); |
| 140 | + execute(String.format("INSERT INTO %%s (\"key\", %s) VALUES (2, 2)", "value")); |
| 141 | + |
| 142 | + beforeAndAfterFlush(() -> assertRows(execute(String.format("SELECT key, %s FROM %%s WHERE %<s = 1", "value")), row(1, 1))); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void testMaxAcceptableLongNamesNewIndex() throws Throwable |
| 147 | + { |
| 148 | + assertEquals(182, Version.calculateIndexNameAllowedLength()); |
| 149 | + String longName = "a".repeat(182); |
| 150 | + createTable("CREATE TABLE %s (" + |
| 151 | + "key int PRIMARY KEY," + |
| 152 | + "value int)" |
| 153 | + ); |
| 154 | + executeNet(String.format(createIndexQuery, longName, "%s", "value")); |
| 155 | + |
| 156 | + execute(String.format("INSERT INTO %%s (\"key\", %s) VALUES (1, 1)", "value")); |
| 157 | + execute(String.format("INSERT INTO %%s (\"key\", %s) VALUES (2, 2)", "value")); |
| 158 | + |
| 159 | + beforeAndAfterFlush(() -> assertRows(execute(String.format("SELECT key, %s FROM %%s WHERE %<s = 1", "value")), row(1, 1))); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + public void failTooLongNamesNewIndex() |
| 164 | + { |
| 165 | + String longName = "a".repeat(183); |
| 166 | + createTable("CREATE TABLE %s (" + |
| 167 | + "key int PRIMARY KEY," + |
| 168 | + "value int)" |
| 169 | + ); |
| 170 | + assertThatThrownBy(() -> executeNet(String.format(createIndexQuery, longName, "%s", "value"))) |
| 171 | + .isInstanceOf(InvalidQueryException.class) |
| 172 | + .hasMessage(String.format("Index name shouldn't be more than %s characters long (got %s chars for %s)", |
| 173 | + SchemaConstants.INDEX_NAME_LENGTH, longName.length(), longName)); |
| 174 | + } |
124 | 175 | }
|
0 commit comments