[jboss-cvs] JBoss Messaging SVN: r4798 - in branches/Branch_JBMESSAGING-1314: tests/src/org/jboss/messaging/tests/integration/paging and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 12 19:51:49 EDT 2008
Author: clebert.suconic at jboss.com
Date: 2008-08-12 19:51:48 -0400 (Tue, 12 Aug 2008)
New Revision: 4798
Added:
branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java
Modified:
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java
branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
Log:
Finishing PagingManager implementation
Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java 2008-08-12 21:52:13 UTC (rev 4797)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java 2008-08-12 23:51:48 UTC (rev 4798)
@@ -26,7 +26,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.jboss.messaging.core.journal.SequentialFileFactory;
import org.jboss.messaging.core.paging.PagingManager;
import org.jboss.messaging.core.paging.PagingStore;
Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java 2008-08-12 21:52:13 UTC (rev 4797)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java 2008-08-12 23:51:48 UTC (rev 4798)
@@ -23,6 +23,8 @@
package org.jboss.messaging.core.paging.impl;
+import java.io.File;
+
import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
import org.jboss.messaging.core.paging.PagingStore;
@@ -56,7 +58,11 @@
public PagingStore newStore(String destinationName)
{
- return new PagingStoreImpl(new NIOSequentialFileFactory(directory + "/" + destinationName), destinationName, pageSize);
+ final String destinationDirectory = directory + "/" + destinationName;
+ File destinationFile = new File(destinationDirectory);
+ destinationFile.mkdirs();
+
+ return new PagingStoreImpl(new NIOSequentialFileFactory(destinationDirectory), destinationName, pageSize);
}
// Package protected ---------------------------------------------
Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java 2008-08-12 21:52:13 UTC (rev 4797)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java 2008-08-12 23:51:48 UTC (rev 4798)
@@ -23,7 +23,6 @@
package org.jboss.messaging.core.paging.impl;
-import org.jboss.messaging.core.journal.SequentialFileFactory;
import org.jboss.messaging.core.paging.PagingStore;
/**
Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java 2008-08-12 21:52:13 UTC (rev 4797)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java 2008-08-12 23:51:48 UTC (rev 4798)
@@ -241,7 +241,10 @@
try
{
initialized = false;
- currentPage.close();
+ if (currentPage != null)
+ {
+ currentPage.close();
+ }
}
finally
{
@@ -260,7 +263,7 @@
// You could have two threads adding PagingStore to a ConcurrentHashMap,
// and having both threads calling init. One of the calls should just need to be ignored
return;
- }
+ }
lock.writeLock().lock();
Added: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java (rev 0)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java 2008-08-12 23:51:48 UTC (rev 4798)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.tests.integration.paging;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+
+import org.jboss.messaging.core.paging.Page;
+import org.jboss.messaging.core.paging.PagingStore;
+import org.jboss.messaging.core.paging.impl.PagingManagerImpl;
+import org.jboss.messaging.core.paging.impl.PagingManagerNIOSPI;
+import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.server.impl.ServerMessageImpl;
+import org.jboss.messaging.tests.util.RandomUtil;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public class PagingManagerIntegrationTest extends UnitTestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test";
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testPagingManagerNIO() throws Exception
+ {
+ PagingManagerImpl managerImpl =
+ new PagingManagerImpl(new PagingManagerNIOSPI(journalDir, 1024*1024));
+ managerImpl.start();
+
+ PagingStore store = managerImpl.getPageStore("simple-test");
+
+ ServerMessage msg = createMessage(1l, new SimpleString("simple-test"), createRandomBuffer(10));
+
+ assertFalse(store.writeOnCurrentPage(msg));
+
+ store.startPaging();
+
+ assertTrue(store.writeOnCurrentPage(msg));
+
+ Page page = store.dequeuePage();
+
+ page.open();
+
+ ServerMessage msgs[] = page.read();
+
+ page.close();
+
+ assertEquals(1, msgs.length);
+
+ assertEqualsByteArrays(msg.getBody().array(), msgs[0].getBody().array());
+
+ assertFalse(store.writeOnCurrentPage(msg));
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ recreateDirectory();
+ }
+
+ protected ServerMessage createMessage(long messageId, SimpleString destination, ByteBuffer buffer)
+ {
+ ServerMessage msg = new ServerMessageImpl((byte)1, true, 0,
+ System.currentTimeMillis(), (byte)0, new ByteBufferWrapper(buffer));
+
+ msg.setMessageID((long)messageId);
+
+ msg.setDestination(destination);
+ return msg;
+ }
+
+ protected ByteBuffer createRandomBuffer(int size)
+ {
+ ByteBuffer buffer = ByteBuffer.allocate(size);
+
+ for (int j = 0; j < buffer.limit(); j++)
+ {
+ buffer.put(RandomUtil.randomByte());
+ }
+ return buffer;
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ //deleteDirectory(new File(journalDir));
+ }
+
+ // Private -------------------------------------------------------
+
+ private void recreateDirectory()
+ {
+ File fileJournalDir = new File(journalDir);
+ deleteDirectory(fileJournalDir);
+ fileJournalDir.mkdirs();
+ }
+
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java 2008-08-12 21:52:13 UTC (rev 4797)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java 2008-08-12 23:51:48 UTC (rev 4798)
@@ -23,13 +23,15 @@
package org.jboss.messaging.tests.unit.core.paging.impl;
+import java.util.ArrayList;
+import java.util.concurrent.CountDownLatch;
+
import org.easymock.EasyMock;
import org.jboss.messaging.core.journal.SequentialFileFactory;
import org.jboss.messaging.core.paging.PagingStore;
import org.jboss.messaging.core.paging.impl.PagingManagerImpl;
import org.jboss.messaging.core.paging.impl.PagingManagerSPI;
import org.jboss.messaging.core.paging.impl.PagingStoreImpl;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
import org.jboss.messaging.tests.util.UnitTestCase;
public class PageManagerImplTest extends UnitTestCase
@@ -98,28 +100,83 @@
}
-
- // Package protected ---------------------------------------------
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
- class FakeManagerSPI implements PagingManagerSPI
+ public void testMultipleThreadsGetStore() throws Exception
{
+ PagingManagerSPI spi = EasyMock.createMock(PagingManagerSPI.class);
+ final PagingManagerImpl manager = new PagingManagerImpl(spi);
+
+ final String destination = "some-destination";
- public SequentialFileFactory newFactory(String destinationName)
+ final SequentialFileFactory factory = EasyMock.createNiceMock(SequentialFileFactory.class);
+
+ EasyMock.expect(factory.listFiles(EasyMock.isA(String.class))).andStubReturn(new ArrayList<String>());
+
+ PagingStoreImpl storeImpl = new PagingStoreImpl(factory, destination, 1);
+
+ EasyMock.expect(spi.newStore(destination)).andStubReturn(storeImpl);
+
+ EasyMock.replay(spi, factory);
+
+ manager.start();
+
+ int NUMBER_OF_THREADS = 100;
+
+ final CountDownLatch latchPositioned = new CountDownLatch(NUMBER_OF_THREADS);
+ final CountDownLatch latchReady = new CountDownLatch(1);
+
+ class GetPageThread extends Thread
{
- return new FakeSequentialFileFactory();
+ Exception e;
+
+ public void run()
+ {
+ try
+ {
+ latchPositioned.countDown();
+ latchReady.await();
+ manager.getPageStore(destination);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ this.e = e;
+ }
+
+ }
}
-
- public PagingStore newStore(String destinationName)
+
+ GetPageThread threads[] = new GetPageThread[NUMBER_OF_THREADS];
+ for (int i = 0; i < NUMBER_OF_THREADS; i++)
{
- return new PagingStoreImpl(new FakeSequentialFileFactory(),destinationName, 10 * 1024);
+ threads[i] = new GetPageThread();
+ threads[i].start();
}
+ latchPositioned.await();
+ latchReady.countDown();
+
+ for (GetPageThread thread: threads)
+ {
+ thread.join();
+ if (thread.e != null)
+ {
+ throw thread.e;
+ }
+ }
+
+ EasyMock.verify(spi, factory);
+
}
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
}
Modified: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java 2008-08-12 21:52:13 UTC (rev 4797)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java 2008-08-12 23:51:48 UTC (rev 4798)
@@ -53,6 +53,22 @@
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+
+ public void testDoubleStart() throws Exception
+ {
+ SequentialFileFactory factory = new FakeSequentialFileFactory();
+
+ PagingStore storeImpl = new PagingStoreImpl(factory, "test", 1024 * 2);
+
+ storeImpl.start();
+
+ // this is not supposed to throw an exception.
+ // As you could have start being called twice as Stores are dynamically created, on a multi-thread environment
+ storeImpl.start();
+
+ storeImpl.stop();
+
+ }
public void testStore() throws Exception
{
More information about the jboss-cvs-commits
mailing list