Examples of PositionedByteRange


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

      throw new IllegalArgumentException("Not enough buffer remaining. src.offset: "
          + src.getOffset() + " src.length: " + src.getLength() + " src.position: "
          + src.getPosition() + " max length: " + length);
    }
    // create a copy range limited to length bytes. boo.
    PositionedByteRange b = new SimplePositionedMutableByteRange(length);
    src.get(b.getBytes());
    return base.decode(b);
  }
View Full Code Here

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

  protected OrderedNumeric(Order order) { super(order); }

  @Override
  public int encodedLength(Number val) {
    // TODO: this could be done better.
    PositionedByteRange buff = new SimplePositionedMutableByteRange(100);
    return encode(buff, val);
  }
View Full Code Here

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

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

    Bytes.toBytes("7777777"), Bytes.toBytes("88888888"), Bytes.toBytes("999999999"),
  };

  @Test
  public void testEncodedLength() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
    for (DataType<byte[]> type : new OrderedBlob[] { OrderedBlob.ASCENDING, OrderedBlob.DESCENDING }) {
      for (byte[] val : VALUES) {
        buff.setPosition(0);
        type.encode(buff, val);
        assertEquals(
          "encodedLength does not match actual, " + Bytes.toStringBinary(val),
          buff.getPosition(), type.encodedLength(val));
      }
    }
  }
View Full Code Here

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

      new String[] { null, "", "1", "22", "333", "4444", "55555", "666666",
    "7777777", "88888888", "999999999" };

  @Test
  public void testEncodedLength() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
    for (DataType<String> type : new OrderedString[] { OrderedString.ASCENDING, OrderedString.DESCENDING }) {
      for (String val : VALUES) {
        buff.setPosition(0);
        type.encode(buff, val);
        assertEquals(
          "encodedLength does not match actual, " + val,
          buff.getPosition(), type.encodedLength(val));
      }
    }
  }
View Full Code Here

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

  @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

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

        // intentionally include a wrapped instance to test wrapper behavior.
        .add(new TerminatedWrapper<String>(OrderedString.ASCENDING, "/"))
        .add(OrderedNumeric.ASCENDING)
        .toStruct();

    PositionedByteRange buf1 = new SimplePositionedMutableByteRange(7);
    Object[] val1 = new Object[] { BigDecimal.ONE, "foo" }; // => 2 bytes + 5 bytes
    assertEquals("Encoding shorter value wrote a surprising number of bytes.",
      buf1.getLength(), shorter.encode(buf1, val1));
    int shortLen = buf1.getLength();

    // test iterator
    buf1.setPosition(0);
    StructIterator it = longer.iterator(buf1);
    it.skip();
    it.skip();
    assertEquals("Position should be at end. Broken test.", buf1.getLength(), buf1.getPosition());
    assertEquals("Failed to skip null element with extended struct.", 0, it.skip());
    assertEquals("Failed to skip null element with extended struct.", 0, it.skip());

    buf1.setPosition(0);
    it = longer.iterator(buf1);
    assertEquals(BigDecimal.ONE, it.next());
    assertEquals("foo", it.next());
    assertEquals("Position should be at end. Broken test.", buf1.getLength(), buf1.getPosition());
    assertNull("Failed to skip null element with extended struct.", it.next());
    assertNull("Failed to skip null element with extended struct.", it.next());

    // test Struct
    buf1.setPosition(0);
    assertArrayEquals("Simple struct decoding is broken.", val1, shorter.decode(buf1));

    buf1.setPosition(0);
    assertArrayEquals("Decoding short value with extended struct should append null elements.",
      Arrays.copyOf(val1, 4), longer.decode(buf1));

    // test omission of trailing members
    PositionedByteRange buf2 = new SimplePositionedMutableByteRange(7);
    buf1.setPosition(0);
    assertEquals(
      "Encoding a short value with extended struct should have same result as using short struct.",
      shortLen, longer.encode(buf2, val1));
    assertArrayEquals(
      "Encoding a short value with extended struct should have same result as using short struct",
      buf1.getBytes(), buf2.getBytes());

    // test null trailing members
    // all fields are nullable, so nothing should hit the buffer.
    val1 = new Object[] { null, null, null, null }; // => 0 bytes
    buf1.set(0);
    buf2.set(0);
    assertEquals("Encoding null-truncated value wrote a surprising number of bytes.",
      buf1.getLength(), longer.encode(buf1, new Object[0]));
    assertEquals("Encoding null-extended value wrote a surprising number of bytes.",
      buf1.getLength(), longer.encode(buf1, val1));
    assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes());
    assertArrayEquals("Decoded unexpected result.", val1, longer.decode(buf2));

    // all fields are nullable, so only 1 should hit the buffer.
    Object[] val2 = new Object[] { BigDecimal.ONE, null, null, null }; // => 2 bytes
    buf1.set(2);
    buf2.set(2);
    assertEquals("Encoding null-truncated value wrote a surprising number of bytes.",
      buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val2, 1)));
    assertEquals("Encoding null-extended value wrote a surprising number of bytes.",
      buf2.getLength(), longer.encode(buf2, val2));
    assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes());
    buf2.setPosition(0);
    assertArrayEquals("Decoded unexpected result.", val2, longer.decode(buf2));

    // all fields are nullable, so only 1, null, "foo" should hit the buffer.
    // => 2 bytes + 1 byte + 6 bytes
    Object[] val3 = new Object[] { BigDecimal.ONE, null, "foo", null };
    buf1.set(9);
    buf2.set(9);
    assertEquals("Encoding null-truncated value wrote a surprising number of bytes.",
      buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val3, 3)));
    assertEquals("Encoding null-extended value wrote a surprising number of bytes.",
      buf2.getLength(), longer.encode(buf2, val3));
    assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes());
    buf2.setPosition(0);
    assertArrayEquals("Decoded unexpected result.", val3, longer.decode(buf2));
  }
View Full Code Here

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

  @Test
  public void testEncodeDecode() {
    Integer intVal = Integer.valueOf(10);
    String strVal = "hello";
    PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
    SampleUnion1 type = new SampleUnion1();

    type.encode(buff, intVal);
    buff.setPosition(0);
    assertTrue(0 == intVal.compareTo(type.decodeA(buff)));
    buff.setPosition(0);
    type.encode(buff, strVal);
    buff.setPosition(0);
    assertTrue(0 == strVal.compareTo(type.decodeB(buff)));
  }
View Full Code Here

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

  @Test
  public void testSkip() {
    Integer intVal = Integer.valueOf(10);
    String strVal = "hello";
    PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
    SampleUnion1 type = new SampleUnion1();

    int len = type.encode(buff, intVal);
    buff.setPosition(0);
    assertEquals(len, type.skip(buff));
    buff.setPosition(0);
    len = type.encode(buff, strVal);
    buff.setPosition(0);
    assertEquals(len, type.skip(buff));
  }
View Full Code Here

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

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

  @Test
  public void testReadWrite() {
    for (int limit : limits) {
      PositionedByteRange buff = new SimplePositionedMutableByteRange(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));
          buff.setPosition(0);
          byte[] actual = type.decode(buff);
          assertTrue("Decoding output differs from expected",
            Bytes.equals(val, 0, val.length, actual, 0, val.length));
          buff.setPosition(0);
          assertEquals(limit, type.skip(buff));
        }
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.