<commit_before>package io.vertx.ext.mail;

import io.vertx.core.Vertx;
import io.vertx.core.net.NetServer;
import io.vertx.core.net.NetServerOptions;

/*
 * really dumb mock test server that just replays a number of lines
 * as response. this doesn't check any conditions at all.  
 */
public class TestSmtpServer {

  private NetServer netServer;
  private String answers;

  /*
   * set up server with a default reply
   * that works for EHLO and no login
   * with one recipient
   */
  public TestSmtpServer(Vertx vertx) {
    setAnswers("220 example.com ESMTP",
        "250-example.com",
        "250-SIZE 1000000",
        "250 PIPELINING",
        "250 2.1.0 Ok",
        "250 2.1.5 Ok",
        "354 End data with <CR><LF>.<CR><LF>",
        "250 2.0.0 Ok: queued as ABCDDEF0123456789",
        "221 2.0.0 Bye");
    startServer(vertx);
  }

  public TestSmtpServer(Vertx vertx, String answers) {
    setAnswers(answers);
    startServer(vertx);
  }

  public TestSmtpServer(Vertx vertx, String... answers) {
    setAnswers(answers);
    startServer(vertx);
  }

  private void startServer(Vertx vertx) {
    NetServerOptions nsOptions = new NetServerOptions();
    nsOptions.setPort(1587);
    netServer = vertx.createNetServer(nsOptions);

    netServer.connectHandler(socket -> {
      socket.write(answers);
      // wait 10 seconds for the protocol to finish
      vertx.setTimer(10000, v -> socket.close());
    });
    netServer.listen();
  }

  public void setAnswers(String answers) {
    this.answers = answers;
  }

  public void setAnswers(String... answers) {
    this.answers = String.join("\r\n", answers) + "\r\n";
  }

  public void stop() {
    if (netServer != null) {
      netServer.close();
      netServer = null;
    }
  }

}<commit_msg>wait for test server start/stop, hopefully this will fix the occasional connection refused error<commit_after>package io.vertx.ext.mail;

import java.util.concurrent.CountDownLatch;

import io.vertx.core.Vertx;
import io.vertx.core.net.NetServer;
import io.vertx.core.net.NetServerOptions;

/*
 * really dumb mock test server that just replays a number of lines
 * as response. this doesn't check any conditions at all.  
 */
public class TestSmtpServer {

  private NetServer netServer;
  private String answers;

  /*
   * set up server with a default reply
   * that works for EHLO and no login
   * with one recipient
   */
  public TestSmtpServer(Vertx vertx) {
    setAnswers("220 example.com ESMTP",
        "250-example.com",
        "250-SIZE 1000000",
        "250 PIPELINING",
        "250 2.1.0 Ok",
        "250 2.1.5 Ok",
        "354 End data with <CR><LF>.<CR><LF>",
        "250 2.0.0 Ok: queued as ABCDDEF0123456789",
        "221 2.0.0 Bye");
    startServer(vertx);
  }

  public TestSmtpServer(Vertx vertx, String answers) {
    setAnswers(answers);
    startServer(vertx);
  }

  public TestSmtpServer(Vertx vertx, String... answers) {
    setAnswers(answers);
    startServer(vertx);
  }

  private void startServer(Vertx vertx) {
    NetServerOptions nsOptions = new NetServerOptions();
    nsOptions.setPort(1587);
    netServer = vertx.createNetServer(nsOptions);

    netServer.connectHandler(socket -> {
      socket.write(answers);
      // wait 10 seconds for the protocol to finish
      vertx.setTimer(10000, v -> socket.close());
    });
    CountDownLatch latch = new CountDownLatch(1);
    netServer.listen(r -> latch.countDown());
    try {
      latch.await();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }

  public void setAnswers(String answers) {
    this.answers = answers;
  }

  public void setAnswers(String... answers) {
    this.answers = String.join("\r\n", answers) + "\r\n";
  }

  public void stop() {
    if (netServer != null) {
      CountDownLatch latch = new CountDownLatch(1);
      netServer.close(v -> latch.countDown());
      try {
        latch.await();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      netServer = null;
    }
  }

}
{'fraction_non_alphanumeric': 0.1196029776674938, 'fraction_numerical': 0.0337468982630273, 'mean_word_length': 2.7920978363123234, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1080959', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1303, 'n_words': 335}