fix plist destroy, intermittent failure of src/test/java/org/apache/activemq/broker/region/QueuePurgeTest.java

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@911055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2010-02-17 16:29:16 +00:00
parent 75a32e4ec7
commit af31f2dc00
3 changed files with 30 additions and 9 deletions

View File

@ -117,10 +117,10 @@ public class PList {
void destroy(Transaction tx) throws IOException {
// start from the first
EntryLocation entry = loadEntry(tx, getRoot(tx).getNext());
EntryLocation entry = getFirst(tx);
while (entry != null) {
EntryLocation toRemove = entry.copy();
entry = loadEntry(tx, entry.getNext());
entry = getNext(tx, entry.getNext());
doRemove(tx, toRemove);
}
}

View File

@ -137,6 +137,7 @@ public class QueuePurgeTest extends TestCase {
LOG.info("purge done: " + (System.currentTimeMillis() - start) + "ms");
assertEquals("Queue size is not zero, it's " + proxy.getQueueSize(), 0,
proxy.getQueueSize());
assertEquals("usage goes to duck", 0, proxy.getMemoryPercentUsage());
}
private QueueViewMBean getProxyToQueueViewMBean()

View File

@ -17,11 +17,13 @@
package org.apache.activemq.store.kahadb.plist;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNull;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.activemq.util.IOHelper;
import org.apache.kahadb.util.ByteSequence;
import org.junit.After;
@ -32,8 +34,6 @@ public class PListTest {
private PListStore store;
private PList plist;
@Test
@ -82,7 +82,10 @@ public class PListTest {
@Test
public void testRemove() throws IOException {
final int COUNT = 2000;
doTestRemove(2000);
}
protected void doTestRemove(final int COUNT) throws IOException {
Map<String, ByteSequence> map = new LinkedHashMap<String, ByteSequence>();
for (int i = 0; i < COUNT; i++) {
String test = new String("test" + i);
@ -100,9 +103,26 @@ public class PListTest {
}
//@Test
public void testDestroy() {
fail("Not yet implemented");
@Test
public void testDestroy() throws Exception {
doTestRemove(1);
plist.destroy();
assertEquals(0,plist.size());
}
@Test
public void testDestroyNonEmpty() throws Exception {
final int COUNT = 1000;
Map<String, ByteSequence> map = new LinkedHashMap<String, ByteSequence>();
for (int i = 0; i < COUNT; i++) {
String test = new String("test" + i);
ByteSequence bs = new ByteSequence(test.getBytes());
map.put(test, bs);
plist.addLast(test, bs);
}
plist.destroy();
assertEquals(0,plist.size());
assertNull("no first entry", plist.getFirst());
}
@Before