bind(ObjectMapper.class).to(DefaultObjectMapper.class);
}
}
).build().createInjector();
LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class);
lifecycleManager.start();
String desc = "{\n" +
" \"default\": {\n" +
" \"type\": \"TestSink\",\n" +
" \"message\": \"defaultTestSink\"\n" +
" },\n" +
" \"topic1\": {\n" +
" \"type\": \"TestSink\",\n" +
" \"message\": \"topic1TestSink\"\n" +
" }\n" +
"}";
SinkManager sinkManager = injector.getInstance(SinkManager.class);
ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
sinkManager.set(getSinkMap(mapper, desc));
assertEquals(sinkManager.getSink("topic1").getStat(), "topic1TestSink open");
assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
assertEquals(sinkManager.getSink("topic7").getStat(), "defaultTestSink open");
assertTrue(
sinkManager.reportSinkStat().equals("default:defaultTestSink open\n\ntopic1:topic1TestSink open\n\n") ||
sinkManager.reportSinkStat().equals("topic1:topic1TestSink open\n\ndefault:defaultTestSink open\n\n"));
assertEquals(TestSink.getNumOfSinks(), 2);
// change desc - test removal
desc = "{\n" +
" \"default\": {\n" +
" \"type\": \"TestSink\",\n" +
" \"message\": \"defaultTestSink\"\n" +
" }\n" +
"}";
sinkManager.set(getSinkMap(mapper, desc));
assertEquals(sinkManager.getSink("topic1").getStat(), "defaultTestSink open");
assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
assertEquals(sinkManager.reportSinkStat(),
String.format("default:defaultTestSink open\n\n"));
assertEquals(TestSink.getNumOfSinks(), 1);
// change desc - test addition
desc = "{\n" +
" \"default\": {\n" +
" \"type\": \"TestSink\",\n" +
" \"message\": \"defaultTestSink\"\n" +
" },\n" +
" \"topic2\": {\n" +
" \"type\": \"TestSink\",\n" +
" \"message\": \"topic2TestSink\"\n" +
" }\n" +
"}";
sinkManager.set(getSinkMap(mapper, desc));
assertEquals(sinkManager.getSink("topic1").getStat(), "defaultTestSink open");
assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
assertEquals(sinkManager.getSink("topic2").getStat(), "topic2TestSink open");
assertTrue(
sinkManager.reportSinkStat().equals("default:defaultTestSink open\n\ntopic2:topic2TestSink open\n\n") ||
sinkManager.reportSinkStat().equals("topic2:topic2TestSink open\n\ndefault:defaultTestSink open\n\n")
);
assertEquals(TestSink.getNumOfSinks(), 2);
// test exception - nothing changed
desc = "{\n" +
" \"default\": {\n" +
" \"type\": \"TestSink\",\n" +
" \"message\": \"defaultTestSink\"\n" +
" },\n" +
" \"topic2\": {\n" +
" \"type\": \"TestSink\",\n" +
" \"message\": \"topic2TestSink\"\n" +
" }\n" +
"},";
sinkManager.set(getSinkMap(mapper, desc));
assertEquals(sinkManager.getSink("topic1").getStat(), "defaultTestSink open");
assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
assertEquals(sinkManager.getSink("topic2").getStat(), "topic2TestSink open");
assertTrue(
sinkManager.reportSinkStat().equals("default:defaultTestSink open\n\ntopic2:topic2TestSink open\n\n") ||
sinkManager.reportSinkStat().equals("topic2:topic2TestSink open\n\ndefault:defaultTestSink open\n\n")
);
assertEquals(TestSink.getNumOfSinks(), 2);
// test destroy
lifecycleManager.close();
assertEquals(TestSink.getNumOfSinks(), 0);
assertNull(sinkManager.getSink("any"));
}