예제 #1
0
  /** Test for method {@link IndexCache#add(byte[], int, long)}: update. */
  @Test
  public void testUpdate() {
    final byte[] key = token("keyUpdate");
    final int size = 10;
    final long pointer = 12L;

    cache.add(key, size - 1, pointer - 1L);
    cache.add(key, size, pointer);

    assertCacheEntry(key, size, pointer);
  }
예제 #2
0
파일: FTIndex.java 프로젝트: fpapai/basex
  /**
   * Returns a cache entry.
   *
   * @param token token to be found or cached
   * @return cache entry
   */
  private IndexEntry entry(final byte[] token) {
    final IndexEntry e = cache.get(token);
    if (e != null) return e;

    final long p = token(token);
    return p == -1
        ? new IndexEntry(token, 0, 0)
        : cache.add(token, size(p, token.length), pointer(p, token.length));
  }
예제 #3
0
  /** Test for method {@link IndexCache#add(byte[], int, long)}. */
  @Test
  public void testAdd() {
    for (int i = 0; i < 4000; ++i) {
      final byte[] key = token("keyAdd" + i);
      final long pointer = i + 5000L;

      cache.add(key, i, pointer);
      assertCacheEntry(key, i, pointer);
    }
  }
예제 #4
0
  /** Test for method {@link IndexCache#delete(byte[])}. */
  @Test
  public void testDelete() {
    final byte[] key = token("keyDelete");
    final int size = 10;
    final long pointer = 12L;

    cache.add(key, size, pointer);
    cache.delete(key);

    assertNull(cache.get(key));
  }
예제 #5
0
  /** Test for method {@link IndexCache#get(byte[])}. */
  @Test
  public void testGetNotExisting() {
    for (int i = 0; i < 4000; ++i) {
      final byte[] key = token("keyAdd" + i);
      final long pointer = i + 5000L;

      cache.add(key, i, pointer);
      assertCacheEntry(key, i, pointer);
    }
    assertNull(cache.get(token("keyAdd" + 4000)));
  }
예제 #6
0
  /** Test that new records can be continuously added without hitting {@link OutOfMemoryError}. */
  @Test
  @Ignore("Start this test with a small heap size (e.g. -Xmx64m)")
  public void testPerformance() {
    final Random random = new Random(System.nanoTime());

    while (true) {
      final byte[] key = new byte[100];
      random.nextBytes(key);
      final int size = random.nextInt();
      final long pointer = random.nextLong();

      cache.add(key, size, pointer);
    }
  }