You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/07/22 12:56:08 UTC

[3/7] git commit: implemented deletion of versions (MARMOTTA-18)

implemented deletion of versions (MARMOTTA-18)


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/18c428af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/18c428af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/18c428af

Branch: refs/heads/develop
Commit: 18c428af2115acc84e47e6473a59ad7fa8552388
Parents: 1ba8179
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Jul 22 11:07:07 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Jul 22 11:07:07 2013 +0200

----------------------------------------------------------------------
 .../persistence/KiWiVersioningConnection.java   |  60 ++++++++++
 .../versioning/sail/KiWiVersioningSail.java     | 116 +++++++++++++++----
 .../kiwi/persistence/h2/statements.properties   |   2 +-
 .../persistence/mysql/statements.properties     |   2 +-
 .../persistence/pgsql/statements.properties     |   2 +-
 .../versioning/test/SnapshotRepositoryTest.java |  14 +--
 .../test/VersioningPersistenceTest.java         |  92 +++++++++++++--
 .../test/VersioningRepositoryTest.java          |  13 +--
 8 files changed, 242 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
index 054cf20..2ef8946 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
+++ b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
@@ -17,6 +17,7 @@
  */
 package org.apache.marmotta.kiwi.versioning.persistence;
 
+import com.google.common.base.Preconditions;
 import info.aduna.iteration.CloseableIteration;
 import info.aduna.iteration.EmptyIteration;
 import info.aduna.iteration.ExceptionConvertingIteration;
@@ -130,6 +131,65 @@ public class KiWiVersioningConnection extends KiWiConnection {
     }
 
     /**
+     * Remove the version with the id passed as argument, including all references to added and removed triples. The
+     * triples themselves are not deleted immediately, we let the garbage collector carry this out periodically.
+     * @param id
+     * @throws SQLException
+     */
+    public void removeVersion(Long id) throws SQLException {
+        Preconditions.checkNotNull(id);
+        Preconditions.checkArgument(id > 0);
+
+        requireJDBCConnection();
+
+        PreparedStatement removeAdded = getPreparedStatement("delete.version_added");
+        removeAdded.clearParameters();
+        removeAdded.setLong(1, id);
+        removeAdded.executeUpdate();
+
+        PreparedStatement removeRemoved = getPreparedStatement("delete.version_removed");
+        removeRemoved.clearParameters();
+        removeRemoved.setLong(1, id);
+        removeRemoved.executeUpdate();
+
+        PreparedStatement removeVersion = getPreparedStatement("delete.version");
+        removeVersion.clearParameters();
+        removeVersion.setLong(1, id);
+        removeVersion.executeUpdate();
+
+    }
+
+    /**
+     * Remove all versions until the date given as argument. Iterates over all versions and deletes them individually.
+     * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
+     * without version will later be cleaned up by the garbage collector
+     * @param until date until when to delete versions
+     * @throws SQLException
+     */
+    public void removeVersions(Date until) throws SQLException {
+        removeVersions(new Date(0), until);
+    }
+
+
+    /**
+     * Remove all versions in the given time interval. Iterates over all versions and deletes them individually.
+     * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
+     * without version will later be cleaned up by the garbage collector
+     * @param from date after which versions will be deleted
+     * @param to   date before which versions will be deleted
+     * @throws SQLException
+     */
+    public void removeVersions(Date from, Date to) throws SQLException {
+        CloseableIteration<Version, SQLException> it = listVersionsInternal(from,to);
+        while(it.hasNext()) {
+            Version next = it.next();
+            removeVersion(next.getId());
+        }
+    }
+
+
+
+    /**
      * Retrieve a version by its id. If the version does not exist, returns null
      *
      * @param id

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/sail/KiWiVersioningSail.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/sail/KiWiVersioningSail.java b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/sail/KiWiVersioningSail.java
index 91de399..7a96b7e 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/sail/KiWiVersioningSail.java
+++ b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/sail/KiWiVersioningSail.java
@@ -72,33 +72,33 @@ public class KiWiVersioningSail extends TransactionalSailWrapper implements Tran
 
     private SesameFilter<Statement> filter;
 
-	/**
-	 * Build a new {@link KiWiVersioningSail} based on the provided parent
-	 * {@link TransactionalSail}.
-	 * 
-	 * @param parent
-	 *            the {@link TransactionalSail} to base the
-	 *            {@link KiWiVersioningSail} on.
-	 */
+    /**
+     * Build a new {@link KiWiVersioningSail} based on the provided parent
+     * {@link TransactionalSail}.
+     *
+     * @param parent
+     *            the {@link TransactionalSail} to base the
+     *            {@link KiWiVersioningSail} on.
+     */
     public KiWiVersioningSail(TransactionalSail parent) {
         this(parent,new AlwaysTrueFilter<Statement>());
     }
 
-	/**
-	 * Build a new selective {@link KiWiVersioningSail} based on the provided
-	 * parent {@link TransactionalSail}. Only {@link Statement}s that are
-	 * accepted by the filter are included in versioning.
-	 * 
-	 * @param parent
-	 *            the {@link TransactionalSail} to base the
-	 *            {@link KiWiVersioningSail} on.
-	 * @param filter
-	 *            a {@link SesameFilter} to filter out {@link Statement}s that
-	 *            should not be versioned. Only a {@link Statement} that is
-	 *            accepted by this filter will be versioned.
-	 * 
-	 * @see SesameFilter#accept(Object)
-	 */
+    /**
+     * Build a new selective {@link KiWiVersioningSail} based on the provided
+     * parent {@link TransactionalSail}. Only {@link Statement}s that are
+     * accepted by the filter are included in versioning.
+     *
+     * @param parent
+     *            the {@link TransactionalSail} to base the
+     *            {@link KiWiVersioningSail} on.
+     * @param filter
+     *            a {@link SesameFilter} to filter out {@link Statement}s that
+     *            should not be versioned. Only a {@link Statement} that is
+     *            accepted by this filter will be versioned.
+     *
+     * @see SesameFilter#accept(Object)
+     */
     public KiWiVersioningSail(TransactionalSail parent, SesameFilter<Statement> filter) {
         super(parent);
         this.persistence = new KiWiVersioningPersistence(getBaseStore().getPersistence());
@@ -316,12 +316,80 @@ public class KiWiVersioningSail extends TransactionalSailWrapper implements Tran
         }
     }
 
+
+    /**
+     * Remove the version with the id passed as argument, including all references to added and removed triples. The
+     * triples themselves are not deleted immediately, we let the garbage collector carry this out periodically.
+     * @param id  the database ID of the version (see {@link Version#getId()})
+     * @throws SailException
+     */
+    public void removeVersion(Long id) throws SailException {
+        try {
+            final KiWiVersioningConnection connection = persistence.getConnection();
+            try {
+                connection.removeVersion(id);
+                connection.commit();
+            } finally {
+                connection.close();
+            }
+
+        } catch(SQLException ex) {
+            throw new SailException("database error while listing versions",ex);
+        }
+    }
+
+    /**
+     * Remove all versions until the date given as argument. Iterates over all versions and deletes them individually.
+     * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
+     * without version will later be cleaned up by the garbage collector
+     * @param until date until when to delete versions
+     * @throws SailException
+     */
+    public void removeVersions(Date until) throws SailException {
+        try {
+            final KiWiVersioningConnection connection = persistence.getConnection();
+            try {
+                connection.removeVersions(until);
+                connection.commit();
+            } finally {
+                connection.close();
+            }
+
+        } catch(SQLException ex) {
+            throw new SailException("database error while listing versions",ex);
+        }
+    }
+
+
+    /**
+     * Remove all versions in the given time interval. Iterates over all versions and deletes them individually.
+     * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
+     * without version will later be cleaned up by the garbage collector
+     * @param from date after which versions will be deleted
+     * @param to   date before which versions will be deleted
+     * @throws SailException
+     */
+    public void removeVersions(Date from, Date to) throws SailException {
+        try {
+            final KiWiVersioningConnection connection = persistence.getConnection();
+            try {
+                connection.removeVersions(from, to);
+                connection.commit();
+            } finally {
+                connection.close();
+            }
+
+        } catch(SQLException ex) {
+            throw new SailException("database error while listing versions",ex);
+        }
+    }
+
     /**
      * Return the version that is the most recent version for a resource given a reference date. The method will either
      * return the version that was current for the resource at the given date or return null in case such a version
      * does not exist (e.g. before the resource was created).
      *
-     * @param resource  the resource for which to find a version
+     * @param r         the resource for which to find a version
      * @param date      the reference date
      * @return the latest version of the resource at the given date, or null if such a version does not exist
      * @throws SQLException

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties b/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
index 1001040..e5b1ae3 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
+++ b/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
@@ -48,4 +48,4 @@ store.version_removed = INSERT INTO versions_removed (version_id,triple_id) VALU
 
 delete.version_added   = DELETE FROM versions_added WHERE version_id = ?
 delete.version_removed = DELETE FROM versions_removed WHERE version_id = ?
-delete.version         = DELETE FROM verions WHERE id = ?
\ No newline at end of file
+delete.version         = DELETE FROM versions WHERE id = ?
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties b/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
index 5fce913..47d7f6a 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
+++ b/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
@@ -50,4 +50,4 @@ store.version_removed = INSERT INTO versions_removed (version_id,triple_id) VALU
 
 delete.version_added   = DELETE FROM versions_added WHERE version_id = ?
 delete.version_removed = DELETE FROM versions_removed WHERE version_id = ?
-delete.version         = DELETE FROM verions WHERE id = ?
\ No newline at end of file
+delete.version         = DELETE FROM versions WHERE id = ?
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties b/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
index 313e5b7..441adfc 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
+++ b/libraries/kiwi/kiwi-versioning/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
@@ -50,7 +50,7 @@ store.version_removed = INSERT INTO versions_removed (version_id,triple_id) VALU
 
 delete.version_added   = DELETE FROM versions_added WHERE version_id = ?
 delete.version_removed = DELETE FROM versions_removed WHERE version_id = ?
-delete.version         = DELETE FROM verions WHERE id = ?
+delete.version         = DELETE FROM versions WHERE id = ?
 
 query.snapshot_size           = SELECT count(*) FROM triples WHERE createdAt <= ? AND (deleted = false OR deletedAt > ?)
 query.snapshot_size_ctx       = SELECT count(*) FROM triples WHERE context = ? AND createdAt <= ? AND (deleted = false OR deletedAt > ?)

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/SnapshotRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/SnapshotRepositoryTest.java b/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/SnapshotRepositoryTest.java
index 7cc52e3..562da23 100644
--- a/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/SnapshotRepositoryTest.java
+++ b/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/SnapshotRepositoryTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.marmotta.kiwi.versioning.test;
 
+import info.aduna.iteration.Iterations;
 import org.apache.marmotta.kiwi.persistence.KiWiDialect;
 import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
 import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
@@ -378,17 +379,6 @@ public class SnapshotRepositoryTest {
      * @return
      */
     public static <E> List<E> asList(RepositoryResult<E> result) throws RepositoryException {
-        ArrayList<E> collection = new ArrayList<E>();
-        try {
-            while (result.hasNext()) {
-                collection.add(result.next());
-            }
-
-            return collection;
-        }
-        finally {
-            result.close();
-        }
+        return Iterations.asList(result);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningPersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningPersistenceTest.java b/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningPersistenceTest.java
index a7d6ad4..4477586 100644
--- a/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningPersistenceTest.java
+++ b/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningPersistenceTest.java
@@ -17,6 +17,8 @@
  */
 package org.apache.marmotta.kiwi.versioning.test;
 
+import info.aduna.iteration.Iteration;
+import info.aduna.iteration.Iterations;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
 import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
@@ -217,13 +219,13 @@ public class VersioningPersistenceTest {
             connection.commit();
 
             // check if listVersions now gives exactly one version
-            List<Version> list1 = connection.listVersions().asList();
+            List<Version> list1 = Iterations.asList(connection.listVersions());
             Assert.assertEquals("there should be exactly one version",1,list1.size());
             Assert.assertEquals("contents of version differ", version1, list1.get(0));
             Assert.assertEquals("version id is not 1", 1L, (long)list1.get(0).getId());
 
             // check if listVersions with subject1 now gives exactly one version
-            List<Version> listr1 = connection.listVersions(subject1).asList();
+            List<Version> listr1 = Iterations.asList(connection.listVersions(subject1));
             Assert.assertEquals("there should be exactly one version", 1, listr1.size());
             Assert.assertEquals("contents of version differ", version1, listr1.get(0));
             Assert.assertEquals("version id is not 1", 1L, (long)listr1.get(0).getId());
@@ -237,13 +239,13 @@ public class VersioningPersistenceTest {
             connection.commit();
 
             // check if listVersions now gives exactly two versions
-            List<Version> list2 = connection.listVersions().asList();
+            List<Version> list2 = Iterations.asList(connection.listVersions());
             Assert.assertEquals("there should be exactly two version",2,list2.size());
             Assert.assertEquals("contents of version differ", version2, list2.get(1));
 
 
             // check if listVersions with subject1 still gives exactly one version
-            List<Version> listr2 = connection.listVersions(subject1).asList();
+            List<Version> listr2 = Iterations.asList(connection.listVersions(subject1));
             Assert.assertEquals("there should be exactly one version", 2, listr2.size());
             Assert.assertEquals("contents of version differ", version1, listr2.get(0));
             Assert.assertEquals("version id is not 1", 1L, (long)listr2.get(0).getId());
@@ -320,7 +322,7 @@ public class VersioningPersistenceTest {
 
 
             // now we test different ways of listing versions between dates
-            List<Version> list1 = connection.listVersions(date1,date2).asList();
+            List<Version> list1 = Iterations.asList(connection.listVersions(date1,date2));
             Assert.assertEquals("there should be exactly one version from "+date1+" to "+date2,1,list1.size());
             Assert.assertEquals("contents of version differ", version1, list1.get(0));
             Assert.assertEquals("version id is not 1", 1L, (long)list1.get(0).getId());
@@ -331,21 +333,21 @@ public class VersioningPersistenceTest {
             Assert.assertEquals("latest version is not the expected version", version1,latest2);
 
             // check if listVersions with subject1 now gives exactly one version
-            List<Version> listr1 = connection.listVersions(subject,date1,date2).asList();
+            List<Version> listr1 = Iterations.asList(connection.listVersions(subject,date1,date2));
             Assert.assertEquals("there should be exactly one version", 1, listr1.size());
             Assert.assertEquals("contents of version differ", version1, listr1.get(0));
             Assert.assertEquals("version id is not 1", 1L, (long)listr1.get(0).getId());
 
 
-            List<Version> list2 = connection.listVersions(date2,date3).asList();
+            List<Version> list2 = Iterations.asList(connection.listVersions(date2,date3));
             Assert.assertEquals("there should be exactly one version from "+date2+" to "+date3,1,list2.size());
             Assert.assertEquals("contents of version differ", version2, list2.get(0));
             Assert.assertEquals("version id is not 2", 2L, (long)list2.get(0).getId());
 
-            List<Version> list3 = connection.listVersions(date3,new Date()).asList();
+            List<Version> list3 = Iterations.asList(connection.listVersions(date3,new Date()));
             Assert.assertEquals("there should be no version from "+date3+" to now",0,list3.size());
 
-            List<Version> list4 = connection.listVersions(date1,date3).asList();
+            List<Version> list4 = Iterations.asList(connection.listVersions(date1,date3));
             Assert.assertEquals("there should be exactly two versions from "+date1+" to "+date3,2,list4.size());
             Assert.assertEquals("contents of version1 differ", version1, list4.get(0));
             Assert.assertEquals("contents of version2 differ", version2, list4.get(1));
@@ -359,6 +361,78 @@ public class VersioningPersistenceTest {
 
     }
 
+
+    @Test
+    public void testCreateRemoveVersions() throws Exception {
+        KiWiVersioningConnection connection = vpersistence.getConnection();
+        try {
+            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
+            KiWiUriResource subject2  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
+            KiWiUriResource pred_1   = new KiWiUriResource("http://localhost/predicate/P1");
+            KiWiUriResource pred_2   = new KiWiUriResource("http://localhost/predicate/P2");
+            KiWiUriResource object_1 = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
+            KiWiStringLiteral object_2 = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(32));
+            KiWiUriResource context  = new KiWiUriResource("http://localhost/context/"+RandomStringUtils.randomAlphanumeric(8));
+
+            connection.storeNode(subject1, false);
+            connection.storeNode(subject2, false);
+            connection.storeNode(pred_1, false);
+            connection.storeNode(pred_2, false);
+            connection.storeNode(object_1, false);
+            connection.storeNode(object_2, false);
+            connection.storeNode(context, false);
+
+            KiWiTriple triple1 = new KiWiTriple(subject1,pred_1,object_1,context);
+            KiWiTriple triple2 = new KiWiTriple(subject2,pred_2,object_2,context);
+
+            connection.storeTriple(triple1);
+            connection.storeTriple(triple2);
+            connection.commit();
+
+            Version version1 = new Version();
+            version1.setCommitTime(new Date());
+            version1.addTriple(triple1);
+            connection.storeVersion(version1);
+            connection.commit();
+
+            // check if listVersions now gives exactly one version
+            List<Version> list1 = Iterations.asList(connection.listVersions());
+            Assert.assertEquals("there should be exactly one version",1,list1.size());
+            Assert.assertEquals("contents of version differ", version1, list1.get(0));
+            Assert.assertEquals("version id is not 1", 1L, (long)list1.get(0).getId());
+
+            Version version2 = new Version();
+            version2.setCommitTime(new Date());
+            version2.addTriple(triple2);
+            version2.removeTriple(triple1);
+            connection.storeVersion(version2);
+            connection.commit();
+
+            // check if listVersions now gives exactly two versions
+            List<Version> list2 = Iterations.asList(connection.listVersions());
+            Assert.assertEquals("there should be exactly two version",2,list2.size());
+            Assert.assertEquals("contents of version differ", version2, list2.get(1));
+
+            connection.commit();
+
+            connection.removeVersion(version1.getId());
+            connection.commit();
+
+            // check if listVersions now gives exactly two versions
+            List<Version> list3 = Iterations.asList(connection.listVersions());
+            Assert.assertEquals("there should be exactly one version",1,list3.size());
+            Assert.assertEquals("contents of version differ", version2, list3.get(0));
+
+            connection.commit();
+
+        } finally {
+            connection.close();
+        }
+
+    }
+
+
+
     /**
      * MYSQL rounds timestamps to the second, so it is sometimes necessary to sleep before doing a test
      */

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/18c428af/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningRepositoryTest.java b/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningRepositoryTest.java
index f0b720a..6757a58 100644
--- a/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningRepositoryTest.java
+++ b/libraries/kiwi/kiwi-versioning/src/test/java/org/apache/marmotta/kiwi/versioning/test/VersioningRepositoryTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.marmotta.kiwi.versioning.test;
 
+import info.aduna.iteration.Iterations;
 import org.apache.marmotta.kiwi.persistence.KiWiDialect;
 import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
 import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
@@ -267,16 +268,6 @@ public class VersioningRepositoryTest {
      * @return
      */
     public static <E> List<E> asList(RepositoryResult<E> result) throws RepositoryException {
-        ArrayList<E> collection = new ArrayList<E>();
-        try {
-            while (result.hasNext()) {
-                collection.add(result.next());
-            }
-
-            return collection;
-        }
-        finally {
-            result.close();
-        }
+        return Iterations.asList(result);
     }
 }