Beispiel #1
0
  @Test
  public void readVarLong_errorCase() {
    byte[] errorCode = new byte[] {-25, -45, -47, -14, -16, -104, -53, -48, -72, -9};
    Buffer buffer = new FixedBuffer(errorCode);
    try {
      buffer.readVarLong();
      Assert.fail("invalid varLong");
    } catch (IllegalArgumentException ignore) {
    }

    Assert.assertEquals(0, buffer.getOffset());
  }
Beispiel #2
0
  private void checkVarLong_bufferSize(long v, int bufferSize) {
    final Buffer buffer = new FixedBuffer(bufferSize);
    buffer.putVar(v);

    buffer.setOffset(0);
    long readV = buffer.readVarLong();
    Assert.assertEquals(readV, v);

    if (logger.isTraceEnabled()) {
      logger.trace("v:{} offset:{}", v, buffer.getOffset());
    }
  }
Beispiel #3
0
  //    @Test
  public void find_SVarLong_errorCode() throws Exception {
    Random random = new Random();
    byte[] bytes = new byte[10];

    while (true) {
      random.nextBytes(bytes);
      Buffer buffer = new FixedBuffer(bytes);
      try {
        long i = buffer.readVarLong();
      } catch (IllegalArgumentException e) {
        logger.info(e.getMessage(), e);
        String binaryString = BytesUtils.toString(bytes);
        logger.info(binaryString);
        for (byte aByte : bytes) {
          String code = String.valueOf((int) aByte);
          logger.info(code);
        }
        return;
      }
    }
  }