use of co.cask.cdap.messaging.data.MessageId in project cdap by caskdata.
the class DataCleanupTest method testPayloadTTLCleanup.
@Test
public void testPayloadTTLCleanup() throws Exception {
try (MetadataTable metadataTable = getMetadataTable();
PayloadTable payloadTable = getPayloadTable();
MessageTable messageTable = getMessageTable()) {
Assert.assertNotNull(messageTable);
TopicId topicId = NamespaceId.DEFAULT.topic("t2");
TopicMetadata topic = new TopicMetadata(topicId, "ttl", "3", TopicMetadata.GENERATION_KEY, Integer.toString(GENERATION));
metadataTable.createTopic(topic);
List<PayloadTable.Entry> entries = new ArrayList<>();
entries.add(new TestPayloadEntry(topicId, GENERATION, "payloaddata", 101, (short) 0));
payloadTable.store(entries.iterator());
byte[] messageId = new byte[MessageId.RAW_ID_SIZE];
MessageId.putRawId(0L, (short) 0, 0L, (short) 0, messageId, 0);
CloseableIterator<PayloadTable.Entry> iterator = payloadTable.fetch(topic, 101L, new MessageId(messageId), true, Integer.MAX_VALUE);
Assert.assertTrue(iterator.hasNext());
PayloadTable.Entry entry = iterator.next();
Assert.assertFalse(iterator.hasNext());
Assert.assertEquals("payloaddata", Bytes.toString(entry.getPayload()));
Assert.assertEquals(101L, entry.getTransactionWritePointer());
iterator.close();
forceFlushAndCompact(Table.PAYLOAD);
// Entry should still be there since ttl has not expired
iterator = payloadTable.fetch(topic, 101L, new MessageId(messageId), true, Integer.MAX_VALUE);
Assert.assertTrue(iterator.hasNext());
entry = iterator.next();
Assert.assertFalse(iterator.hasNext());
Assert.assertEquals("payloaddata", Bytes.toString(entry.getPayload()));
Assert.assertEquals(101L, entry.getTransactionWritePointer());
iterator.close();
TimeUnit.SECONDS.sleep(3 * METADATA_CACHE_EXPIRY);
forceFlushAndCompact(Table.PAYLOAD);
iterator = payloadTable.fetch(topic, 101L, new MessageId(messageId), true, Integer.MAX_VALUE);
Assert.assertFalse(iterator.hasNext());
iterator.close();
metadataTable.deleteTopic(topicId);
}
}
use of co.cask.cdap.messaging.data.MessageId in project cdap by caskdata.
the class DefaultMetricStore method getMetricsProcessorStats.
/**
* Read the metrics processing stats from meta table and return the map of topic information to stats
* @return Map of topic to metrics processing stats
* @throws Exception
*/
@Override
public Map<String, MetricsProcessorStatus> getMetricsProcessorStats() throws Exception {
MetricsConsumerMetaTable metaTable = metaTableSupplier.get();
Map<String, MetricsProcessorStatus> processMap = new HashMap<>();
for (TopicId topicId : metricsTopics) {
TopicProcessMeta topicProcessMeta = metaTable.getTopicProcessMeta(new TopicIdMetaKey(topicId));
if (topicProcessMeta != null) {
MessageId messageId = new MessageId(topicProcessMeta.getMessageId());
MetricsMessageId metricsMessageId = new MetricsMessageId(messageId.getPublishTimestamp(), messageId.getSequenceId(), messageId.getPayloadWriteTimestamp(), messageId.getPayloadSequenceId());
processMap.put(topicId.getTopic(), new MetricsProcessorStatus(metricsMessageId, topicProcessMeta.getOldestMetricsTimestamp(), topicProcessMeta.getLatestMetricsTimestamp(), topicProcessMeta.getMessagesProcessed(), topicProcessMeta.getLastProcessedTimestamp()));
}
}
return processMap;
}
Aggregations