BlockListAsLongs implements Iterable<BlockReportReplica> { abstract public long[] getBlockListAsLongs();  static BlockListAsLongs decodeBuffer(final int numBlocks,
      final ByteString blocksBuf, final int maxDataLength); @VisibleForTesting static BlockListAsLongs decodeBuffers(final int numBlocks,
      final List<ByteString> blocksBufs); static BlockListAsLongs decodeBuffers(final int numBlocks,
      final List<ByteString> blocksBufs, final int maxDataLength); static BlockListAsLongs decodeLongs(List<Long> blocksList); static BlockListAsLongs decodeLongs(List<Long> blocksList,
      int maxDataLength); @VisibleForTesting static BlockListAsLongs encode(
      final Collection<? extends Replica> replicas); static BlockListAsLongs readFrom(InputStream is, int maxDataLength); void writeTo(OutputStream os); @VisibleForTesting static Builder builder(); static Builder builder(int maxDataLength); abstract int getNumberOfBlocks(); abstract ByteString getBlocksBuffer(); List<ByteString> getBlocksBuffers(); abstract long[] getBlockListAsLongs(); abstract Iterator<BlockReportReplica> iterator(); static BlockListAsLongs EMPTY; }
@Test public void testEmptyReport() { BlockListAsLongs blocks = checkReport(); assertArrayEquals( new long[] { 0, 0, -1, -1, -1 }, blocks.getBlockListAsLongs()); }
@Test public void testFinalized() { BlockListAsLongs blocks = checkReport( new FinalizedReplica(b1, null, null)); assertArrayEquals( new long[] { 1, 0, 1, 11, 111, -1, -1, -1 }, blocks.getBlockListAsLongs()); }
@Test public void testUc() { BlockListAsLongs blocks = checkReport( new ReplicaBeingWritten(b1, null, null, null)); assertArrayEquals( new long[] { 0, 1, -1, -1, -1, 1, 11, 111, ReplicaState.RBW.getValue() }, blocks.getBlockListAsLongs()); }
@Test public void testMix() { BlockListAsLongs blocks = checkReport( new FinalizedReplica(b1, null, null), new FinalizedReplica(b2, null, null), new ReplicaBeingWritten(b3, null, null, null), new ReplicaWaitingToBeRecovered(b4, null, null)); assertArrayEquals( new long[] { 2, 2, 1, 11, 111, 2, 22, 222, -1, -1, -1, 3, 33, 333, ReplicaState.RBW.getValue(), 4, 44, 444, ReplicaState.RWR.getValue() }, blocks.getBlockListAsLongs()); }