Beispiel #1
0
  /** Tests removing all the entries, after they have been written to disk. */
  @Test
  public void testRemoveAllSlow() throws Exception {
    final CompoundStore diskStore = (CompoundStore) createDiskStore();

    // Add the entry
    final String value = "value";
    diskStore.put(new Element("key1", value));
    diskStore.put(new Element("key2", value));

    // Wait
    waitShorter();

    // Check the entry is there
    Object o1 = diskStore.unretrievedGet("key1");
    Object o2 = diskStore.unretrievedGet("key2");
    if (o1 instanceof Element) {
      assertEquals("DiskMarker", o2.getClass().getSimpleName());
    } else if (o2 instanceof Element) {
      assertEquals("DiskMarker", o1.getClass().getSimpleName());
    } else {
      fail("One of the elements should be in memory");
    }

    // Remove it
    diskStore.removeAll();

    // Check the entry is not there
    assertEquals(0, diskStore.getSize());
    assertEquals(0, diskStore.getOnDiskSize());
    assertNull(diskStore.get("key1"));
    assertNull(diskStore.get("key2"));
  }
Beispiel #2
0
  /** Tests adding an entry and waiting for it to be written. */
  @Test
  public void testPutSlow() throws Exception {
    final CompoundStore diskStore = (CompoundStore) createDiskStore();

    // Make sure the element is not found
    assertEquals(0, diskStore.getSize());
    assertNull(diskStore.get("key"));

    // Add the element
    final String value = "value";
    diskStore.put(new Element("key1", value));
    diskStore.put(new Element("key2", value));

    // Wait
    waitShorter();

    // Get the element
    assertEquals(1, diskStore.getOnDiskSize());
    assertEquals(2, diskStore.getSize());

    Object o1 = diskStore.unretrievedGet("key1");
    Object o2 = diskStore.unretrievedGet("key2");
    if (o1 instanceof Element) {
      assertEquals("DiskMarker", o2.getClass().getSimpleName());
    } else if (o2 instanceof Element) {
      assertEquals("DiskMarker", o1.getClass().getSimpleName());
    } else {
      fail("One of the elements should be in memory");
    }

    Element element1 = diskStore.get("key1");
    Element element2 = diskStore.get("key2");
    assertNotNull(element1);
    assertNotNull(element2);
    assertEquals(value, element1.getObjectValue());
    assertEquals(value, element2.getObjectValue());
  }