@Test public void testErrorInReplicas() { KafkaTopic kafkaTopic = new KafkaTopicBuilder() .withMetadata(new ObjectMetaBuilder().withName("my-topic").build()) .withNewSpec() .withReplicas(-1) .withPartitions(1) .withConfig(emptyMap()) .endSpec() .build(); try { TopicSerialization.fromTopicResource(kafkaTopic); fail("Should throw"); } catch (InvalidTopicException e) { assertThat(e.getMessage(), is("KafkaTopic's spec.replicas should be between 1 and 32767 inclusive")); } }
public static Topic fromTopicResource(KafkaTopic kafkaTopic) { if (kafkaTopic == null) { return null; } Topic.Builder builder = new Topic.Builder() .withMapName(kafkaTopic.getMetadata().getName()) .withTopicName(getTopicName(kafkaTopic)) .withNumPartitions(getPartitions(kafkaTopic)) .withNumReplicas(getReplicas(kafkaTopic)) .withConfig(topicConfigFromTopicConfig(kafkaTopic)) .withMetadata(kafkaTopic.getMetadata()); return builder.build(); }
TopicSerialization { public static Topic fromTopicResource(KafkaTopic kafkaTopic) { if (kafkaTopic == null) { return null; } Topic.Builder builder = new Topic.Builder() .withMapName(kafkaTopic.getMetadata().getName()) .withTopicName(getTopicName(kafkaTopic)) .withNumPartitions(getPartitions(kafkaTopic)) .withNumReplicas(getReplicas(kafkaTopic)) .withConfig(topicConfigFromTopicConfig(kafkaTopic)) .withMetadata(kafkaTopic.getMetadata()); return builder.build(); } }
TopicSerialization { public static Topic fromTopicResource(KafkaTopic kafkaTopic) { if (kafkaTopic == null) { return null; } Topic.Builder builder = new Topic.Builder() .withMapName(kafkaTopic.getMetadata().getName()) .withTopicName(getTopicName(kafkaTopic)) .withNumPartitions(getPartitions(kafkaTopic)) .withNumReplicas(getReplicas(kafkaTopic)) .withConfig(topicConfigFromTopicConfig(kafkaTopic)) .withMetadata(kafkaTopic.getMetadata()); return builder.build(); }  }
TopicSerialization { public static Topic fromTopicResource(KafkaTopic kafkaTopic) { if (kafkaTopic == null) { return null; } Topic.Builder builder = new Topic.Builder() .withMapName(kafkaTopic.getMetadata().getName()) .withTopicName(getTopicName(kafkaTopic)) .withNumPartitions(getPartitions(kafkaTopic)) .withNumReplicas(getReplicas(kafkaTopic)) .withConfig(topicConfigFromTopicConfig(kafkaTopic)) .withMetadata(kafkaTopic.getMetadata()); return builder.build(); }  static Topic fromTopicResource(KafkaTopic kafkaTopic); static KafkaTopic toTopicResource(Topic topic, Labels labels); static NewTopic toNewTopic(Topic topic, Map<Integer, List<Integer>> assignment); static Map<ConfigResource, Config> toTopicConfig(Topic topic); static Topic fromTopicMetadata(TopicMetadata meta); static byte[] toJson(Topic topic); @SuppressWarnings("unchecked") static Topic fromJson(byte[] json); }
TopicSerialization { public static Topic fromTopicResource(KafkaTopic kafkaTopic) { if (kafkaTopic == null) { return null; } Topic.Builder builder = new Topic.Builder() .withMapName(kafkaTopic.getMetadata().getName()) .withTopicName(getTopicName(kafkaTopic)) .withNumPartitions(getPartitions(kafkaTopic)) .withNumReplicas(getReplicas(kafkaTopic)) .withConfig(topicConfigFromTopicConfig(kafkaTopic)) .withMetadata(kafkaTopic.getMetadata()); return builder.build(); }  static Topic fromTopicResource(KafkaTopic kafkaTopic); static KafkaTopic toTopicResource(Topic topic, Labels labels); static NewTopic toNewTopic(Topic topic, Map<Integer, List<Integer>> assignment); static Map<ConfigResource, Config> toTopicConfig(Topic topic); static Topic fromTopicMetadata(TopicMetadata meta); static byte[] toJson(Topic topic); @SuppressWarnings("unchecked") static Topic fromJson(byte[] json); static final String JSON_KEY_TOPIC_NAME; static final String JSON_KEY_MAP_NAME; static final String JSON_KEY_PARTITIONS; static final String JSON_KEY_REPLICAS; static final String JSON_KEY_CONFIG; }