From 1aa26bd9eae7460d0d569b231aa8829d97c56dd4 Mon Sep 17 00:00:00 2001 From: Sverre H Huseby Date: Fri, 17 Dec 2021 12:25:01 +0100 Subject: [PATCH 1/3] Throw exception for invalid plan name --- .../kafka/topology/serdes/TopicCustomDeserializer.java | 5 +++-- .../kafka/topology/TopologyObjectBuilderTest.java | 7 +++++++ src/test/resources/descriptor-with-invalid-plan.yaml | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/descriptor-with-invalid-plan.yaml diff --git a/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java b/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java index 3ff216ee0..9270a895e 100644 --- a/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java +++ b/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; import com.purbon.kafka.topology.Configuration; +import com.purbon.kafka.topology.exceptions.TopologyParsingException; import com.purbon.kafka.topology.exceptions.ValidationException; import com.purbon.kafka.topology.model.PlanMap; import com.purbon.kafka.topology.model.SubjectNameStrategy; @@ -85,10 +86,10 @@ public Topic deserialize(JsonParser parser, DeserializationContext context) thro Map planConfigObject = plans.get(planLabel).getConfig(); planConfigObject.forEach(config::putIfAbsent); } else { - LOGGER.warn(planLabel + " is missing in the plans definition. It will be ignored."); + throw new TopologyParsingException( + "Reference to non-existing plan \"" + planLabel + "\""); } }); - Topic topic = new Topic(name, producers, consumers, optionalDataType, config, this.config); Optional subjectNameStrategy = diff --git a/src/test/java/com/purbon/kafka/topology/TopologyObjectBuilderTest.java b/src/test/java/com/purbon/kafka/topology/TopologyObjectBuilderTest.java index f6b48662d..01ee8fa3a 100644 --- a/src/test/java/com/purbon/kafka/topology/TopologyObjectBuilderTest.java +++ b/src/test/java/com/purbon/kafka/topology/TopologyObjectBuilderTest.java @@ -146,6 +146,13 @@ public void testTopologyWithPlansButWithNoPlansDef() throws IOException { TopologyObjectBuilder.build(descriptorFile); } + @Test(expected = TopologyParsingException.class) + public void testTopologyWithInvalidPlan() throws IOException { + String descriptorFile = TestUtils.getResourceFilename("/descriptor-with-invalid-plan.yaml"); + String plansFile = TestUtils.getResourceFilename("/plans.yaml"); + TopologyObjectBuilder.build(descriptorFile, plansFile); + } + @Test(expected = TopologyParsingException.class) public void testInvalidTopology() throws IOException { String descriptorFile = diff --git a/src/test/resources/descriptor-with-invalid-plan.yaml b/src/test/resources/descriptor-with-invalid-plan.yaml new file mode 100644 index 000000000..a2b90839a --- /dev/null +++ b/src/test/resources/descriptor-with-invalid-plan.yaml @@ -0,0 +1,10 @@ +--- +context: "contextOrg" +source: "source" +projects: + - name: "foo" + topics: + - name: "fooBar" + plan: "gold" + - name: "barFoo" + plan: "invalid-plan-name" From 9ed4e2362fe7be3c1e8d8109bae0b44996e8683e Mon Sep 17 00:00:00 2001 From: "Sverre H. Huseby" Date: Fri, 17 Dec 2021 12:36:29 +0100 Subject: [PATCH 2/3] Update src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java Co-authored-by: Aksel Hilde <42339256+akselh@users.noreply.github.com> --- .../purbon/kafka/topology/serdes/TopicCustomDeserializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java b/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java index 9270a895e..b1e79f9ec 100644 --- a/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java +++ b/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java @@ -87,7 +87,7 @@ public Topic deserialize(JsonParser parser, DeserializationContext context) thro planConfigObject.forEach(config::putIfAbsent); } else { throw new TopologyParsingException( - "Reference to non-existing plan \"" + planLabel + "\""); + "Topic \"" + name "\" references non-existing plan \"" + planLabel + "\""); } }); Topic topic = new Topic(name, producers, consumers, optionalDataType, config, this.config); From 4e48abe2dc5c78db427896d2cf4f81f479510428 Mon Sep 17 00:00:00 2001 From: Aksel Hilde <42339256+akselh@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:42:02 +0100 Subject: [PATCH 3/3] Fix failed build --- .../purbon/kafka/topology/serdes/TopicCustomDeserializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java b/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java index b1e79f9ec..34a1a20e9 100644 --- a/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java +++ b/src/main/java/com/purbon/kafka/topology/serdes/TopicCustomDeserializer.java @@ -87,7 +87,7 @@ public Topic deserialize(JsonParser parser, DeserializationContext context) thro planConfigObject.forEach(config::putIfAbsent); } else { throw new TopologyParsingException( - "Topic \"" + name "\" references non-existing plan \"" + planLabel + "\""); + "Topic \"" + name + "\" references non-existing plan \"" + planLabel + "\""); } }); Topic topic = new Topic(name, producers, consumers, optionalDataType, config, this.config);