mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged DEV/IMAP3 to HEAD
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14654 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
161
source/java/org/alfresco/repo/imap/RemoteLoadTest.java
Executable file
161
source/java/org/alfresco/repo/imap/RemoteLoadTest.java
Executable file
@@ -0,0 +1,161 @@
|
||||
package org.alfresco.repo.imap;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.Folder;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Store;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.sun.mail.util.BASE64DecoderStream;
|
||||
|
||||
public class RemoteLoadTest extends TestCase
|
||||
{
|
||||
|
||||
private Log logger = LogFactory.getLog(LoadTest.class);
|
||||
|
||||
private static final String USER_NAME = "admin";
|
||||
private static final String USER_PASSWORD = "admin";
|
||||
private static final String TEST_FOLDER_NAME = "test_imap1000";
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testMailbox()
|
||||
{
|
||||
logger.info("Getting folder...");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
String host = "localhost";
|
||||
|
||||
// Create empty properties
|
||||
Properties props = new Properties();
|
||||
|
||||
// Get session
|
||||
Session session = Session.getDefaultInstance(props, null);
|
||||
|
||||
Store store = null;
|
||||
Folder folder = null;
|
||||
try
|
||||
{
|
||||
// Get the store
|
||||
store = session.getStore("imap");
|
||||
store.connect(host, USER_NAME, USER_PASSWORD);
|
||||
|
||||
// Get folder
|
||||
folder = store.getFolder(TEST_FOLDER_NAME);
|
||||
folder.open(Folder.READ_ONLY);
|
||||
|
||||
// Get directory
|
||||
Message message[] = folder.getMessages();
|
||||
|
||||
for (int i = 0, n = message.length; i < n; i++)
|
||||
{
|
||||
message[i].getAllHeaders();
|
||||
|
||||
Address[] from = message[i].getFrom();
|
||||
System.out.print(i + ": ");
|
||||
if (from != null)
|
||||
{
|
||||
System.out.print(message[i].getFrom()[0] + "\t");
|
||||
}
|
||||
System.out.println(message[i].getSubject());
|
||||
|
||||
Object content = message[i].getContent();
|
||||
if (content instanceof MimeMultipart)
|
||||
{
|
||||
for (int j = 0, m = ((MimeMultipart)content).getCount(); j < m; j++)
|
||||
{
|
||||
BodyPart part = ((MimeMultipart)content).getBodyPart(j);
|
||||
Object partContent = part.getContent();
|
||||
|
||||
if (partContent instanceof String)
|
||||
{
|
||||
String body = (String)partContent;
|
||||
}
|
||||
else if (partContent instanceof FilterInputStream)
|
||||
{
|
||||
FilterInputStream fis = (FilterInputStream)partContent;
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
|
||||
/* while (bis.available() > 0)
|
||||
{
|
||||
bis.read();
|
||||
}*/
|
||||
byte[] bytes = new byte[524288];
|
||||
while (bis.read(bytes) != -1)
|
||||
{
|
||||
}
|
||||
bis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int nn = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
logger.info("Time: " + t + " ms (" + t/1000 + " s)");
|
||||
logger.info("Length: " + message.length);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error(e.getMessage(), e);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close connection
|
||||
try
|
||||
{
|
||||
if (folder != null)
|
||||
{
|
||||
folder.close(false);
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
logger.error(e.getMessage(), e);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
try
|
||||
{
|
||||
if (store != null)
|
||||
{
|
||||
store.close();
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
logger.error(e.getMessage(), e);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user