Beispiel #1
0
  public static SinkManager startSinkMakager(Injector injector) throws Exception {
    String sinkDesc =
        "{\n"
            + "    \"default\": {\n"
            + "        \"type\": \"TestSink\",\n"
            + "        \"message\": \"default\"\n"
            + "    },\n"
            + "    \"sink1\": {\n"
            + "        \"type\": \"TestSink\",\n"
            + "        \"message\": \"sink1\"\n"
            + "    },\n"
            + "    \"sink2\": {\n"
            + "        \"type\": \"TestSink\",\n"
            + "        \"message\": \"sink2\"\n"
            + "    }\n"
            + "}";
    SinkManager sinkManager = injector.getInstance(SinkManager.class);
    ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
    sinkManager.set(getSinkMap(mapper, sinkDesc));

    return sinkManager;
  }
Beispiel #2
0
  @Test
  public void test() throws Exception {
    final Properties properties = new Properties();
    properties.setProperty(ServerConfig.MESSAGE_ROUTER_THREADS, "1");

    Injector injector =
        LifecycleInjector.builder()
            .withModules(
                new SuroPlugin() {
                  @Override
                  protected void configure() {
                    bind(ObjectMapper.class).to(DefaultObjectMapper.class);
                    this.addSinkType("TestSink", TestSink.class);
                  }
                },
                new RoutingPlugin())
            .withBootstrapModule(
                new BootstrapModule() {
                  @Override
                  public void configure(BootstrapBinder binder) {
                    binder
                        .bindConfigurationProvider()
                        .toInstance(new PropertiesConfigurationProvider(properties));
                  }
                })
            .createInjector();

    SinkManager sinkManager = startSinkMakager(injector);

    startMessageRouter(injector);

    MessageSetProcessor queue = injector.getInstance(MessageSetProcessor.class);
    queue.start();

    MessageSetBuilder builder = new MessageSetBuilder(new ClientConfig());

    for (int i = 0; i < 10; ++i) {
      builder.withMessage("topic1", Integer.toString(i).getBytes());
    }
    // sink1: 10
    // default: 10
    queue.process(builder.build());

    for (int i = 0; i < 5; ++i) {
      builder.withMessage("topic2", Integer.toString(i).getBytes());
    }
    // sink1: 5
    queue.process(builder.build());

    for (int i = 0; i < 20; ++i) {
      builder.withMessage("topic3", Integer.toString(i).getBytes());
    }
    // default: 20
    queue.process(builder.build());

    // total sink1: 15, default: 30
    int count = 10;
    while (!answer() && count > 0) {
      Thread.sleep(1000);
      --count;
    }
    assertTrue(count > 0);

    queue.shutdown();
    sinkManager.shutdown();
  }
Beispiel #3
0
 @GET
 @Produces("text/plain")
 public String get() {
   return sinkManager.reportSinkStat();
 }