Created
October 19, 2011 13:17
-
-
Save normanmaurer/1298253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.normanmaurer.niosmtp; | |
import java.io.ByteArrayInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.InetSocketAddress; | |
import java.util.Arrays; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.Semaphore; | |
import me.normanmaurer.niosmtp.client.DeliveryResult; | |
import me.normanmaurer.niosmtp.client.SMTPClient; | |
import me.normanmaurer.niosmtp.client.SMTPClientFuture; | |
import me.normanmaurer.niosmtp.client.SMTPClientFutureListener; | |
import me.normanmaurer.niosmtp.client.SMTPClientImpl; | |
import me.normanmaurer.niosmtp.core.SMTPClientConfigImpl; | |
import me.normanmaurer.niosmtp.transport.impl.NettySMTPClientTransport; | |
import org.junit.Test; | |
public class Bechmark { | |
private final static byte[] DATA = new byte[5000]; | |
static { | |
for (int i = 0 ; i < DATA.length; i++) { | |
DATA[i] = (byte)i; | |
} | |
} | |
private final static MessageInput INPUT = new MessageInput() { | |
@Override | |
public InputStream get8Bit() throws IOException { | |
return new ByteArrayInputStream(DATA); | |
} | |
@Override | |
public InputStream get7bit() throws IOException { | |
return new ByteArrayInputStream(DATA); | |
} | |
}; | |
@Test | |
public void benchmark() throws InterruptedException, ExecutionException { | |
final SMTPClient client = new SMTPClientImpl(NettySMTPClientTransport.createPlain()); | |
final Semaphore semaphore = new Semaphore(100); | |
final CountDownLatch latch = new CountDownLatch(1000); | |
final long time = System.currentTimeMillis(); | |
for (int i = 0; i < 1000; i++){ | |
semaphore.acquire(); | |
SMTPClientFuture future = client.deliver(new InetSocketAddress("213.157.0.216", 8080), "test@localhost", Arrays.asList("test@localhost"), INPUT, new SMTPClientConfigImpl()); | |
future.addListener(new SMTPClientFutureListener() { | |
@Override | |
public void operationComplete(DeliveryResult result) { | |
latch.countDown(); | |
semaphore.release(); | |
} | |
}); | |
} | |
latch.await(); | |
System.out.println("sec " +( System.currentTimeMillis() -time) / 1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment