activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Zeng (JIRA)" <j...@apache.org>
Subject [jira] Created: (AMQ-1504) Bug in MapContainerImpl and DiskIndexLinkedList
Date Tue, 27 Nov 2007 08:15:27 GMT
Bug in MapContainerImpl and DiskIndexLinkedList
-----------------------------------------------

                 Key: AMQ-1504
                 URL: https://issues.apache.org/activemq/browse/AMQ-1504
             Project: ActiveMQ
          Issue Type: Test
          Components: Message Store
    Affects Versions: 4.1.1
            Reporter: Chris Zeng


package Test;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.MessageAck;
import org.apache.activemq.command.MessageId;
import org.apache.activemq.kaha.StoreFactory;
import org.apache.activemq.store.MessageStore;
import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter;

/**
 * 
 * @author chris
 * 
 */

public class MapContainerImplTest extends TestCase {
	/**
	 * Create the test case
	 * 
	 * @param testName
	 *            name of the test case
	 */

	public MapContainerImplTest(String testName) {
		super(testName);
	}

	/**
	 * @return the suite of tests being tested
	 */
	public static Test suite() {
		return new TestSuite(MapContainerImplTest.class);
	}

	/**
	 * bug exists in MapContainerImpl write method in MapContainerImpl should
	 * refreshEntry after getPrevIndex
	 */
	public void testRemoveLast() {
		try {
			String dir = "C:/Temp/FilePersistenceAdapter";
			StoreFactory.delete(dir + "/kaha.db");

			KahaPersistenceAdapter theAdapter = new KahaPersistenceAdapter(
					new File(dir));

			ActiveMQQueue queue = new ActiveMQQueue("Test");

			MessageStore theStore = theAdapter.createQueueMessageStore(queue);
			ActiveMQTextMessage message = null;
			message = new ActiveMQTextMessage();
			message.setJMSMessageID("4");
			message.setText("TEST");
			theStore.addMessage(null, message);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("3");
			message.setText("TEST");
			theStore.addMessage(null, message);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("2");
			message.setText("TEST");
			theStore.addMessage(null, message);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("1");
			message.setText("TEST");
			theStore.addMessage(null, message);

			MessageAck ack = null;
			ack = new MessageAck();
			ack.setLastMessageId(new MessageId("1"));
			theStore.removeMessage(null, ack);

			ack = new MessageAck();
			ack.setLastMessageId(new MessageId("2"));
			theStore.removeMessage(null, ack);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("5");
			message.setText("TEST");
			theStore.addMessage(null, message);

			theAdapter.stop();

			theAdapter = new KahaPersistenceAdapter(new File(dir));

			queue = new ActiveMQQueue("Test");

			theStore = theAdapter.createQueueMessageStore(queue);
			
			theAdapter.stop();
			
			System.out.println("That is ok!");
			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * Bug exists in DiskIndexLinkedList. After reading index from file, if the index is root
or last,
	 * We should update the data in the root or last object instead of return last or root directly.
	 * If the index is root, we can not simplly write "root = index",  we should update the 
	 * data in this root object, because others are using "this" object.
	 */

	public void testRemoveLast_ThenRemoveTheOneBeforeLast() {
		try {
			String dir = "C:/Temp/FilePersistenceAdapter";
			StoreFactory.delete(dir + "/kaha.db");

			KahaPersistenceAdapter theAdapter = new KahaPersistenceAdapter(
					new File(dir));

			ActiveMQQueue queue = new ActiveMQQueue("Test");

			MessageStore theStore = theAdapter.createQueueMessageStore(queue);

			ActiveMQTextMessage message = null;

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("4");
			message.setText("TEST");
			theStore.addMessage(null, message);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("3");
			message.setText("TEST");
			theStore.addMessage(null, message);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("2");
			message.setText("TEST");
			theStore.addMessage(null, message);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("1");
			message.setText("TEST");
			theStore.addMessage(null, message);

			MessageAck ack = null;
			ack = new MessageAck();
			ack.setLastMessageId(new MessageId("1"));
			theStore.removeMessage(null, ack);

			ack = new MessageAck();
			ack.setLastMessageId(new MessageId("3"));
			theStore.removeMessage(null, ack);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("3");
			message.setText("TEST");
			theStore.addMessage(null, message);

			message = new ActiveMQTextMessage();
			message.setJMSMessageID("1");
			message.setText("TEST");
			theStore.addMessage(null, message);

			theAdapter.stop();

			theAdapter = new KahaPersistenceAdapter(new File(dir));

			queue = new ActiveMQQueue("Test");

			theStore = theAdapter.createQueueMessageStore(queue);
			
			theStore.stop();
			
			System.out.println("That is ok!");

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}


we can not see the out in the console.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message