Package org.subethamail.smtp

Source Code of org.subethamail.smtp.StartStopTest

package org.subethamail.smtp;

import java.util.Properties;

import javax.mail.Session;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.wiser.Wiser;

/**
* This class attempts to quickly start/stop 10 Wiser servers. It makes sure that the socket bind address is correctly
* shut down.
*
* @author Jon Stevens
*/
public class StartStopTest extends TestCase
{
  /** */
  @SuppressWarnings("unused")
  private static Logger log = LoggerFactory.getLogger(StartStopTest.class);

  /** */
  public static final int PORT = 2566;

  /** */
  protected Session session;

  protected int counter = 0;

  /** */
  public StartStopTest(String name)
  {
    super(name);
  }

  /** */
  @Override
  protected void setUp() throws Exception
  {
    super.setUp();

    Properties props = new Properties();
    props.setProperty("mail.smtp.host", "localhost");
    props.setProperty("mail.smtp.port", Integer.toString(PORT));
    this.session = Session.getDefaultInstance(props);
  }

  /** */
  @Override
  protected void tearDown() throws Exception
  {
    super.tearDown();
  }

  /** */
  public void testMultipleStartStop() throws Exception
  {
    for (int i = 0; i < 10; i++)
    {
      this.startStop(i > 5);
    }
    assertEquals(this.counter, 10);
  }

  /** */
  private void startStop(boolean pause) throws Exception
  {
    Wiser wiser = new Wiser();
    wiser.setPort(PORT);

    wiser.start();

    if (pause)
      Thread.sleep(1000);

    wiser.stop();

    this.counter++;
  }

  /** */
  public static Test suite()
  {
    return new TestSuite(StartStopTest.class);
  }
}
TOP

Related Classes of org.subethamail.smtp.StartStopTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.