Java Code Examples for io.vertx.ext.unit.Async#countDown()

The following examples show how to use io.vertx.ext.unit.Async#countDown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 6 votes vote down vote up
/**
 * Tests one response with one line
 */
@Test
public void testOneResponseOneLine(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final String oneLineResp = "250 2.1.0 OK";
  final AtomicBoolean init = new AtomicBoolean(false);
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(oneLineResp, message);
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.handle(Buffer.buffer(oneLineResp + "\r\n"));
}
 
Example 2
Source File: RabbitMQServiceTest.java    From vertx-rabbitmq-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicConsumerWithErrorHandler(TestContext ctx) throws Exception {
  int count = 1;
  Set<String> messages = createMessages(count);
  String q = setupQueue(ctx, messages, "application/json");

  Async latch = ctx.async(count);

  Handler<Throwable> errorHandler = throwable -> latch.countDown();

  client.basicConsumer(q, ctx.asyncAssertSuccess(consumer -> {
    consumer.exceptionHandler(errorHandler);
    consumer.handler(json -> {
      throw new IllegalStateException("Getting message with malformed json");
    });
  }));
}
 
Example 3
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * Tests one response with multiple lines.
 *
 * Capabilities declared by SMTP server are good example here.
 */
@Test
public void testOneResponseMultiLines(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final AtomicBoolean init = new AtomicBoolean(false);
  final String capaMessage = "250-smtp.gmail.com at your service, [209.132.188.80]\n" +
    "250-AUTH LOGIN PLAIN\n" +
    "250 PIPELINING";
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(capaMessage, message);
      Capabilities capa = new Capabilities();
      capa.parseCapabilities(message);
      testContext.assertTrue(capa.isCapaPipelining());
      testContext.assertFalse(capa.isStartTLS());
      testContext.assertEquals(2, capa.getCapaAuth().size());
      testContext.assertTrue(capa.getCapaAuth().contains("LOGIN"));
      testContext.assertTrue(capa.getCapaAuth().contains("PLAIN"));
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.handle(Buffer.buffer(capaMessage + "\r\n"));
}
 
Example 4
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * Tests one response with multiple lines with crlf ends for each line
 *
 * Capabilities declared by SMTP server are good example here.
 */
@Test
public void testOneResponseMultiLinesEndwithCRLF(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final AtomicBoolean init = new AtomicBoolean(false);
  final String capaMessage = "250-smtp.gmail.com at your service, [209.132.188.80]\r\n" +
    "250-AUTH LOGIN PLAIN\r\n" +
    "250 PIPELINING";
  final String expected = "250-smtp.gmail.com at your service, [209.132.188.80]\n" +
    "250-AUTH LOGIN PLAIN\n" +
    "250 PIPELINING";
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(expected, message);
      Capabilities capa = new Capabilities();
      capa.parseCapabilities(message);
      testContext.assertTrue(capa.isCapaPipelining());
      testContext.assertFalse(capa.isStartTLS());
      testContext.assertEquals(2, capa.getCapaAuth().size());
      testContext.assertTrue(capa.getCapaAuth().contains("LOGIN"));
      testContext.assertTrue(capa.getCapaAuth().contains("PLAIN"));
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.handle(Buffer.buffer(capaMessage + "\r\n"));
}
 
Example 5
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * Tests multi responses, each response has one line
 */
@Test
public void testMultiResponseMultiLines(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final AtomicBoolean init = new AtomicBoolean(false);
  final String multilines = "250 2.1.0 OK1\r\n" +
    "250 2.1.1 OK2\r\n" +
    "250 2.1.2 OK3";
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(multilines, message);
      String[] lines = message.split("\r\n");
      for (String l: lines) {
        System.out.println("Line:" + l + ":-");
      }
      testContext.assertEquals(3, lines.length);
      testContext.assertEquals("250 2.1.0 OK1", lines[0]);
      testContext.assertEquals("250 2.1.1 OK2", lines[1]);
      testContext.assertEquals("250 2.1.2 OK3", lines[2]);
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.setExpected(3);
  multilineParser.handle(Buffer.buffer(multilines + "\r\n"));
}
 
Example 6
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * Tests multi responses, each response has multiple lines
 */
@Test
public void testMultiResponseMultiLinesMore(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final AtomicBoolean init = new AtomicBoolean(false);
  final String multilinesWithLF = "250-2.1.0 OK1\n250 2.1.0.1 OK1.1\r\n" +
    "250 2.1.1 OK2\r\n" +
    "250 2.1.2 OK3";
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(multilinesWithLF, message);
      String[] lines = message.split("\r\n");
      testContext.assertEquals(3, lines.length);
      testContext.assertEquals("250-2.1.0 OK1\n250 2.1.0.1 OK1.1", lines[0]);
      testContext.assertEquals("250 2.1.1 OK2", lines[1]);
      testContext.assertEquals("250 2.1.2 OK3", lines[2]);
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.setExpected(3);
  multilineParser.handle(Buffer.buffer(multilinesWithLF + "\r\n"));
}
 
Example 7
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * Tests multi responses, each response has multiple lines with crlf ended for each line
 */
@Test
public void testMultiResponseMultiLinesEndswithCRLFMore(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final AtomicBoolean init = new AtomicBoolean(false);
  final String multilinesWithLF = "250-2.1.0 OK1\r\n250 2.1.0.1 OK1.1\r\n" +
    "250 2.1.1 OK2\r\n" +
    "250 2.1.2 OK3";
  final String expected = "250-2.1.0 OK1\n250 2.1.0.1 OK1.1\r\n" +
    "250 2.1.1 OK2\r\n" +
    "250 2.1.2 OK3";
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(expected, message);
      String[] lines = message.split("\r\n");
      testContext.assertEquals(3, lines.length);
      testContext.assertEquals("250-2.1.0 OK1\n250 2.1.0.1 OK1.1", lines[0]);
      testContext.assertEquals("250 2.1.1 OK2", lines[1]);
      testContext.assertEquals("250 2.1.2 OK3", lines[2]);
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.setExpected(3);
  multilineParser.handle(Buffer.buffer(multilinesWithLF + "\r\n"));
}
 
Example 8
Source File: ShellTest.java    From vertx-shell with Apache License 2.0 4 votes vote down vote up
@Test
public void testResumeProcessToBackground(TestContext context) throws Exception {
  TestTtyConnection conn = new TestTtyConnection(vertx);
  ShellImpl shell = createShell(conn);
  shell.init().readline();
  Async latch1 = context.async();
  Async latch2 = context.async();
  Async latch3 = context.async();
  commands.add(CommandBuilder.command("foo").processHandler(process -> {
    Job job = shell.jobController().getJob(1);
    context.assertTrue(process.isForeground());
    process.suspendHandler(v -> {
      context.assertFalse(process.isForeground());
      context.assertEquals(0, latch1.count());
      try {
        process.write("");
        context.fail();
      } catch (IllegalStateException ignore) {
      }
      latch2.countDown();
    });
    process.resumeHandler(v -> {
      context.assertFalse(process.isForeground());
      context.assertEquals(0, latch2.count());
      context.assertEquals(ExecStatus.RUNNING, job.status());
      process.write("");
      context.assertNull(shell.jobController().foregroundJob());
      latch3.awaitSuccess(2000);
      process.write("resumed");
    });
    process.stdinHandler(txt -> {
      context.fail();
    });
    latch1.countDown();
  }));
  conn.read("foo\r");
  latch1.awaitSuccess(10000);
  conn.sendEvent(TtyEvent.SUSP);
  latch2.awaitSuccess(10000);
  conn.out().setLength(0);
  conn.read("bg\r");
  conn.assertWritten("bg\n[1]+ Running foo\n% ");
  latch3.countDown();
  conn.assertWritten("resumed");
  conn.read("hello");
  conn.assertWritten("hello");
}