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:
154
source/java/org/alfresco/repo/imap/LoadTest.java
Executable file
154
source/java/org/alfresco/repo/imap/LoadTest.java
Executable file
@@ -0,0 +1,154 @@
|
||||
package org.alfresco.repo.imap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.Flags;
|
||||
|
||||
import org.alfresco.repo.importer.ACPImportPackageHandler;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.view.ImporterService;
|
||||
import org.alfresco.service.cmr.view.Location;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import com.icegreen.greenmail.imap.ImapConstants;
|
||||
import com.icegreen.greenmail.store.SimpleStoredMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class LoadTest extends TestCase
|
||||
{
|
||||
private Log logger = LogFactory.getLog(LoadTest.class);
|
||||
|
||||
|
||||
private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||
|
||||
private ImapService imapService;
|
||||
private ImporterService importerService;
|
||||
|
||||
private AlfrescoImapUser user;
|
||||
private static final String USER_NAME = "admin";
|
||||
private static final String USER_PASSWORD = "admin";
|
||||
private static final String TEST_DATA_FOLDER_NAME = "test_data";
|
||||
private static final String TEST_FOLDER_NAME = "test_imap3";
|
||||
private static final long MESSAGE_QUANTITY = 3;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
|
||||
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
|
||||
imapService = serviceRegistry.getImapService();
|
||||
importerService = serviceRegistry.getImporterService();
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
SearchService searchService = serviceRegistry.getSearchService();
|
||||
NamespaceService namespaceService = serviceRegistry.getNamespaceService();
|
||||
|
||||
user = new AlfrescoImapUser(USER_NAME + "@alfresco.com", USER_NAME, USER_PASSWORD);
|
||||
|
||||
authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());
|
||||
|
||||
StoreRef storeRef = new StoreRef("workspace://SpacesStore");
|
||||
NodeRef rootRef = nodeService.getRootNode(storeRef);
|
||||
|
||||
// Delete test folder
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(rootRef, "/app:company_home/imap:imap_home/cm:admin/cm:" + TEST_FOLDER_NAME, null, namespaceService, false);
|
||||
if (nodeRefs.size() == 1)
|
||||
{
|
||||
NodeRef ch = nodeRefs.get(0);
|
||||
nodeService.deleteNode(ch);
|
||||
}
|
||||
// Delete test data folder
|
||||
nodeRefs = searchService.selectNodes(rootRef, "/app:company_home/imap:imap_home/cm:admin/cm:" + TEST_DATA_FOLDER_NAME, null, namespaceService, false);
|
||||
if (nodeRefs.size() == 1)
|
||||
{
|
||||
NodeRef ch = nodeRefs.get(0);
|
||||
nodeService.deleteNode(ch);
|
||||
}
|
||||
|
||||
NodeRef adminNodeRef = searchService.selectNodes(rootRef, "/app:company_home/imap:imap_home/cm:admin", null, namespaceService, false).get(0);
|
||||
importTestData("test-resources/load_test_data.acp", adminNodeRef);
|
||||
|
||||
|
||||
AlfrescoImapFolder testDataFolder = imapService.getFolder(user, TEST_DATA_FOLDER_NAME);
|
||||
// FileInfo fileInfo = imapService.searchMails(drafts.getFolderInfo().getNodeRef(), "*", AlfrescoImapConst.MODE_ARCHIVE, false).get(0);
|
||||
// SimpleStoredMessage m = drafts.createImapMessage(fileInfo, (long)0, true);
|
||||
|
||||
// imapService.setExtractAttachmentsEnabled(false);
|
||||
SimpleStoredMessage m = testDataFolder.getMessages().get(0);
|
||||
m = testDataFolder.getMessage(m.getUid());
|
||||
|
||||
|
||||
|
||||
|
||||
AlfrescoImapFolder folder = imapService.createMailbox(user, TEST_FOLDER_NAME);
|
||||
|
||||
logger.info("Creating folders...");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < MESSAGE_QUANTITY; i++)
|
||||
{
|
||||
System.out.println("i = " + i);
|
||||
// folder.appendMessageInternal(message, new Flags(), new Date());
|
||||
folder.appendMessage(m.getMimeMessage(), new Flags(), new Date());
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error(e, e);
|
||||
}
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
logger.info("Create time: " + t + " ms (" + t/1000 + " s (" + t/60000 + " min))");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void testList()
|
||||
{
|
||||
logger.info("Listing folders...");
|
||||
|
||||
long t = System.currentTimeMillis();
|
||||
List<AlfrescoImapFolder> list = imapService.listMailboxes(user, TEST_FOLDER_NAME + "*");
|
||||
t = System.currentTimeMillis() - t;
|
||||
|
||||
logger.info("List time: " + t + " ms (" + t/1000 + " s)");
|
||||
logger.info("List size: " + list.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void importTestData(String acpName, NodeRef space) throws IOException
|
||||
{
|
||||
ClassPathResource acpResource = new ClassPathResource(acpName);
|
||||
ACPImportPackageHandler acpHandler = new ACPImportPackageHandler(acpResource.getFile(), null);
|
||||
Location importLocation = new Location(space);
|
||||
importerService.importView(acpHandler, importLocation, null, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user