Copilot commented on code in PR #24310:
URL: https://github.com/apache/kafka/pull/24310#discussion_r4672320200


##########
streams/test-utils/src/test/java/org/apache/kafka/streams/TopologyTestDriverTest.java:
##########
@@ -452,6 +459,147 @@ public void shouldCloseProcessor() {
         testDriver = null;
     }
 
+    @Test
+    public void shouldCloseStateStoreWhenProcessorFailsToInitialize() {
+        final Topology topology = new Topology();
+        topology.addSource("source", SOURCE_TOPIC_1);
+        topology.addProcessor("processor", failingProcessorSupplier("store"), 
"source");
+        topology.addStateStore(
+            
Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore("store"), 
Serdes.String(), Serdes.Long()),
+            "processor");
+
+        assertThrows(StreamsException.class, () -> new 
TopologyTestDriverBuilder(topology).withConfig(config).build());
+
+        assertFalse(store.isOpen());
+        assertFalse(stateDirectory().exists());
+    }
+
+    @Test
+    public void 
shouldCloseGlobalStateStoreWhenProcessorFailsToInitializeOnRestore() {
+        final Topology topology = new Topology();
+        topology.addGlobalStore(
+            
Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore("globalStore"), 
Serdes.String(), Serdes.Long())
+                .withLoggingDisabled(),
+            "source",
+            new StringDeserializer(),
+            new LongDeserializer(),
+            SOURCE_TOPIC_1,
+            "processor",
+            failingProcessorSupplier("globalStore"));
+
+        assertThrows(IllegalStateException.class, () -> new 
TopologyTestDriverBuilder(topology).withConfig(config).build());
+
+        assertFalse(store.isOpen());
+        assertFalse(stateDirectory().exists());
+    }
+
+    @Test
+    public void shouldWipeStateDirectoryWhenFirstStateStoreIsCorrupted() {
+        final Topology topology = new Topology();
+        topology.addSource("source", SOURCE_TOPIC_1);
+        topology.addProcessor("corruptedProcessor", new 
MockProcessorSupplier(), "source");
+        topology.addStateStore(
+            Stores.keyValueStoreBuilder(
+                // fails as a RocksDB store that is found corrupted when it is 
opened, before any store is registered
+                storeSupplier(() -> new 
InMemoryKeyValueStore("corruptedStore") {
+                    @Override
+                    public void init(final StateStoreContext 
stateStoreContext, final StateStore root) {
+                        throw new 
TaskCorruptedException(Set.of(stateStoreContext.taskId()));
+                    }
+                }),
+                Serdes.String(),
+                Serdes.Long()),
+            "corruptedProcessor");
+        topology.addProcessor("persistentProcessor", new 
MockProcessorSupplier(), "source");
+        topology.addStateStore(
+            
Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore("persistentStore"), 
Serdes.String(), Serdes.Long()),
+            "persistentProcessor");
+
+        assertThrows(TaskCorruptedException.class, () -> new 
TopologyTestDriverBuilder(topology).withConfig(config).build());

Review Comment:
   This test leaves `TRANSACTIONAL_STATE_STORES_CONFIG` at its default of 
`false`; the subclasses only change the processing guarantee. It therefore does 
not cover the transactional-store corruption case described in the PR, where 
dirty close has different state-retention behavior. Enable transactional state 
stores here so the directory-deletion assertion also protects that case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to