Add more tests for CASSANDRA-16905

patch by Stefan Miklosovic; reviewed by Andres de la Peña for CASSANDRA-18760
This commit is contained in:
Stefan Miklosovic 2023-08-17 15:19:28 +02:00
parent f0280fb6f8
commit 65a3d36eb9
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
1 changed files with 56 additions and 8 deletions

View File

@ -35,6 +35,41 @@ import static org.junit.Assert.assertEquals;
public class AlterTest extends CQLTester
{
@Test
public void testNonFrozenCollectionsAreIncompatibleWithBlob() throws Throwable
{
String[] collectionTypes = new String[] {"map<int, int>", "set<int>", "list<int>"};
for (String type : collectionTypes)
{
createTable("CREATE TABLE %s (a int, b " + type + ", PRIMARY KEY (a));");
alterTable("ALTER TABLE %s DROP b;");
assertInvalidMessage("Cannot re-add previously dropped column 'b' of type blob, incompatible with previous type " + type,
"ALTER TABLE %s ADD b blob;");
}
for (String type : collectionTypes)
{
createTable("CREATE TABLE %s (a int, b blob, PRIMARY KEY (a));");
alterTable("ALTER TABLE %s DROP b;");
assertInvalidMessage("Cannot re-add previously dropped column 'b' of type " + type + ", incompatible with previous type blob",
"ALTER TABLE %s ADD b " + type + ';');
}
}
@Test
public void testFrozenCollectionsAreCompatibleWithBlob()
{
String[] collectionTypes = new String[] {"frozen<map<int, int>>", "frozen<set<int>>", "frozen<list<int>>"};
for (String type : collectionTypes)
{
createTable("CREATE TABLE %s (a int, b " + type + ", PRIMARY KEY (a));");
alterTable("ALTER TABLE %s DROP b;");
alterTable("ALTER TABLE %s ADD b blob;");
}
}
@Test
public void testAddList() throws Throwable
{
@ -338,6 +373,27 @@ public class AlterTest extends CQLTester
execute("ALTER TABLE %s RENAME c1 TO \"\"");
}
@Test
public void testInvalidDroppingAndAddingOfCollections() throws Throwable
{
for (String[] typePair : new String[][]
{
new String[] {"list<int>", "list<varint>"},
new String[] {"set<int>", "set<varint>"},
new String[] {"map<int, int>", "map<varint, varint>"},
new String[] {"list<int>", "frozen<list<varint>>"},
new String[] {"set<int>", "frozen<set<varint>>"},
new String[] {"map<int, int>", "frozen<map<varint, varint>>"},
})
{
createTable("create table %s (k int, c int, v " + typePair[0] + ", PRIMARY KEY (k, c))");
execute("alter table %s drop v");
assertInvalidMessage("Cannot re-add previously dropped column 'v' of type "
+ typePair[1] + ", incompatible with previous type " + typePair[0],
"alter table %s add v " + typePair[1]);
}
}
@Test(expected = InvalidRequestException.class)
public void testDropFixedAddVariable() throws Throwable
{
@ -346,14 +402,6 @@ public class AlterTest extends CQLTester
execute("alter table %s add v varint");
}
@Test(expected = InvalidRequestException.class)
public void testDropFixedCollectionAddVariableCollection() throws Throwable
{
createTable("create table %s (k int, c int, v list<int>, PRIMARY KEY (k, c))");
execute("alter table %s drop v");
execute("alter table %s add v list<varint>");
}
@Test(expected = InvalidRequestException.class)
public void testDropSimpleAddComplex() throws Throwable
{