diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java index badfabfac1..36dfc27716 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java @@ -582,17 +582,6 @@ public final class Page implements Comparable { return otherPage.getPageId() - this.pageId; } - @Override - protected void finalize() { - try { - if (file != null && file.isOpen()) { - file.close(false); - } - } catch (Exception e) { - ActiveMQServerLogger.LOGGER.pageFinaliseError(e); - } - } - @Override public int hashCode() { final int prime = 31; diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java index 894651e2c0..eaf0359e14 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java @@ -225,19 +225,20 @@ public class PageTest extends ActiveMQTestBase { file = factory.createSequentialFile("00010.page"); file.open(); - page = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); + Page page1 = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); - List msgs = page.read(new NullStorageManager()); + List msgs = page1.read(new NullStorageManager()); Assert.assertEquals(numberOfElements, msgs.size()); - Assert.assertEquals(numberOfElements, page.getNumberOfMessages()); + Assert.assertEquals(numberOfElements, page1.getNumberOfMessages()); for (int i = 0; i < msgs.size(); i++) { Assert.assertEquals(simpleDestination, msgs.get(i).getMessage().getAddressSimpleString()); } - page.delete(null); + page.close(false); + page1.delete(null); Assert.assertEquals(0, factory.listFiles("page").size()); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java index f1808beb57..7867b7c805 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java @@ -179,6 +179,7 @@ public class PagingStoreImplTest extends ActiveMQTestBase { Assert.assertEquals(1, storeImpl.getNumberOfPages()); + storeImpl.stop(); } @Test @@ -226,6 +227,7 @@ public class PagingStoreImplTest extends ActiveMQTestBase { Assert.assertEquals(numMessages, msg.size()); Assert.assertEquals(1, storeImpl.getNumberOfPages()); + page.close(false); page = storeImpl.depage(); Assert.assertNull(page); @@ -362,6 +364,7 @@ public class PagingStoreImplTest extends ActiveMQTestBase { Assert.assertEquals(0, store.getNumberOfPages()); page.open(); + page.close(false); } @@ -576,6 +579,8 @@ public class PagingStoreImplTest extends ActiveMQTestBase { Assert.assertEquals(0, buffers2.size()); Assert.assertEquals(0, storeImpl.getAddressSize()); + + storeImpl.stop(); } @Test @@ -791,6 +796,7 @@ public class PagingStoreImplTest extends ActiveMQTestBase { Assert.assertEquals(msg.getMessageID(), msg.getLongProperty("count").longValue()); msgsRead++; } + page.close(false); } storeImpl.stop();