Author: bago
Date: Sun May 7 07:46:33 2006
New Revision: 404773
URL: http://svn.apache.org/viewcvs?rev=404773&view=rev
Log:
Refactored the MimeMessageCopyOnWriteProxyTest and added a proof of a bug
(maybe related to JAMES-474)
Modified:
james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
Modified:
james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
URL:
http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java?rev=404773&r1=404772&r2=404773&view=diff
==============================================================================
---
james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
(original)
+++
james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
Sun May 7 07:46:33 2006
@@ -20,12 +20,10 @@
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
-import javax.mail.util.SharedByteArrayInputStream;
-
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
+import javax.mail.util.SharedByteArrayInputStream;
-import java.io.IOException;
import java.util.ArrayList;
public class MimeMessageCopyOnWriteProxyTest extends MimeMessageFromStreamTest
{
@@ -34,7 +32,6 @@
String content = "Subject: foo\r\nContent-Transfer-Encoding2: plain";
String sep = "\r\n\r\n";
String body = "bar\r\n.\r\n";
- MailImpl mail;
protected MimeMessage getMessageFromSources(String sources) throws
Exception {
MimeMessageInputStreamSource mmis = null;
@@ -46,20 +43,10 @@
// return new MimeMessage(Session.getDefaultInstance(new
Properties()),new ByteArrayInputStream(sources.getBytes()));
}
- protected void setUp() throws Exception {
- mw = (MimeMessageCopyOnWriteProxy)
getMessageFromSources(content+sep+body);
- }
-
-
- protected void tearDown() throws Exception {
- ContainerUtil.dispose(mw);
- }
-
-
- public void testMessageCloning1() throws MessagingException, IOException {
+ public void testMessageCloning1() throws Exception {
ArrayList r = new ArrayList();
r.add(new MailAddress("[EMAIL PROTECTED]"));
- mail = new MailImpl("test",new MailAddress("[email protected]"),r,mw);
+ MailImpl mail = new MailImpl("test",new
MailAddress("[email protected]"),r,(MimeMessageCopyOnWriteProxy)
getMessageFromSources(content+sep+body));
MailImpl m2 = (MailImpl) mail.duplicate();
System.out.println("mail: "+getReferences(mail.getMessage())+" m2:
"+getReferences(m2.getMessage()));
assertNotSame(m2,mail);
@@ -74,13 +61,14 @@
// test it is different after a write operation!
mail.getMessage().setSubject("new Subject");
assertTrue(!isSameMimeMessage(m2.getMessage(),mail.getMessage()));
+ ContainerUtil.dispose(mail);
}
- public void testMessageCloning2() throws MessagingException, IOException {
+ public void testMessageCloning2() throws Exception {
ArrayList r = new ArrayList();
r.add(new MailAddress("[EMAIL PROTECTED]"));
- mail = new MailImpl("test",new MailAddress("[email protected]"),r,mw);
+ MailImpl mail = new MailImpl("test",new
MailAddress("[email protected]"),r,(MimeMessageCopyOnWriteProxy)
getMessageFromSources(content+sep+body));
MailImpl m2 = (MailImpl) mail.duplicate();
System.out.println("mail: "+getReferences(mail.getMessage())+" m2:
"+getReferences(m2.getMessage()));
assertNotSame(m2,mail);
@@ -114,12 +102,13 @@
m2clone.getMessage().setSubject("new Subject 2");
m2clone.getMessage().setText("new Body 3");
assertTrue(isSameMimeMessage(m2clone.getMessage(),mm));
+ ContainerUtil.dispose(mail);
}
- public void testMessageAvoidCloning() throws MessagingException,
IOException {
+ public void testMessageAvoidCloning() throws Exception {
ArrayList r = new ArrayList();
r.add(new MailAddress("[EMAIL PROTECTED]"));
- mail = new MailImpl("test",new MailAddress("[email protected]"),r,mw);
+ MailImpl mail = new MailImpl("test",new
MailAddress("[email protected]"),r,(MimeMessageCopyOnWriteProxy)
getMessageFromSources(content+sep+body));
// cloning the message
Mail mailClone = mail.duplicate();
assertTrue(isSameMimeMessage(mailClone.getMessage(),mail.getMessage()));
@@ -127,6 +116,9 @@
assertNotSame(mail.getMessage(),mailClone.getMessage());
// dispose mail and check that the clone has still a valid message and
it is the same!
ContainerUtil.dispose(mail);
+ // need to add a gc and a wait, because the original mimemessage
should be finalized before the test.
+ System.gc();
+ Thread.sleep(1000);
// dumb test
assertTrue(isSameMimeMessage(mailClone.getMessage(),mailClone.getMessage()));
// change the message that should be not referenced by mail that has
@@ -134,13 +126,14 @@
mailClone.getMessage().setSubject("new Subject 2");
mailClone.getMessage().setText("new Body 3");
assertTrue(isSameMimeMessage(mailClone.getMessage(),mm));
+ ContainerUtil.dispose(mail);
}
- public void testMessageDisposing() throws MessagingException, IOException {
+ public void testMessageDisposing() throws Exception {
ArrayList r = new ArrayList();
r.add(new MailAddress("[EMAIL PROTECTED]"));
- mail = new MailImpl("test",new MailAddress("[email protected]"),r,mw);
+ MailImpl mail = new MailImpl("test",new
MailAddress("[email protected]"),r,(MimeMessageCopyOnWriteProxy)
getMessageFromSources(content+sep+body));
// cloning the message
MailImpl mailClone = (MailImpl) mail.duplicate();
ContainerUtil.dispose(mail);
@@ -152,6 +145,28 @@
assertNull(mailClone.getMessage());
assertNull(mail.getMessage());
+ ContainerUtil.dispose(mail);
+ }
+
+ public void testNPE1() throws MessagingException, InterruptedException {
+ ArrayList recipients = new ArrayList();
+ recipients.add(new MailAddress("[EMAIL PROTECTED]"));
+ MimeMessageCopyOnWriteProxy mw = new MimeMessageCopyOnWriteProxy(
+ new MimeMessageInputStreamSource(
+ "test",
+ new SharedByteArrayInputStream(
+ ("Return-path: [EMAIL PROTECTED]"+
+ "Content-Transfer-Encoding: plain\r\n"+
+ "Subject: test\r\n\r\n"+
+ "Body Text\r\n").getBytes())));
+
+ MimeMessageCopyOnWriteProxy mw2 = new MimeMessageCopyOnWriteProxy(mw);
+ ContainerUtil.dispose(mw2);
+ mw2 = null;
+ System.gc();
+ Thread.sleep(1000);
+ mw.getMessageSize();
+
}
private static String getReferences(MimeMessage m) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]