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

查看:38
本文介绍了使用 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:

  • 阅读仅由某些邮件标识符标识的特定电子邮件
  • 在文件夹之间移动邮件
  • 将邮件复制到另一个文件夹
  • 标记邮件已读/未读
  • 明确地从垃圾箱中删除邮件等

有没有办法使用一些插件采样器或插件来测试这些其他场景?

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:

参考下面的示例,使用 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 采样器和 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 与 JSR223 与 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天全站免登陆