Beispiel #1
0
  private static void assertLong(Slice slice, int index) {
    // fill slice with FF
    slice.fill((byte) 0xFF);

    // set and get the value
    slice.setLong(index, 0xAAAA_AAAA_5555_5555L);
    assertEquals(slice.getLong(index), 0xAAAA_AAAA_5555_5555L);

    try {
      slice.getLong(-1);
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      slice.getLong((slice.length() - SIZE_OF_LONG) + 1);
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      slice.getLong(slice.length());
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      slice.getLong(slice.length() + 1);
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
  }
Beispiel #2
0
  @Test
  public void testMemoryMappedReads() throws IOException {
    Path path = Files.createTempFile("longs", null);
    ImmutableList<Long> values = createRandomLongs(20000);

    Slice output = allocate(values.size() * Longs.BYTES);
    for (int i = 0; i < values.size(); i++) {
      output.setLong(i * Longs.BYTES, values.get(i));
    }

    Files.write(path, output.getBytes());

    Slice slice = Slices.mapFileReadOnly(path.toFile());
    for (int i = 0; i < values.size(); i++) {
      long actual = slice.getLong(i * Longs.BYTES);
      long expected = values.get(i);
      assertEquals(actual, expected);
    }

    assertEquals(slice.getBytes(), output.getBytes());
  }