Search in sources :

Example 1 with FieldIdentifier

use of org.apache.cassandra.cql3.FieldIdentifier in project cassandra by apache.

the class CellTest method testValidateNonFrozenUDT.

@Test
public void testValidateNonFrozenUDT() {
    // has field position 0
    FieldIdentifier f1 = field("f1");
    // has field position 1
    FieldIdentifier f2 = field("f2");
    UserType udt = new UserType("ks", bb("myType"), asList(f1, f2), asList(Int32Type.instance, UTF8Type.instance), true);
    ColumnMetadata c;
    // Valid cells
    c = fakeColumn("c", udt);
    assertValid(BufferCell.live(c, 0, bb(1), CellPath.create(bbs(0))));
    assertValid(BufferCell.live(c, 0, bb("foo"), CellPath.create(bbs(1))));
    assertValid(BufferCell.expiring(c, 0, 4, 4, bb(1), CellPath.create(bbs(0))));
    assertValid(BufferCell.expiring(c, 0, 4, 4, bb("foo"), CellPath.create(bbs(1))));
    assertValid(BufferCell.tombstone(c, 0, 4, CellPath.create(bbs(0))));
    // Invalid value (text in an int field)
    assertInvalid(BufferCell.live(c, 0, bb("foo"), CellPath.create(bbs(0))));
    // Invalid ttl
    assertInvalid(BufferCell.expiring(c, 0, -4, 4, bb(1), CellPath.create(bbs(0))));
    // Invalid local deletion times
    assertInvalid(BufferCell.expiring(c, 0, 4, -5, bb(1), CellPath.create(bbs(0))));
    assertInvalid(BufferCell.expiring(c, 0, 4, Cell.NO_DELETION_TIME, bb(1), CellPath.create(bbs(0))));
    // Invalid cell path (int values should be 0 or 2 bytes)
    assertInvalid(BufferCell.live(c, 0, bb(1), CellPath.create(ByteBufferUtil.bytes((long) 4))));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) FieldIdentifier(org.apache.cassandra.cql3.FieldIdentifier) Test(org.junit.Test)

Example 2 with FieldIdentifier

use of org.apache.cassandra.cql3.FieldIdentifier in project cassandra by apache.

the class CellTest method testValidateFrozenUDT.

@Test
public void testValidateFrozenUDT() {
    // has field position 0
    FieldIdentifier f1 = field("f1");
    // has field position 1
    FieldIdentifier f2 = field("f2");
    UserType udt = new UserType("ks", bb("myType"), asList(f1, f2), asList(Int32Type.instance, UTF8Type.instance), false);
    ColumnMetadata c = fakeColumn("c", udt);
    ByteBuffer val = udt(bb(1), bb("foo"));
    // Valid cells
    assertValid(BufferCell.live(c, 0, val));
    assertValid(BufferCell.live(c, 0, val));
    assertValid(BufferCell.expiring(c, 0, 4, 4, val));
    assertValid(BufferCell.expiring(c, 0, 4, 4, val));
    assertValid(BufferCell.tombstone(c, 0, 4));
    // fewer values than types is accepted
    assertValid(BufferCell.live(c, 0, udt(bb(1))));
    // Invalid values
    // invalid types
    assertInvalid(BufferCell.live(c, 0, udt(bb("foo"), bb(1))));
    // too many types
    assertInvalid(BufferCell.live(c, 0, udt(bb(1), bb("foo"), bb("bar"))));
    // Invalid ttl
    assertInvalid(BufferCell.expiring(c, 0, -4, 4, val));
    // Invalid local deletion times
    assertInvalid(BufferCell.expiring(c, 0, 4, -5, val));
    assertInvalid(BufferCell.expiring(c, 0, 4, Cell.NO_DELETION_TIME, val));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) FieldIdentifier(org.apache.cassandra.cql3.FieldIdentifier) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

FieldIdentifier (org.apache.cassandra.cql3.FieldIdentifier)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1