Skip to content
Permalink
Browse files
Ignore test mails found from previous runs (see jira POSTAGE-10)
git-svn-id: https://svn.apache.org/repos/asf/james/postage/trunk@438486 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Bernd Fondermann committed Aug 30, 2006
1 parent eebf979 commit 619ac6e5007a9fcdf6175f4182f301839d25984c
Showing 8 changed files with 38 additions and 25 deletions.
@@ -73,6 +73,17 @@ public class PostageRunner implements Runnable {

private int m_minutesRunning = 0;

/**
* defines the prefix for every mail id generated by the current runner, so they can be distinguished from
* next runs. the runner instance is responsable to initializing this value!
* NOTE: this construct becomes a problem when two runners are running in parallel
*/
private static String m_messageIdPrefix = null;

public static String getMessageIdPrefix() {
return m_messageIdPrefix + "-";
}

/**
* sends messages to James in two ways:
* 1. internal users relay to internal or external users using (inbound) SMTP
@@ -85,7 +96,9 @@ public class PostageRunner implements Runnable {
* @param postageConfiguration
*/
public PostageRunner(PostageConfiguration postageConfiguration) {
m_postageConfiguration = postageConfiguration;
m_messageIdPrefix = "" + System.currentTimeMillis();

m_postageConfiguration = postageConfiguration;

int totalMailsPerMin = m_postageConfiguration.getTotalMailsPerMin();
int durationMinutes = m_postageConfiguration.getDurationMinutes();
@@ -28,7 +28,7 @@
import org.apache.james.postage.SamplingException;
import org.apache.james.postage.StartupException;
import org.apache.james.postage.execution.Sampler;
import org.apache.james.postage.mail.HeaderConstants;
import org.apache.james.postage.mail.MailMatchingUtils;
import org.apache.james.postage.result.MailProcessingRecord;
import org.apache.james.postage.result.PostageRunnerResult;
import org.apache.james.postage.user.UserList;
@@ -42,7 +42,6 @@
import java.io.InputStream;
import java.io.Reader;
import java.util.Iterator;
import java.util.List;

public class POP3Client implements Sampler {

@@ -117,8 +116,6 @@ private void findAllMatchingTestMail(String username) throws SamplingException {
try {
org.apache.commons.net.pop3.POP3Client pop3Client = openConnection(username);



// retrieve all messages
POP3MessageInfo[] entries = null;
try {
@@ -173,19 +170,9 @@ private void analyzeAndMatch(Reader mailReader, MailProcessingRecord mailProcess

InputStream in = new ReaderInputStream(mailReader);
MimeMessage message;
String id = null;
try {
message = new MimeMessage(null, in);
in.close();

String[] idHeaders = message.getHeader(HeaderConstants.MAIL_ID_HEADER);
if (idHeaders != null && idHeaders.length > 0) {
id = idHeaders[0]; // there should be exactly one.
}
if (id == null) {
log.info("skipping non-postage mail. remains on server. subject was: " + message.getSubject());
return;
}
} catch (IOException e) {
log.info("failed to close mail reader.");
return;
@@ -194,6 +181,10 @@ private void analyzeAndMatch(Reader mailReader, MailProcessingRecord mailProcess
return;
}


if (!MailMatchingUtils.isMatchCandidate(message)) return;

String id = MailMatchingUtils.getMailIdHeader(message);
try {
mailProcessingRecord.setByteReceivedTotal(message.getSize());

@@ -22,6 +22,7 @@

import org.apache.james.postage.SamplingException;
import org.apache.james.postage.StartupException;
import org.apache.james.postage.mail.HeaderConstants;
import org.apache.james.postage.configuration.MailSender;
import org.apache.james.postage.execution.Sampler;
import org.apache.james.postage.result.MailProcessingRecord;
@@ -62,6 +63,7 @@ public boolean checkAvailability() throws StartupException {

MailProcessingRecord proformaMailProcessingRecord = new MailProcessingRecord();
Session session = getMailSession();
proformaMailProcessingRecord.setMailId(HeaderConstants.JAMES_POSTAGE_STARTUPCHECK_HEADER_ID);
Message message = m_mailSender.createMail(session, proformaMailProcessingRecord);
setMailFromAndTo(message, proformaMailProcessingRecord);
Transport.send(message);
@@ -83,7 +83,7 @@ public JVMResourceSampler(String host, int port, PostageRunnerResult results) {
public void connectRemoteJamesJMXServer() throws SamplingException {
if(jvmResourceSampleWorker == null) throw new SamplingException("JSE specific features not present. (compile the project with JSE 5)");
try {
m_connectMethod.invoke(jvmResourceSampleWorker, VOID_ARGUMENT_LIST);
m_connectMethod.invoke(jvmResourceSampleWorker, (Object[])VOID_ARGUMENT_LIST);
} catch (Exception e) {
throw new SamplingException("could not establish connection to remote James JMX. is James really configured for JMX and running under JSE5 or later?");
}
@@ -92,7 +92,7 @@ public void connectRemoteJamesJMXServer() throws SamplingException {
public void doSample() throws SamplingException {
if(jvmResourceSampleWorker == null) throw new SamplingException("JSE specific features not present. (compile the project with JSE 5)");
try {
m_doSampleMethod.invoke(jvmResourceSampleWorker, VOID_ARGUMENT_LIST);
m_doSampleMethod.invoke(jvmResourceSampleWorker, (Object[])VOID_ARGUMENT_LIST);
} catch (Exception e) {
throw new SamplingException(e);
}
@@ -63,6 +63,10 @@ public Message createMail(Session mailSession, MailSender mailSender, MailProces

if (mailProcessingRecord.getMailId() != null) {
message.addHeader(HeaderConstants.MAIL_ID_HEADER, mailProcessingRecord.getMailId());
} else {
// TODO resolve situations when ID is null
log.warn("ID header is NULL!");
throw new RuntimeException("could not create mail with ID = NULL");
}

if (mailSender.sendTextPart()) {
@@ -26,4 +26,6 @@
public class HeaderConstants {
public static final String MAIL_ID_HEADER = "X-James-Postage-Count";
public static final String JAMES_POSTAGE_HEADER = "X-James-Postage";

public static final String JAMES_POSTAGE_STARTUPCHECK_HEADER_ID = "PROFORMA";
}
@@ -20,6 +20,8 @@

package org.apache.james.postage.result;

import org.apache.james.postage.PostageRunner;

/**
* contains all gathered data concerning one mail message
*/
@@ -37,8 +39,8 @@ public class MailProcessingRecord {
String senderMailAddress;
String receiver;
String receiverMailAddress;
long timeSendStart;
long timeSendEnd;
long timeSendStart;
long byteSendText;
long byteSendBinary;
int errorNumberSending;
@@ -54,7 +56,7 @@ public class MailProcessingRecord {
String receivingQueue;

public synchronized static String getNextId() {
return "" + (m_messageId++);
return PostageRunner.getMessageIdPrefix() + (m_messageId++);
}

public boolean isMatchedSentAndReceived() {
@@ -25,6 +25,7 @@
import org.apache.james.postage.result.MailProcessingRecord;
import org.apache.james.postage.result.PostageRunnerResult;
import org.apache.james.postage.mail.HeaderConstants;
import org.apache.james.postage.mail.MailMatchingUtils;
import org.apache.james.services.MailRepository;
import org.apache.james.services.MailServer;
import org.apache.mailet.Mail;
@@ -58,12 +59,10 @@ public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg)
mailProcessingRecord.setByteReceivedTotal(msg.getSize());

try {
String[] id = msg.getHeader(HeaderConstants.MAIL_ID_HEADER);
if (id == null || id.length == 0 ) {
log.info("skipping non-postage mail. message is lost. subject was: " + msg.getSubject());
return;
}
mailProcessingRecord.setMailId(id[0]);
if (!MailMatchingUtils.isMatchCandidate(msg)) return;

String id = MailMatchingUtils.getMailIdHeader(msg);
mailProcessingRecord.setMailId(id);

String[] subjectHeader = msg.getHeader("Subject");
if (subjectHeader != null && subjectHeader.length > 0) {

0 comments on commit 619ac6e

Please sign in to comment.