UladzislauBlok commented on code in PR #23390:
URL: https://github.com/apache/kafka/pull/23390#discussion_r3958238628
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStreamThreadTest.java:
##########
@@ -292,6 +298,73 @@ public Set<TopicPartition> partitions() {
assertFalse(new File(baseDirectoryName + File.separator + "testAppId"
+ File.separator + "global").exists());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ public void
shouldWipeGlobalStateDirectoryOnTaskCorruptedExceptionDuringStartup() throws
Exception {
+ final InternalTopologyBuilder builderWithCorruptedStore = new
InternalTopologyBuilder();
+
+ final ProcessorSupplier<Object, Object, Void, Void> processorSupplier
= () ->
+ new ContextualProcessor<>() {
+ @Override
+ public void process(final Record<Object, Object> record) {
+ }
+ };
+
+ final StateStore corruptedStore = mock(StateStore.class);
+ when(corruptedStore.name()).thenReturn(GLOBAL_STORE_NAME);
+ when(corruptedStore.persistent()).thenReturn(true);
+ when(corruptedStore.managesOffsets()).thenReturn(true);
+ doThrow(new TaskCorruptedException(Set.of(new TaskId(-1, -1))))
+ .when(corruptedStore).init(any(), any());
Review Comment:
```suggestion
doThrow(new TaskCorruptedException(Set.of(new TaskId(-1,
-1)))).when(corruptedStore).init(any(), any());
```
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStreamThreadTest.java:
##########
@@ -292,6 +298,73 @@ public Set<TopicPartition> partitions() {
assertFalse(new File(baseDirectoryName + File.separator + "testAppId"
+ File.separator + "global").exists());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ public void
shouldWipeGlobalStateDirectoryOnTaskCorruptedExceptionDuringStartup() throws
Exception {
+ final InternalTopologyBuilder builderWithCorruptedStore = new
InternalTopologyBuilder();
+
+ final ProcessorSupplier<Object, Object, Void, Void> processorSupplier
= () ->
+ new ContextualProcessor<>() {
+ @Override
+ public void process(final Record<Object, Object> record) {
+ }
+ };
+
+ final StateStore corruptedStore = mock(StateStore.class);
+ when(corruptedStore.name()).thenReturn(GLOBAL_STORE_NAME);
+ when(corruptedStore.persistent()).thenReturn(true);
+ when(corruptedStore.managesOffsets()).thenReturn(true);
+ doThrow(new TaskCorruptedException(Set.of(new TaskId(-1, -1))))
+ .when(corruptedStore).init(any(), any());
+
+ @SuppressWarnings("unchecked")
+ final StoreBuilder<StateStore> corruptedStoreBuilder =
mock(StoreBuilder.class);
+ when(corruptedStoreBuilder.name()).thenReturn(GLOBAL_STORE_NAME);
+ when(corruptedStoreBuilder.build()).thenReturn(corruptedStore);
+
+ builderWithCorruptedStore.addGlobalStore(
+ "sourceName",
+ null,
+ null,
+ null,
+ GLOBAL_STORE_TOPIC_NAME,
+ "processorName",
+ new StoreDelegatingProcessorSupplier<>(
+ processorSupplier,
+ Set.of(corruptedStoreBuilder)
+ ),
+ false
+ );
+
+ globalStreamThread = new GlobalStreamThread(
+
builderWithCorruptedStore.rewriteTopology(config).buildGlobalStateTopology(),
+ config,
+ mockConsumer,
+ new StateDirectory(config, time, true, false),
+ 0,
+ -1L,
+ new StreamsMetricsImpl(new Metrics(), "test-client", time),
+ time,
+ "clientId",
+ stateRestoreListener,
+ e -> { }
+ );
+
+ final File globalStateDir =
+ new File(baseDirectoryName + File.separator + "testAppId" +
File.separator + "global");
Review Comment:
```suggestion
final File globalStateDir = new File(baseDirectoryName +
File.separator + "testAppId" + File.separator + "global");
```
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStreamThreadTest.java:
##########
@@ -292,6 +298,73 @@ public Set<TopicPartition> partitions() {
assertFalse(new File(baseDirectoryName + File.separator + "testAppId"
+ File.separator + "global").exists());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ public void
shouldWipeGlobalStateDirectoryOnTaskCorruptedExceptionDuringStartup() throws
Exception {
+ final InternalTopologyBuilder builderWithCorruptedStore = new
InternalTopologyBuilder();
+
+ final ProcessorSupplier<Object, Object, Void, Void> processorSupplier
= () ->
+ new ContextualProcessor<>() {
+ @Override
+ public void process(final Record<Object, Object> record) {
+ }
+ };
+
+ final StateStore corruptedStore = mock(StateStore.class);
+ when(corruptedStore.name()).thenReturn(GLOBAL_STORE_NAME);
+ when(corruptedStore.persistent()).thenReturn(true);
+ when(corruptedStore.managesOffsets()).thenReturn(true);
Review Comment:
non of that is needed
can we trim everything what isn't used by test?
I was able to pass this test local with this setup:
```
final InternalTopologyBuilder builderWithCorruptedStore = new
InternalTopologyBuilder();
final ProcessorSupplier<Object, Object, Void, Void>
processorSupplier = () ->
new ContextualProcessor<>() {
@Override
public void process(final Record<Object, Object> record) {
}
};
final StateStore corruptedStore = mock(StateStore.class);
doThrow(new TaskCorruptedException(Set.of(new TaskId(-1,
-1)))).when(corruptedStore).init(any(), any());
@SuppressWarnings("unchecked")
final StoreBuilder<StateStore> corruptedStoreBuilder =
mock(StoreBuilder.class);
when(corruptedStoreBuilder.build()).thenReturn(corruptedStore);
builderWithCorruptedStore.addGlobalStore(
"sourceName",
null,
null,
null,
GLOBAL_STORE_TOPIC_NAME,
"processorName",
new StoreDelegatingProcessorSupplier<>(
processorSupplier,
Set.of(corruptedStoreBuilder)
),
false
);
globalStreamThread = new GlobalStreamThread(
builderWithCorruptedStore.rewriteTopology(config).buildGlobalStateTopology(),
config,
mockConsumer,
new StateDirectory(config, time, true, false),
0,
-1L,
new StreamsMetricsImpl(new Metrics(), "test-client", time),
time,
"clientId",
stateRestoreListener,
e -> { }
);
```
--
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]