Exemplo n.º 1
0
  @Test
  public void testSerializeDeserialize() throws IOException {
    CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 2);
    state.writeElement(NodeId.fromInt(1), 4L, 4L);
    state.writeElement(NodeId.fromInt(2), 4L, 4L, true);
    state.writeElement(NodeId.fromInt(3), 4L, 4L);
    state.writeElement(NodeId.fromInt(4), 4L, 4L, true);

    CounterColumn original = new CounterColumn(ByteBufferUtil.bytes("x"), state.context, 1L);
    DataOutputBuffer bufOut = new DataOutputBuffer();
    Column.serializer().serialize(original, bufOut);
    byte[] serialized = bufOut.getData();

    ByteArrayInputStream bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterColumn deserialized =
        (CounterColumn) Column.serializer().deserialize(new DataInputStream(bufIn));
    assert original.equals(deserialized);

    bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterColumn deserializedOnRemote =
        (CounterColumn) Column.serializer().deserialize(new DataInputStream(bufIn), null, true);
    assert deserializedOnRemote.name().equals(original.name());
    assert deserializedOnRemote.total() == original.total();
    assert deserializedOnRemote.value().equals(cc.clearAllDelta(original.value()));
    assert deserializedOnRemote.timestamp() == deserialized.timestamp();
    assert deserializedOnRemote.timestampOfLastDelete() == deserialized.timestampOfLastDelete();
  }
Exemplo n.º 2
0
  @Test
  public void testCreate() throws UnknownHostException {
    long delta = 3L;
    CounterUpdateColumn cuc = new CounterUpdateColumn(ByteBufferUtil.bytes("x"), delta, 1L);
    CounterColumn column = cuc.localCopy(Table.open("Keyspace5").getColumnFamilyStore("Counter1"));

    assert delta == column.total();
    assert 1 == column.value().getShort(0);
    assert 0 == column.value().getShort(2);
    assert NodeId.wrap(column.value(), 4).isLocalId();
    assert 1L == column.value().getLong(4 + 0 * stepLength + idLength);
    assert delta == column.value().getLong(4 + 0 * stepLength + idLength + clockLength);
  }