Skip to content

CASSANDRA-20733: fixed the abstract type meaningless emptyness test that failed because a type defined emptyness in a meaningless way #4216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,9 @@ public void meaninglessEmptyness()
continue;
if (type.isEmptyValueMeaningless())
{
AbstractType<?> finalType = type;
// some types (such as TimeUUID) have the same equqlas, so equality checks don't work here, need reference checks
Assertions.assertThat(AbstractTypeGenerators.MEANINGLESS_EMPTYNESS)
Assertions.assertThat(AbstractTypeGenerators.supportsMeaninglessEmptyness(type))
.describedAs("New type %s detected that says its emptyness is meaningless, but it isn't allowed to be! This is a legacy concept only!", type.getClass())
.anyMatch(t -> t == finalType);
.isTrue();

Assertions.assertThat(type.isNull(ByteBufferUtil.EMPTY_BYTE_BUFFER)).isTrue();
}
Expand All @@ -314,7 +312,7 @@ public void meaninglessEmptyness()
@Test
public void onlyMeaninglessEmptyness()
{
qt().forAll(Generators.filter(AbstractTypeGenerators.builder().withDefaultSizeGen(1).build(), t -> !AbstractTypeGenerators.MEANINGLESS_EMPTYNESS.contains(t))).checkAssert(type -> {
qt().forAll(Generators.filter(AbstractTypeGenerators.builder().withDefaultSizeGen(1).build(), t -> !AbstractTypeGenerators.supportsMeaninglessEmptyness(t))).checkAssert(type -> {
Assertions.assertThat(type.isEmptyValueMeaningless()).isFalse();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void isNullWithNullColumn()
@Test
public void harryPotterAndTheMeaninglessEmptyness()
{
for (var type : AbstractTypeGenerators.MEANINGLESS_EMPTYNESS)
for (var type : AbstractTypeGenerators.meaninglessEmptyness())
{
if (type == CounterColumnType.instance) continue;
TableMetadata metadata = TableMetadata.builder("ks", "tbl")
Expand Down
19 changes: 18 additions & 1 deletion test/unit/org/apache/cassandra/utils/AbstractTypeGenerators.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import javax.annotation.Nullable;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -186,7 +187,7 @@ public static List<AbstractType<?>> knownPrimitiveTypes()
.build();
// NEVER EVER EVER UPDATE THIS LIST!
// meaningless emptyness is a legacy thrift concept, so only types from back then apply and all new types will never apply
public static final ImmutableUniqueList<AbstractType<?>> MEANINGLESS_EMPTYNESS = ImmutableUniqueList.of(
private static final ImmutableList<AbstractType<?>> MEANINGLESS_EMPTYNESS = ImmutableList.of(
CounterColumnType.instance,

BooleanType.instance,
Expand All @@ -209,6 +210,22 @@ public static List<AbstractType<?>> knownPrimitiveTypes()
LongType.instance
);

public static Iterable<AbstractType<?>> meaninglessEmptyness()
{
return MEANINGLESS_EMPTYNESS;
}

public static boolean supportsMeaninglessEmptyness(AbstractType<?> type)
{
// Why list iteration rather than contains? Because equality is hard... and some types like to do things like
// public boolean equals(Object obj) { return obj instanceof AbstractTimeUUIDType<?>; }
for (var t : meaninglessEmptyness())
{
if (t == type) return true;
}
return false;
}

private AbstractTypeGenerators()
{

Expand Down
13 changes: 10 additions & 3 deletions test/unit/org/apache/cassandra/utils/ImmutableUniqueList.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public static <T> ImmutableUniqueList<T> of(T... values)
{
Builder<T> builder = builder(values.length);
for (T v : values)
builder.add(v);
if (!builder.maybeAdd(v))
throw new IllegalArgumentException("Unable to add " + v + " as its a duplicate");
return builder.build();
}

Expand Down Expand Up @@ -123,12 +124,18 @@ public Builder(int expectedSize)
this.values = new ArrayList<>(expectedSize);
}

public Builder<T> add(T t)
public boolean maybeAdd(T t)
{
if (indexLookup.containsKey(t)) return this;
if (indexLookup.containsKey(t)) return false;
int idx = this.idx++;
indexLookup.put(t, idx);
values.add(t);
return true;
}

public Builder<T> add(T t)
{
maybeAdd(t);
return this;
}

Expand Down