Permalink
Browse files

[FIX] Closing of transactions.

  • Loading branch information...
1 parent 6e8bff4 commit e4288812d087e41a1e390d10bfbb321de409a345 @JohannesLichtenberger JohannesLichtenberger committed Jan 31, 2014
@@ -1,79 +1,81 @@
-/**
- * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the University of Konstanz nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package org.sirix.cache;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sirix.Holder;
-import org.sirix.TestHelper;
-import org.sirix.access.conf.DatabaseConfiguration;
-import org.sirix.api.PageReadTrx;
-import org.sirix.exception.SirixException;
-import org.sirix.page.UnorderedKeyValuePage;
-
-public class BerkeleyPersistentCacheTest {
-
- private Cache<Long, RecordPageContainer<UnorderedKeyValuePage>> cache;
-
- private Holder holder;
-
- private PageReadTrx mPageReadTrx;
-
- @Before
- public void setUp() throws SirixException {
- TestHelper.deleteEverything();
- TestHelper.createTestDocument();
- holder = Holder.generateSession();
- mPageReadTrx = holder.getSession().beginPageReadTrx();
- cache = new BerkeleyPersistenceCache<>(new File(new File(
- TestHelper.PATHS.PATH1.getFile(), DatabaseConfiguration.Paths.DATA
- .getFile().getName()), TestHelper.RESOURCE), 1, "log", mPageReadTrx);
- CacheTestHelper.setUp(cache);
- }
-
- @Test
- public void test() {
- for (long i = 0; i < CacheTestHelper.PAGES.length; i++) {
- final RecordPageContainer<UnorderedKeyValuePage> cont = cache.get(i);
- final UnorderedKeyValuePage current = (UnorderedKeyValuePage) cont.getComplete();
- assertEquals(CacheTestHelper.PAGES[(int) i][0], current);
- }
- cache.clear();
- }
-
- @After
- public void tearDown() throws SirixException {
- mPageReadTrx.close();
- TestHelper.closeEverything();
- }
-}
+/**
+ * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the University of Konstanz nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.sirix.cache;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.sirix.Holder;
+import org.sirix.TestHelper;
+import org.sirix.access.conf.DatabaseConfiguration;
+import org.sirix.api.PageReadTrx;
+import org.sirix.exception.SirixException;
+import org.sirix.page.UnorderedKeyValuePage;
+
+public class BerkeleyPersistentCacheTest {
+
+ private Cache<Long, RecordPageContainer<UnorderedKeyValuePage>> cache;
+
+ private Holder holder;
+
+ private PageReadTrx mPageReadTrx;
+
+ @Before
+ public void setUp() throws SirixException {
+ TestHelper.deleteEverything();
+ TestHelper.createTestDocument();
+ holder = Holder.generateSession();
+ mPageReadTrx = holder.getSession().beginPageReadTrx();
+ cache = new BerkeleyPersistenceCache<>(new File(new File(
+ TestHelper.PATHS.PATH1.getFile(), DatabaseConfiguration.Paths.DATA
+ .getFile().getName()), TestHelper.RESOURCE), 1, "log", mPageReadTrx);
+ CacheTestHelper.setUp(cache);
+ }
+
+ @Test
+ public void test() {
+ for (long i = 0; i < CacheTestHelper.PAGES.length; i++) {
+ final RecordPageContainer<UnorderedKeyValuePage> cont = cache.get(i);
+ final UnorderedKeyValuePage current = (UnorderedKeyValuePage) cont.getComplete();
+ assertEquals(CacheTestHelper.PAGES[(int) i][0], current);
+ }
+ }
+
+ @After
+ public void tearDown() throws SirixException {
+ cache.clear();
+ cache.close();
+ CacheTestHelper.PAGE_READ_TRX.close();
+ mPageReadTrx.close();
+ TestHelper.closeEverything();
+ }
+}
@@ -1,85 +1,85 @@
-/**
- * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the University of Konstanz nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.sirix.cache;
-
-import org.junit.Test;
-import org.sirix.Holder;
-import org.sirix.access.conf.ResourceConfiguration;
-import org.sirix.api.PageReadTrx;
-import org.sirix.exception.SirixException;
-import org.sirix.page.PageKind;
-import org.sirix.page.PageReference;
-import org.sirix.page.UnorderedKeyValuePage;
-
-import com.google.common.base.Optional;
-
-/**
- * Helper class for testing the cache.
- *
- * @author Sebastian Graf, University of Konstanz
- *
- */
-public class CacheTestHelper {
-
- /** Page reading transaction. */
- private static PageReadTrx PAGE_READ_TRX;
-
- /** Unordered record pages. */
- protected static UnorderedKeyValuePage[][] PAGES;
-
- /**
- * Setup the cache.
- *
- * @param cache
- * cache to fill
- * @throws SirixException
- * if setting up Sirix session fails
- */
- public static void setUp(
- final Cache<Long, RecordPageContainer<UnorderedKeyValuePage>> cache)
- throws SirixException {
- PAGE_READ_TRX = Holder.generateSession().getSession().beginPageReadTrx();
- PAGES = new UnorderedKeyValuePage[LRUCache.CACHE_CAPACITY + 1][ResourceConfiguration.VERSIONSTORESTORE + 1];
- for (int i = 0; i < PAGES.length; i++) {
- final UnorderedKeyValuePage page = new UnorderedKeyValuePage(i, PageKind.RECORDPAGE, Optional.<PageReference> absent(), PAGE_READ_TRX);
- final UnorderedKeyValuePage[] revs = new UnorderedKeyValuePage[ResourceConfiguration.VERSIONSTORESTORE];
-
- for (int j = 0; j < ResourceConfiguration.VERSIONSTORESTORE; j++) {
- PAGES[i][j + 1] = new UnorderedKeyValuePage(i, PageKind.RECORDPAGE, Optional.<PageReference> absent(), PAGE_READ_TRX);
- revs[j] = PAGES[i][j + 1];
- }
- PAGES[i][0] = page;
- cache.put((long) i, new RecordPageContainer<>(page));
- }
- }
-
- @Test
- public void dummy() {
- // Only for dummy purposes.
- }
-
-}
+/**
+ * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the University of Konstanz nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.sirix.cache;
+
+import org.junit.Test;
+import org.sirix.Holder;
+import org.sirix.access.conf.ResourceConfiguration;
+import org.sirix.api.PageReadTrx;
+import org.sirix.exception.SirixException;
+import org.sirix.page.PageKind;
+import org.sirix.page.PageReference;
+import org.sirix.page.UnorderedKeyValuePage;
+
+import com.google.common.base.Optional;
+
+/**
+ * Helper class for testing the cache.
+ *
+ * @author Sebastian Graf, University of Konstanz
+ *
+ */
+public class CacheTestHelper {
+
+ /** Page reading transaction. */
+ public static PageReadTrx PAGE_READ_TRX;
+
+ /** Unordered record pages. */
+ protected static UnorderedKeyValuePage[][] PAGES;
+
+ /**
+ * Setup the cache.
+ *
+ * @param cache
+ * cache to fill
+ * @throws SirixException
+ * if setting up Sirix session fails
+ */
+ public static void setUp(
+ final Cache<Long, RecordPageContainer<UnorderedKeyValuePage>> cache)
+ throws SirixException {
+ PAGE_READ_TRX = Holder.generateSession().getSession().beginPageReadTrx();
+ PAGES = new UnorderedKeyValuePage[LRUCache.CACHE_CAPACITY + 1][ResourceConfiguration.VERSIONSTORESTORE + 1];
+ for (int i = 0; i < PAGES.length; i++) {
+ final UnorderedKeyValuePage page = new UnorderedKeyValuePage(i, PageKind.RECORDPAGE, Optional.<PageReference> absent(), PAGE_READ_TRX);
+ final UnorderedKeyValuePage[] revs = new UnorderedKeyValuePage[ResourceConfiguration.VERSIONSTORESTORE];
+
+ for (int j = 0; j < ResourceConfiguration.VERSIONSTORESTORE; j++) {
+ PAGES[i][j + 1] = new UnorderedKeyValuePage(i, PageKind.RECORDPAGE, Optional.<PageReference> absent(), PAGE_READ_TRX);
+ revs[j] = PAGES[i][j + 1];
+ }
+ PAGES[i][0] = page;
+ cache.put((long) i, new RecordPageContainer<>(page));
+ }
+ }
+
+ @Test
+ public void dummy() {
+ // Only for dummy purposes.
+ }
+
+}
Oops, something went wrong.

0 comments on commit e428881

Please sign in to comment.