use of co.cask.cdap.proto.StreamProperties in project cdap by caskdata.
the class StreamCoordinatorTestBase method testConfig.
@Test
public void testConfig() throws Exception {
final StreamAdmin streamAdmin = getStreamAdmin();
final String streamName = "testConfig";
final StreamId streamId = NamespaceId.DEFAULT.stream(streamName);
streamAdmin.create(streamId);
StreamCoordinatorClient coordinator = getStreamCoordinator();
final BlockingDeque<Integer> thresholds = new LinkedBlockingDeque<>();
final BlockingDeque<Long> ttls = new LinkedBlockingDeque<>();
coordinator.addListener(streamId, new StreamPropertyListener() {
@Override
public void thresholdChanged(StreamId streamId, int threshold) {
thresholds.add(threshold);
}
@Override
public void ttlChanged(StreamId streamId, long ttl) {
ttls.add(ttl);
}
});
// Have two threads, one update the threshold, one update the ttl
final CyclicBarrier barrier = new CyclicBarrier(2);
final CountDownLatch completeLatch = new CountDownLatch(2);
for (int i = 0; i < 2; i++) {
final int threadId = i;
Thread t = new Thread() {
@Override
public void run() {
try {
barrier.await();
for (int i = 0; i < 100; i++) {
Long ttl = (threadId == 0) ? (long) (i * 1000) : null;
Integer threshold = (threadId == 1) ? i : null;
streamAdmin.updateConfig(streamId, new StreamProperties(ttl, null, threshold));
}
completeLatch.countDown();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
};
t.start();
}
Assert.assertTrue(completeLatch.await(60, TimeUnit.SECONDS));
// Check the last threshold and ttl are correct. We don't check if the listener gets every update as it's
// possible that it doesn't see every updates, but only the latest value (that's what ZK watch guarantees).
Assert.assertTrue(validateLastElement(thresholds, 99));
Assert.assertTrue(validateLastElement(ttls, 99000L));
// Verify the config is right
StreamConfig config = streamAdmin.getConfig(streamId);
Assert.assertEquals(99, config.getNotificationThresholdMB());
Assert.assertEquals(99000L, config.getTTL());
}
Aggregations