@Test
public void testDiskSizeRestrictionReplace() throws Exception {

    Key[] keys = prepareDiskSizeRestrictionTests();
    store.put(keys[4], new StoreInfoAndData(new byte[200], 4, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[0], new StoreInfoAndData(new byte[200], 0, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[1], new StoreInfoAndData(new byte[200], 1, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[3], new StoreInfoAndData(new byte[200], 3, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[2], new StoreInfoAndData(new byte[200], 2, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    try (
        Statement statement = store.metadataDb.createStatement();
        ResultSet rs = statement.executeQuery(FilesystemStore.QUERY_GETCURRENT_SIZE)) {
        assertTrue(rs.next());
        assertEquals(1000L, Long.parseLong(rs.getString(1)));
    }
    store.put(keys[4], new StoreInfoAndData(new byte[100], 4, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[0], new StoreInfoAndData(new byte[300], 0, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[1], new StoreInfoAndData(new byte[200], 1, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[3], new StoreInfoAndData(new byte[100], 3, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[2], new StoreInfoAndData(new byte[300], 2, false));
    assertStoreContains(keys, keys[0], keys[1], keys[2], keys[3], keys[4]);
    store.put(keys[2], new StoreInfoAndData(new byte[400], 2, false));
    assertStoreContains(keys, keys[2], keys[3], keys[4]);
}