コード例 #1
0
  @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();
  }
コード例 #2
0
  @Test
  public void testNatsSubjectFanIntoRedis() throws Exception {

    int count = 5;

    String config =
        "{"
            + "\"nats_to_redis_map\" : ["
            + "{"
            + "\"subject\" : \"Export.Redis1\","
            + "\"channel\" : \"Import_NATS\""
            + "},"
            + "{"
            + "\"subject\" : \"Export.Redis2\","
            + "\"channel\" : \"Import_NATS\""
            + "},"
            + "{"
            + "\"subject\" : \"Export.Redis3\","
            + "\"channel\" : \"Import_NATS\""
            + "}"
            + "]"
            + "}";

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

    Connector c = new Connector();

    ExecutorService executor = Executors.newFixedThreadPool(10);

    NatsPublisher np1 = new NatsPublisher("np1", "Export.Redis1", count);
    NatsPublisher np2 = new NatsPublisher("np2", "Export.Redis2", count);
    NatsPublisher np3 = new NatsPublisher("np3", "Export.Redis3", count);

    RedisSubscriber rs1 = new RedisSubscriber("rs1", "Import_NATS", count * 3);

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

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

    // start the connector
    executor.execute(c);
    Thread.sleep(1000);
    ;

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

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

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

    c.shutdown();
  }
コード例 #3
0
  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();
  }