use of co.cask.cdap.api.messaging.TopicAlreadyExistsException in project cdap by caskdata.
the class MetadataTableTest method testCRUD.
@Test
public void testCRUD() throws Exception {
try (MetadataTable table = createMetadataTable()) {
TopicId topicId = NamespaceId.DEFAULT.topic("topic");
// Update a non-existing topic should fail.
try {
table.updateTopic(new TopicMetadata(topicId, "ttl", 10));
Assert.fail("Expected TopicNotFoundException");
} catch (TopicNotFoundException e) {
// Expected
}
// Create a topic and validate
table.createTopic(new TopicMetadata(topicId, "ttl", 10));
Assert.assertEquals(10, table.getMetadata(topicId).getTTL());
// Update the property and validate
table.updateTopic(new TopicMetadata(topicId, "ttl", 30));
Assert.assertEquals(30, table.getMetadata(topicId).getTTL());
// Create the same topic again should fail
try {
table.createTopic(new TopicMetadata(topicId, "ttl", 10));
Assert.fail("Expected TopicAlreadyExistsException");
} catch (TopicAlreadyExistsException e) {
// Expected
}
// It shouldn't affect the topic at all if creation failed
Assert.assertEquals(30, table.getMetadata(topicId).getTTL());
// Delete the topic
table.deleteTopic(topicId);
try {
table.getMetadata(topicId);
Assert.fail("Expected TopicNotFoundException");
} catch (TopicNotFoundException e) {
// Expected
}
// Delete again should raise a TopicNotFoundException
try {
table.deleteTopic(topicId);
Assert.fail("Expected TopicNotFoundException");
} catch (TopicNotFoundException e) {
// Expected
}
}
}
Aggregations