Package org.apache.hadoop.hbase.util

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


  @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


  @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

  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

    }
  }

  @Test(expected = IllegalArgumentException.class)
  public void testInsufficientRemainingRead() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(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 SimplePositionedMutableByteRange(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 SimplePositionedMutableByteRange(3);
    DataType<byte[]> type = new FixedLengthWrapper<byte[]>(new RawBytes(), 0);
    type.encode(buff, Bytes.toBytes("foo"));
  }
View Full Code Here

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

  @Test
  public void testEncodedLength() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
    for (DataType<byte[]> type :
      new OrderedBlobVar[] { OrderedBlobVar.ASCENDING, OrderedBlobVar.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

  }

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

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

  @Test
  public void testReadWriteSkippable() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
    for (OrderedString t : new OrderedString[] {
        OrderedString.ASCENDING, OrderedString.DESCENDING
    }) {
      for (byte[] term : TERMINATORS) {
        for (String val : VALUES_STRINGS) {
          buff.setPosition(0);
          DataType<String> type = new TerminatedWrapper<String>(t, term);
          assertEquals(val.length() + 2 + term.length, type.encode(buff, val));
          buff.setPosition(0);
          assertEquals(val, type.decode(buff));
          assertEquals(val.length() + 2 + term.length, buff.getPosition());
        }
      }
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testReadWriteNonSkippable() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(12);
    for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
      for (byte[] term : TERMINATORS) {
        for (byte[] val : VALUES_BYTES) {
          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

TOP

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

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.