Search in sources :

Example 1 with SchemaChange

use of org.apache.cassandra.transport.Event.SchemaChange in project cassandra by apache.

the class SerDeserTest method eventSerDeserTest.

public void eventSerDeserTest(ProtocolVersion version) throws Exception {
    List<Event> events = new ArrayList<>();
    events.add(TopologyChange.newNode(FBUtilities.getBroadcastAddress(), 42));
    events.add(TopologyChange.removedNode(FBUtilities.getBroadcastAddress(), 42));
    events.add(TopologyChange.movedNode(FBUtilities.getBroadcastAddress(), 42));
    events.add(StatusChange.nodeUp(FBUtilities.getBroadcastAddress(), 42));
    events.add(StatusChange.nodeDown(FBUtilities.getBroadcastAddress(), 42));
    events.add(new SchemaChange(SchemaChange.Change.CREATED, "ks"));
    events.add(new SchemaChange(SchemaChange.Change.UPDATED, "ks"));
    events.add(new SchemaChange(SchemaChange.Change.DROPPED, "ks"));
    events.add(new SchemaChange(SchemaChange.Change.CREATED, SchemaChange.Target.TABLE, "ks", "table"));
    events.add(new SchemaChange(SchemaChange.Change.UPDATED, SchemaChange.Target.TABLE, "ks", "table"));
    events.add(new SchemaChange(SchemaChange.Change.DROPPED, SchemaChange.Target.TABLE, "ks", "table"));
    if (version.isGreaterOrEqualTo(ProtocolVersion.V3)) {
        events.add(new SchemaChange(SchemaChange.Change.CREATED, SchemaChange.Target.TYPE, "ks", "type"));
        events.add(new SchemaChange(SchemaChange.Change.UPDATED, SchemaChange.Target.TYPE, "ks", "type"));
        events.add(new SchemaChange(SchemaChange.Change.DROPPED, SchemaChange.Target.TYPE, "ks", "type"));
    }
    if (version.isGreaterOrEqualTo(ProtocolVersion.V4)) {
        List<String> moreTypes = Arrays.asList("text", "bigint");
        events.add(new SchemaChange(SchemaChange.Change.CREATED, SchemaChange.Target.FUNCTION, "ks", "func", Collections.<String>emptyList()));
        events.add(new SchemaChange(SchemaChange.Change.UPDATED, SchemaChange.Target.FUNCTION, "ks", "func", moreTypes));
        events.add(new SchemaChange(SchemaChange.Change.DROPPED, SchemaChange.Target.FUNCTION, "ks", "func", moreTypes));
        events.add(new SchemaChange(SchemaChange.Change.CREATED, SchemaChange.Target.AGGREGATE, "ks", "aggr", Collections.<String>emptyList()));
        events.add(new SchemaChange(SchemaChange.Change.UPDATED, SchemaChange.Target.AGGREGATE, "ks", "aggr", moreTypes));
        events.add(new SchemaChange(SchemaChange.Change.DROPPED, SchemaChange.Target.AGGREGATE, "ks", "aggr", moreTypes));
    }
    for (Event ev : events) {
        ByteBuf buf = Unpooled.buffer(ev.serializedSize(version));
        ev.serialize(buf, version);
        assertEquals(ev, Event.deserialize(buf, version));
    }
}
Also used : SchemaChange(org.apache.cassandra.transport.Event.SchemaChange) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 SchemaChange (org.apache.cassandra.transport.Event.SchemaChange)1