使用JMeter Mail Reader采样器测试高级方案 [英] Testing advanced scenarios using JMeter Mail Reader sampler

查看:592
本文介绍了使用JMeter Mail Reader采样器测试高级方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用邮件阅读器采样器在Jmeter中编写了一个测试计划,以测试IMAPS服务器.该测试仅允许我从一个文件夹中读取所有邮件,或者从该文件夹中读取x封邮件. (可选)我可以在读取邮件后将其从服务器中删除.

I have written a test plan in Jmeter using the mail reader sampler to test an IMAPS server. The test only allows me to either read all mails from a folder or read x number of mails from the folder. Optionally I can delete the mails from the server after they are read.

但是似乎没有其他选择可以进行其他操作,例如:

However there seem to be no options to do other operations like:

  • 阅读仅由某些邮件标识符标识的特定电子邮件
  • 在文件夹之间移动邮件
  • 将邮件复制到另一个文件夹
  • 标记邮件已读/未读
  • 从垃圾箱中明确删除邮件 等
  • Read a particular email only identified by some mail identifier
  • move mails between folders
  • copy mails to another folder
  • mark mails are read/unread
  • delete mails from trash explicitly etc.

是否可以使用某些插件采样器或插件来测试其他场景?

Is there a way in which these other scenarios can also be tested using some addon sampler or plugin?

如果JMeter不支持此功能,请建议使用任何其他可以进行这种测试的性能测试工具

If JMeter does not support this, kindly suggest any other performance testing tool using which this kind of testing can be done

推荐答案

很遗憾,JMeter Mail Reader Sampler不允许高级操作.但是,可以通过脚本扩展JMeter.

Unfortunately JMeter Mail Reader Sampler doesn't allow advanced operations. However JMeter can be extended by scripting.

因此,您可以使用Java Mail API和所提供的脚本采样器之一来实现所有必需的方法:

So you can implement all required methods using Java Mail API and one of scripting samplers provided:

  • Beanshell Sampler
  • JSR223 Sampler

有关使用Gmail IMAP删除垃圾邮件"文件夹中所有邮件的示例,请参见以下示例:

Refer to example below for deleting all messages from "Spam" folder using IMAP for Gmail:

import com.sun.mail.imap.IMAPSSLStore;
import javax.mail. *;

try {
    Properties properties = props;
    properties.put("mail.smtps.auth", "true");
    properties.put("mail.imap.ssl.enable", "true");
    Session imapsession = Session.getInstance(properties, null);

    imapsession.setDebug(false);
    Store imapstore = new IMAPSSLStore(imapsession, new URLName("imaps", "imap.gmail.com", 993, "", "your.account@gmail.com", "password"));
    imapstore.connect();
    Folder rootfolder = imapstore.getDefaultFolder();
    Folder[] imapfolders = rootfolder.list("*");

    for (Folder folder : imapfolders) {
        if (folder.getName().equals("Spam")) {
            folder.open(Folder.READ_WRITE);
            log.info("Spam folder contains " + folder.getMessageCount() + " messages");
            Message[] messages = folder.getMessages();
            for (Message message : messages) {
                message.setFlag(Flags.Flag.DELETED, true);
                log.info("Marking message with subject: " + message.getSubject() + " for deletion");
            }
            folder.expunge();
            folder.close(true);
        }
    }
    imapstore.close();
} catch (Exception ex) {
    log.error("IMAP operation failed", ex);
}

Beanshell Sampler不需要任何其他配置,您只需复制并粘贴上面的代码即可.

Beanshell Sampler doesn't require any extra configuration, you can just copy and paste the code above.

但是,Beanshell具有众所周知的性能问题和局限性,因此,如果您的测试假设或多或少地承担了高负载,则建议使用JSR223 Sampler和Groovy语言.

However Beanshell has well known performance issues and limitations so if your test assumes more or less high load it's recommended to use JSR223 Sampler and Groovy language.

请参见 Beanshell vs JSR223 vs Java JMeter脚本:性能一直在等待中!脚本引擎比较基准,以获取有关Groovy脚本引擎的更多信息和安装说明.

See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! scripting engines comparison benchmark for more information and installation instructions for Groovy scripting engine.

这篇关于使用JMeter Mail Reader采样器测试高级方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆