use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.
the class LevelDBMetadataTableTest method testScanTopics.
@Test
public void testScanTopics() throws Exception {
try (MetadataTable metadataTable = createMetadataTable()) {
LevelDBMetadataTable table = (LevelDBMetadataTable) metadataTable;
TopicMetadata t1 = new TopicMetadata(NamespaceId.CDAP.topic("t1"), ImmutableMap.of(TopicMetadata.TTL_KEY, "10", TopicMetadata.GENERATION_KEY, "1"));
TopicMetadata t2 = new TopicMetadata(NamespaceId.SYSTEM.topic("t2"), ImmutableMap.of(TopicMetadata.TTL_KEY, "20", TopicMetadata.GENERATION_KEY, "1"));
metadataTable.createTopic(t1);
metadataTable.createTopic(t2);
List<TopicId> allTopics = table.listTopics();
Assert.assertEquals(2, allTopics.size());
List<TopicMetadata> metadatas = new ArrayList<>();
Iterators.addAll(metadatas, table.scanTopics());
Assert.assertEquals(2, metadatas.size());
allTopics = table.listTopics(NamespaceId.CDAP);
Assert.assertEquals(1, allTopics.size());
allTopics = table.listTopics(NamespaceId.SYSTEM);
Assert.assertEquals(1, allTopics.size());
metadataTable.deleteTopic(t1.getTopicId());
metadatas.clear();
Iterators.addAll(metadatas, table.scanTopics());
Assert.assertEquals(2, metadatas.size());
Assert.assertEquals(1, metadataTable.listTopics().size());
Assert.assertEquals(1, metadataTable.listTopics(NamespaceId.SYSTEM).size());
Assert.assertTrue(metadataTable.listTopics(NamespaceId.CDAP).isEmpty());
metadataTable.deleteTopic(t2.getTopicId());
metadatas.clear();
Iterators.addAll(metadatas, table.scanTopics());
for (TopicMetadata metadata : metadatas) {
Assert.assertEquals(-1, metadata.getGeneration());
}
Assert.assertTrue(metadataTable.listTopics().isEmpty());
}
}
use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.
the class CoreMessagingService method deleteTopic.
@Override
public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException {
try (MetadataTable metadataTable = createMetadataTable()) {
metadataTable.deleteTopic(topicId);
topicCache.invalidate(topicId);
messageTableWriterCache.invalidate(topicId);
payloadTableWriterCache.invalidate(topicId);
}
}
use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.
the class CoreMessagingService method createTopic.
@Override
public void createTopic(TopicMetadata topicMetadata) throws TopicAlreadyExistsException, IOException {
try (MetadataTable metadataTable = createMetadataTable()) {
Map<String, String> properties = createDefaultProperties();
properties.putAll(topicMetadata.getProperties());
metadataTable.createTopic(new TopicMetadata(topicMetadata.getTopicId(), properties, true));
}
}
use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.
the class HBaseTableCoprocessorTestRun method testInvalidTx.
@Test
public void testInvalidTx() throws Exception {
try (MetadataTable metadataTable = getMetadataTable();
MessageTable messageTable = getMessageTable()) {
TopicId topicId = NamespaceId.DEFAULT.topic("invalidTx");
TopicMetadata topic = new TopicMetadata(topicId, TopicMetadata.TTL_KEY, "1000000", TopicMetadata.GENERATION_KEY, Integer.toString(GENERATION));
metadataTable.createTopic(topic);
List<MessageTable.Entry> entries = new ArrayList<>();
long invalidTxWritePtr = invalidList.toRawList().get(0);
entries.add(new TestMessageEntry(topicId, GENERATION, "data", invalidTxWritePtr, (short) 0));
messageTable.store(entries.iterator());
// Fetch the entries and make sure we are able to read it
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
checkEntry(iterator, invalidTxWritePtr);
}
// Fetch the entries with tx and make sure we are able to read it
Transaction tx = new Transaction(V[8], V[8], new long[0], new long[0], -1);
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, tx)) {
checkEntry(iterator, invalidTxWritePtr);
}
// Now run full compaction
forceFlushAndCompact(Table.MESSAGE);
// Try to fetch the entry non-transactionally and the entry should still be there
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
checkEntry(iterator, invalidTxWritePtr);
}
// Fetch the entries transactionally and we should see no entries returned
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, tx)) {
Assert.assertFalse(iterator.hasNext());
}
metadataTable.deleteTopic(topicId);
// Sleep so that the metadata cache expires
TimeUnit.SECONDS.sleep(3 * METADATA_CACHE_EXPIRY);
forceFlushAndCompact(Table.MESSAGE);
// Test deletion of messages from a deleted topic
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
Assert.assertFalse(iterator.hasNext());
}
}
}
use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.
the class CoreMessagingService method updateTopic.
@Override
public void updateTopic(TopicMetadata topicMetadata) throws TopicNotFoundException, IOException {
try (MetadataTable metadataTable = createMetadataTable()) {
Map<String, String> properties = createDefaultProperties();
properties.putAll(topicMetadata.getProperties());
metadataTable.updateTopic(new TopicMetadata(topicMetadata.getTopicId(), properties, true));
topicCache.invalidate(topicMetadata.getTopicId());
}
}
Aggregations