@Test public void testTopicExistsForNonexistentTopic() throws Exception { assertFalse(topicEnsure.topicExists(simpleTopicSpec("unknown-topic"), TIMEOUT_MS)); }
public boolean topicExists(TopicSpec spec, Integer timeOut) throws Exception { try { DescribeTopicsResult topicDescribeResult = adminClient.describeTopics( Collections.singletonList(spec.name()), new DescribeTopicsOptions().timeoutMs(timeOut) ); topicDescribeResult.all().get().get(spec.name()); } catch (ExecutionException e) { if (e.getCause() instanceof UnknownTopicOrPartitionException) { return false; } else { throw e; } } return true; }
TopicEnsure { public boolean topicExists(TopicSpec spec, Integer timeOut) throws Exception { try { DescribeTopicsResult topicDescribeResult = adminClient.describeTopics( Collections.singletonList(spec.name()), new DescribeTopicsOptions().timeoutMs(timeOut) ); topicDescribeResult.all().get().get(spec.name()); } catch (ExecutionException e) { if (e.getCause() instanceof UnknownTopicOrPartitionException) { return false; } else { throw e; } } return true; } }
TopicEnsure { public boolean topicExists(TopicSpec spec, Integer timeOut) throws Exception { try { DescribeTopicsResult topicDescribeResult = adminClient.describeTopics( Collections.singletonList(spec.name()), new DescribeTopicsOptions().timeoutMs(timeOut) ); topicDescribeResult.all().get().get(spec.name()); } catch (ExecutionException e) { if (e.getCause() instanceof UnknownTopicOrPartitionException) { return false; } else { throw e; } } return true; } TopicEnsure(Properties props); }
TopicEnsure { public boolean topicExists(TopicSpec spec, Integer timeOut) throws Exception { try { DescribeTopicsResult topicDescribeResult = adminClient.describeTopics( Collections.singletonList(spec.name()), new DescribeTopicsOptions().timeoutMs(timeOut) ); topicDescribeResult.all().get().get(spec.name()); } catch (ExecutionException e) { if (e.getCause() instanceof UnknownTopicOrPartitionException) { return false; } else { throw e; } } return true; } TopicEnsure(Properties props); boolean createTopic(TopicSpec spec, int timeOut); boolean validateTopic(TopicSpec spec, int timeOut); boolean topicExists(TopicSpec spec, Integer timeOut); }
TopicEnsure { public boolean topicExists(TopicSpec spec, Integer timeOut) throws Exception { try { DescribeTopicsResult topicDescribeResult = adminClient.describeTopics( Collections.singletonList(spec.name()), new DescribeTopicsOptions().timeoutMs(timeOut) ); topicDescribeResult.all().get().get(spec.name()); } catch (ExecutionException e) { if (e.getCause() instanceof UnknownTopicOrPartitionException) { return false; } else { throw e; } } return true; } TopicEnsure(Properties props); boolean createTopic(TopicSpec spec, int timeOut); boolean validateTopic(TopicSpec spec, int timeOut); boolean topicExists(TopicSpec spec, Integer timeOut);  }