Package org.apache.hadoop.hbase.util

Examples of org.apache.hadoop.hbase.util.PositionedByteRange


   */
  @Override
  public int encode(PositionedByteRange dst, T val) {
    final int start = dst.getPosition();
    int written = wrapped.encode(dst, val);
    PositionedByteRange b = dst.shallowCopy();
    b.setLength(dst.getPosition());
    b.setPosition(start);
    if (-1 != terminatorPosition(b)) {
      dst.setPosition(start);
      throw new IllegalArgumentException("Encoded value contains terminator sequence.");
    }
    dst.put(term);
View Full Code Here


  static final int[] limits = { 9, 12, 15 };

  @Test
  public void testReadWrite() {
    for (int limit : limits) {
      PositionedByteRange buff = new SimplePositionedByteRange(limit);
      for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
        for (byte[] val : VALUES) {
          buff.setPosition(0);
          DataType<byte[]> type = new FixedLengthWrapper<byte[]>(new RawBytes(ord), limit);
          assertEquals(limit, type.encode(buff, val));
          byte[] expected = Arrays.copyOf(val, limit);
          buff.setPosition(0);
          byte[] actual = type.decode(buff);
          assertArrayEquals(expected, actual);
          buff.setPosition(0);
          assertEquals(limit, type.skip(buff));
        }
      }
    }
  }
View Full Code Here

    }
  }

  @Test(expected = IllegalArgumentException.class)
  public void testInsufficientRemainingRead() {
    PositionedByteRange buff = new SimplePositionedByteRange(0);
    DataType<byte[]> type = new FixedLengthWrapper<byte[]>(new RawBytes(), 3);
    type.decode(buff);
  }
View Full Code Here

    type.decode(buff);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testInsufficientRemainingWrite() {
    PositionedByteRange buff = new SimplePositionedByteRange(0);
    DataType<byte[]> type = new FixedLengthWrapper<byte[]>(new RawBytes(), 3);
    type.encode(buff, Bytes.toBytes(""));
  }
View Full Code Here

    type.encode(buff, Bytes.toBytes(""));
  }

  @Test(expected = IllegalArgumentException.class)
  public void testOverflowPassthrough() {
    PositionedByteRange buff = new SimplePositionedByteRange(3);
    DataType<byte[]> type = new FixedLengthWrapper<byte[]>(new RawBytes(), 0);
    type.encode(buff, Bytes.toBytes("foo"));
  }
View Full Code Here

  }

  @Test(expected = IllegalArgumentException.class)
  public void testEncodedValueContainsTerm() {
    DataType<byte[]> type = new TerminatedWrapper<byte[]>(new RawBytes(), "foo");
    PositionedByteRange buff = new SimplePositionedByteRange(16);
    type.encode(buff, Bytes.toBytes("hello foobar!"));
  }
View Full Code Here

    type.encode(buff, Bytes.toBytes("hello foobar!"));
  }

  @Test
  public void testReadWrite() {
    PositionedByteRange buff = new SimplePositionedByteRange(12);
    for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
      for (byte[] term : TERMINATORS) {
        for (byte[] val : VALUES) {
          buff.setPosition(0);
          DataType<byte[]> type = new TerminatedWrapper<byte[]>(new RawBytes(ord), term);
          assertEquals(val.length + term.length, type.encode(buff, val));
          buff.setPosition(0);
          assertArrayEquals(val, type.decode(buff));
          assertEquals(val.length + term.length, buff.getPosition());
        }
      }
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testSkip() {
    PositionedByteRange buff = new SimplePositionedByteRange(12);
    for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
      for (byte[] term : TERMINATORS) {
        for (byte[] val : VALUES) {
          buff.setPosition(0);
          DataType<byte[]> type = new TerminatedWrapper<byte[]>(new RawBytes(ord), term);
          int expected = type.encode(buff, val);
          buff.setPosition(0);
          assertEquals(expected, type.skip(buff));
          assertEquals(expected, buff.getPosition());
        }
      }
    }
  }
View Full Code Here

    }
  }

  @Test(expected = IllegalArgumentException.class)
  public void testInvalidSkip() {
    PositionedByteRange buff = new SimplePositionedByteRange(Bytes.toBytes("foo"));
    DataType<byte[]> type = new TerminatedWrapper<byte[]>(new RawBytes(), new byte[] { 0x00 });
    type.skip(buff);
  }
View Full Code Here

  @Test(expected = NullPointerException.class)
  public void testNonNullableNullExtension() {
    Struct s = new StructBuilder()
        .add(new RawStringTerminated("|")) // not nullable
        .toStruct();
    PositionedByteRange buf = new SimplePositionedMutableByteRange(4);
    s.encode(buf, new Object[1]);
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.util.PositionedByteRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.