Esempio n. 1
0
  @Test
  public void readVarInt_errorCase() {
    byte[] errorCode = new byte[] {-118, -41, -17, -117, -81, -115, -64, -64, -108, -88};
    Buffer buffer = new FixedBuffer(errorCode);
    try {
      buffer.readVarInt();
      Assert.fail("invalid varInt");
    } catch (IllegalArgumentException ignore) {
    }

    Assert.assertEquals(0, buffer.getOffset());
  }
Esempio n. 2
0
 private void checkVarInt_bufferSize(int v, int offset, int bufferSize) {
   final Buffer buffer = new FixedBuffer(bufferSize);
   buffer.putVar(v);
   if (offset != -1) {
     Assert.assertEquals(buffer.getOffset(), offset);
   } else {
     logger.info("{} offsetSize:{}", v, buffer.getOffset());
   }
   buffer.setOffset(0);
   int readV = buffer.readVarInt();
   Assert.assertEquals(readV, v);
 }
Esempio n. 3
0
  //    @Test
  public void find_SVarInt_errorCode() throws Exception {
    Random random = new Random();
    byte[] bytes = new byte[10];

    while (true) {
      random.nextBytes(bytes);
      Buffer buffer = new FixedBuffer(bytes);
      try {
        int i = buffer.readVarInt();
      } 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;
      }
    }
  }