Esempio 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();
  }
Esempio n. 2
0
  @Test
  public void testUpdateDigest() throws Exception {
    MessageDigest digest1 = MessageDigest.getInstance("md5");
    MessageDigest digest2 = MessageDigest.getInstance("md5");

    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);
    CounterColumn cleared =
        new CounterColumn(ByteBufferUtil.bytes("x"), cc.clearAllDelta(state.context), 1L);

    original.updateDigest(digest1);
    cleared.updateDigest(digest2);

    assert Arrays.equals(digest1.digest(), digest2.digest());
  }
Esempio n. 3
0
 // In 2.1 only used by the unit tests.
 public void writeLocal(CounterId id, long clock, long count) {
   writeElement(id, clock, count, false, true);
 }
Esempio n. 4
0
 // In 2.1 only used by the unit tests.
 public void writeRemote(CounterId id, long clock, long count) {
   writeElement(id, clock, count, false, false);
 }
Esempio n. 5
0
 public void writeGlobal(CounterId id, long clock, long count) {
   writeElement(id, clock, count, true, false);
 }