/**
   * Test fanout NATS -> 2 Redis channels Also tests one map present.
   *
   * @throws Exception
   */
  @Test
  public void testNatsSubjectFanoutToRedis() throws Exception {

    int count = 5;

    String config =
        "{"
            + "\"nats_to_redis_map\" : ["
            + "{"
            + "\"subject\" : \"Export.Redis\","
            + "\"channel\" : \"Import_NATS\""
            + "},"
            + "{"
            + "\"subject\" : \"Export.Redis\","
            + "\"channel\" : \"Import_NATS2\""
            + "}"
            + "]"
            + "}";

    System.setProperty(RedisPubSubPlugin.CONFIG_URL, generateContentFile(config));

    Connector c = new Connector();

    ExecutorService executor = Executors.newFixedThreadPool(10);

    RedisSubscriber rs1 = new RedisSubscriber("rs1", "Import_NATS", count);
    RedisSubscriber rs2 = new RedisSubscriber("rs2", "Import_NATS2", count);

    NatsPublisher np1 = new NatsPublisher("np1", "Export.Redis", count);

    // start the connector
    executor.execute(c);

    // start the subsciber apps
    executor.execute(rs1);
    executor.execute(rs2);

    // wait for subscribers to be ready.
    rs1.waitUntilReady();
    rs2.waitUntilReady();

    // let the connector start
    Thread.sleep(1000);

    // start the publishers
    executor.execute(np1);

    // wait for the subscribers to complete.
    rs1.waitForCompletion();
    rs2.waitForCompletion();

    Assert.assertTrue("Invalid count", rs1.getMessageCount() == count);
    Assert.assertTrue("Invalid count", rs2.getMessageCount() == count);

    c.shutdown();
  }
  @Test
  public void testNatsToRedis() throws Exception {

    System.clearProperty(RedisPubSubPlugin.CONFIG_URL);

    Connector c = new Connector();

    ExecutorService executor = Executors.newFixedThreadPool(6);

    RedisSubscriber rs = new RedisSubscriber("rs", "Import_NATS", 5);
    NatsPublisher np = new NatsPublisher("np", "Export.Redis", 5);

    // start the connector
    executor.execute(c);

    // start the subsciber
    executor.execute(rs);

    // wait for subscriber to be ready.
    rs.waitUntilReady();

    // let the connector start
    Thread.sleep(2000);

    // start the publisher
    executor.execute(np);

    // wait for the subscribers to complete.
    rs.waitForCompletion();

    Assert.assertTrue("Invalid count", rs.getMessageCount() == 5);

    c.shutdown();
  }
  private void testOneToOneWithDefaultConfig(int count) throws Exception {

    System.clearProperty(RedisPubSubPlugin.CONFIG_URL);

    Connector c = new Connector();

    ExecutorService executor = Executors.newFixedThreadPool(6);

    RedisSubscriber rs = new RedisSubscriber("rs", "Import_NATS", count);
    RedisPublisher rp = new RedisPublisher("rp", "Export_NATS", count);

    NatsPublisher np = new NatsPublisher("np", "Export.Redis", count);
    NatsSubscriber ns = new NatsSubscriber("ns", "Import.Redis", count);

    // start the connector
    executor.execute(c);

    // start the subsciber apps
    executor.execute(rs);
    executor.execute(ns);

    // wait for subscribers to be ready.
    rs.waitUntilReady();
    ns.waitUntilReady();

    // let the connector start
    Thread.sleep(1000);

    // start the publishers
    executor.execute(np);
    executor.execute(rp);

    // wait for the subscribers to complete.
    rs.waitForCompletion();
    ns.waitForCompletion();

    Assert.assertTrue("Invalid count", rs.getMessageCount() == count);
    Assert.assertTrue("Invalid count", ns.getMessageCount() == count);

    c.shutdown();
  }