### Question:
LevelDBMetadataTable implements MetadataTable { public CloseableIterator<TopicMetadata> scanTopics() throws IOException { return scanTopics(null, null); } LevelDBMetadataTable(DB levelDB); @Override TopicMetadata getMetadata(TopicId topicId); @Override void createTopic(TopicMetadata topicMetadata); @Override void updateTopic(TopicMetadata topicMetadata); @Override void deleteTopic(TopicId topicId); @Override List<TopicId> listTopics(NamespaceId namespaceId); @Override List<TopicId> listTopics(); CloseableIterator<TopicMetadata> scanTopics(); @Override void close();  }### Answer:
@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()); } }