Package org.apache.hadoop.hbase.util

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


      int term = terminatorPosition(src);
      if (-1 == term) throw new IllegalArgumentException("Terminator sequence not found.");
      byte[] b = new byte[term - src.getPosition()];
      src.get(b);
      // TODO: should we assert that b.position == b.length?
      T ret = wrapped.decode(new SimplePositionedByteRange(b));
      src.get(this.term);
      return ret;
    }
  }
View Full Code Here


    PositionedByteRange[] encodedGeneric = new PositionedByteRange[constructorArgs.length];
    PositionedByteRange[] encodedSpecialized = new PositionedByteRange[constructorArgs.length];
    Constructor<?> ctor = specialized.encodedClass().getConstructor(Object[].class);
    for (int i = 0; i < vals.length; i++) {
      vals[i] = ctor.newInstance(new Object[] { constructorArgs[i] });
      encodedGeneric[i] = new SimplePositionedByteRange(generic.encodedLength(constructorArgs[i]));
      encodedSpecialized[i] = new SimplePositionedByteRange(specialized.encodedLength(vals[i]));
    }

    // populate our arrays
    for (int i = 0; i < vals.length; i++) {
      generic.encode(encodedGeneric[i], constructorArgs[i]);
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

TOP

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

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.