Ejemplo n.º 1
0
  public static void main(String... ignored) {
    ByteBuffer wrap = ByteBuffer.allocate(1024);
    Bytes bufferBytes = ByteBufferBytes.wrap(wrap);
    byte[] bytes = "BAC,12.32,12.54,12.56,232443".getBytes();

    int runs = 10000000;
    long start = System.nanoTime();
    for (int i = 0; i < runs; i++) {
      bufferBytes.clear();
      // read the next message.
      bufferBytes.write(bytes);
      bufferBytes.position(0);
      // decode message
      String word = bufferBytes.parseUtf8(StopCharTesters.COMMA_STOP);
      double low = bufferBytes.parseDouble();
      double curr = bufferBytes.parseDouble();
      double high = bufferBytes.parseDouble();
      long sequence = bufferBytes.parseLong();
      if (i == 0) {
        assertEquals("BAC", word);
        assertEquals(12.32, low, 0.0);
        assertEquals(12.54, curr, 0.0);
        assertEquals(12.56, high, 0.0);
        assertEquals(232443, sequence);
      }
    }
    long time = System.nanoTime() - start;
    System.out.println("Average time was " + time / runs + " nano-seconds");
  }
Ejemplo n.º 2
0
  @Test
  @Ignore
  public void NullPointerException() {
    final Bytes bytes =
        ByteBufferBytes.wrap(ByteBuffer.allocate(1024).order(ByteOrder.nativeOrder()));

    NullPointerException expected = new NullPointerException("test");
    bytes.writeObject(expected);

    bytes.position(0);
    NullPointerException actual = (NullPointerException) bytes.readObject();

    Assert.assertEquals(expected, actual);
  }