@Test
  public void testGetColumn() throws IOException, ColumnFamilyNotDefinedException {
    Table table = Table.open("Keyspace1");
    RowMutation rm;

    // add data
    rm = new RowMutation("Keyspace1", "key1");
    rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "abcd".getBytes(), 0);
    rm.apply();

    ReadCommand command =
        new SliceByNamesReadCommand(
            "Keyspace1", "key1", new QueryPath("Standard1"), Arrays.asList("Column1".getBytes()));
    Row row = command.getRow(table);
    IColumn col = row.cf.getColumn("Column1".getBytes());
    assert Arrays.equals(col.value(), "abcd".getBytes());
  }
Exemplo n.º 2
0
  @Test
  public void testReconcile() throws UnknownHostException {
    IColumn left;
    IColumn right;
    IColumn reconciled;

    ByteBuffer context;

    // tombstone + tombstone
    left = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 1L);
    right = new DeletedColumn(ByteBufferUtil.bytes("x"), 2, 2L);

    assert left.reconcile(right).getMarkedForDeleteAt() == right.getMarkedForDeleteAt();
    assert right.reconcile(left).getMarkedForDeleteAt() == right.getMarkedForDeleteAt();

    // tombstone > live
    left = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 2L);
    right = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 1L);

    assert left.reconcile(right) == left;

    // tombstone < live last delete
    left = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 1L);
    right = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 4L, 2L);

    assert left.reconcile(right) == right;

    // tombstone == live last delete
    left = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 2L);
    right = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 4L, 2L);

    assert left.reconcile(right) == right;

    // tombstone > live last delete
    left = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 4L);
    right = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 9L, 1L);

    reconciled = left.reconcile(right);
    assert reconciled.name() == right.name();
    assert reconciled.value() == right.value();
    assert reconciled.timestamp() == right.timestamp();
    assert ((CounterColumn) reconciled).timestampOfLastDelete() == left.getMarkedForDeleteAt();

    // live < tombstone
    left = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 1L);
    right = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 2L);

    assert left.reconcile(right) == right;

    // live last delete > tombstone
    left = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 4L, 2L);
    right = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 1L);

    assert left.reconcile(right) == left;

    // live last delete == tombstone
    left = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 4L, 2L);
    right = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 2L);

    assert left.reconcile(right) == left;

    // live last delete < tombstone
    left = new CounterColumn(ByteBufferUtil.bytes("x"), 0L, 9L, 1L);
    right = new DeletedColumn(ByteBufferUtil.bytes("x"), 1, 4L);

    reconciled = left.reconcile(right);
    assert reconciled.name() == left.name();
    assert reconciled.value() == left.value();
    assert reconciled.timestamp() == left.timestamp();
    assert ((CounterColumn) reconciled).timestampOfLastDelete() == right.getMarkedForDeleteAt();

    // live < live last delete
    left =
        new CounterColumn(
            ByteBufferUtil.bytes("x"),
            cc.create(NodeId.fromInt(1), 2L, 3L, false),
            1L,
            Long.MIN_VALUE);
    right =
        new CounterColumn(
            ByteBufferUtil.bytes("x"), cc.create(NodeId.fromInt(1), 1L, 1L, false), 4L, 3L);

    assert left.reconcile(right) == right;

    // live last delete > live
    left =
        new CounterColumn(
            ByteBufferUtil.bytes("x"), cc.create(NodeId.fromInt(1), 2L, 3L, false), 6L, 5L);
    right =
        new CounterColumn(
            ByteBufferUtil.bytes("x"), cc.create(NodeId.fromInt(1), 1L, 1L, false), 4L, 3L);

    assert left.reconcile(right) == left;

    // live + live
    left =
        new CounterColumn(
            ByteBufferUtil.bytes("x"),
            cc.create(NodeId.fromInt(1), 1L, 1L, false),
            4L,
            Long.MIN_VALUE);
    right =
        new CounterColumn(
            ByteBufferUtil.bytes("x"),
            cc.create(NodeId.fromInt(1), 2L, 3L, false),
            1L,
            Long.MIN_VALUE);

    reconciled = left.reconcile(right);
    assert reconciled.name().equals(left.name());
    assert ((CounterColumn) reconciled).total() == 3L;
    assert reconciled.timestamp() == 4L;

    left = reconciled;
    right =
        new CounterColumn(
            ByteBufferUtil.bytes("x"),
            cc.create(NodeId.fromInt(2), 1L, 5L, false),
            2L,
            Long.MIN_VALUE);

    reconciled = left.reconcile(right);
    assert reconciled.name().equals(left.name());
    assert ((CounterColumn) reconciled).total() == 8L;
    assert reconciled.timestamp() == 4L;

    left = reconciled;
    right =
        new CounterColumn(
            ByteBufferUtil.bytes("x"),
            cc.create(NodeId.fromInt(2), 2L, 2L, false),
            6L,
            Long.MIN_VALUE);

    reconciled = left.reconcile(right);
    assert reconciled.name().equals(left.name());
    assert ((CounterColumn) reconciled).total() == 5L;
    assert reconciled.timestamp() == 6L;

    context = reconciled.value();
    int hd = 2; // header
    assert hd + 2 * stepLength == context.remaining();

    assert Util.equalsNodeId(NodeId.fromInt(1), context, hd + 0 * stepLength);
    assert 2L == context.getLong(hd + 0 * stepLength + idLength);
    assert 3L == context.getLong(hd + 0 * stepLength + idLength + clockLength);

    assert Util.equalsNodeId(NodeId.fromInt(2), context, hd + 1 * stepLength);
    assert 2L == context.getLong(hd + 1 * stepLength + idLength);
    assert 2L == context.getLong(hd + 1 * stepLength + idLength + clockLength);

    assert ((CounterColumn) reconciled).timestampOfLastDelete() == Long.MIN_VALUE;
  }