1fanwang commented on PR #22155:
URL: https://github.com/apache/kafka/pull/22155#issuecomment-6958318663

   Before, on the base commit with this PR's two test files copied in, run from 
a checkout of this PR's head:
   
   ```text
   HEAD_SHA=$(git rev-parse HEAD)
   git worktree add --detach ../kafka-base 
8f4e08b5a3fc05eb65e97909572cfbb62a583f79
   cd ../kafka-base
   git checkout "$HEAD_SHA" -- 
streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateTaskTest.java
 
streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateManagerImplTest.java
   ./gradlew :streams:test \
     --tests 
'org.apache.kafka.streams.processor.internals.GlobalStateTaskTest.shouldPreserveHeadersWhenGlobalStateDeserializationMutatesHeaders'
 \
     --tests 
'org.apache.kafka.streams.processor.internals.GlobalStateManagerImplTest.shouldPreserveHeadersWhenDeserializationMutatesHeadersDuringReprocessing'
 \
     --tests 
'org.apache.kafka.streams.processor.internals.GlobalStateTaskTest.shouldExposeSourceRawKeyAndValueToProcessingExceptionHandler'
 \
     -x checkstyleMain -x checkstyleTest -x spotbugsMain -x spotbugsTest
   ```
   
   ```text
   GlobalStateTaskTest > 
shouldPreserveHeadersWhenGlobalStateDeserializationMutatesHeaders() FAILED
       org.opentest4j.AssertionFailedError: expected: <RecordHeaders(headers = 
[RecordHeader(key = source-only, value = [107, 101, 112, 116])], isReadOnly = 
false)> but was: <RecordHeaders(headers = [], isReadOnly = false)>
   GlobalStateTaskTest > 
shouldExposeSourceRawKeyAndValueToProcessingExceptionHandler() FAILED
       org.opentest4j.AssertionFailedError: actual array was <null>
   GlobalStateManagerImplTest > 
shouldPreserveHeadersWhenDeserializationMutatesHeadersDuringReprocessing() 
FAILED
       org.opentest4j.AssertionFailedError: expected: <RecordHeaders(headers = 
[RecordHeader(key = source-only, value = [107, 101, 112, 116])], isReadOnly = 
false)> but was: <RecordHeaders(headers = [], isReadOnly = false)>
   BUILD FAILED in 14s
   ```
   
   Before, the punctuator test against the main sources of 
579a27f2ab75d2fe5eae990636a3ce2d2e2f7820, where a new context takes the live 
headers:
   
   ```text
   git checkout 579a27f2ab75d2fe5eae990636a3ce2d2e2f7820 -- streams/src/main
   ./gradlew :streams:integration-tests:test --tests 
'org.apache.kafka.streams.integration.ProcessingExceptionHandlerIntegrationTest.shouldExposeForwardedHeadersWhenPunctuatorForwardFailsDownstream'
 -x checkstyleMain -x checkstyleTest -x spotbugsMain -x spotbugsTest
   git checkout HEAD -- streams/src/main
   ```
   
   ```text
   ProcessingExceptionHandlerIntegrationTest > 
shouldExposeForwardedHeadersWhenPunctuatorForwardFailsDownstream() FAILED
       org.opentest4j.AssertionFailedError: Unexpected exception type thrown, 
expected: <org.apache.kafka.streams.errors.StreamsException> but was: 
<org.opentest4j.AssertionFailedError>
           org.opentest4j.AssertionFailedError: expected: not <null>
   BUILD FAILED in 4s
   ```
   
   After, in a clean checkout of this PR's head, with the script below saved as 
add-handler-prints.sh in the repository root:
   
   <details>
   <summary>Reproducer source: add-handler-prints.sh</summary>
   
   ```bash
   #!/usr/bin/env bash
   set -euo pipefail
   git apply <<'PATCH'
   diff --git 
a/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/ProcessingExceptionHandlerIntegrationTest.java
 
b/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/ProcessingExceptionHandlerIntegrationTest.java
   index 335ccd1dd4..4bd4eca929 100644
   --- 
a/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/ProcessingExceptionHandlerIntegrationTest.java
   +++ 
b/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/ProcessingExceptionHandlerIntegrationTest.java
   @@ -755,6 +755,8 @@ public class ProcessingExceptionHandlerIntegrationTest {
            public Response handleError(final ErrorHandlerContext context,
                                        final Record<?, ?> record,
                                        final Exception exception) {
   +            System.out.println("Punctuator handler record headers: " + 
record.headers());
   +            System.out.println("Punctuator handler context headers: " + 
context.headers());
                assertNotNull(record.headers().lastHeader(PUNCTUATOR_HEADER));
                assertNotNull(context.headers().lastHeader(PUNCTUATOR_HEADER));
                assertArrayEquals(PUNCTUATOR_HEADER_VALUE, 
context.headers().lastHeader(PUNCTUATOR_HEADER).value());
   diff --git 
a/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateManagerImplTest.java
 
b/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateManagerImplTest.java
   index be870aa731..3ae4f81351 100644
   --- 
a/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateManagerImplTest.java
   +++ 
b/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateManagerImplTest.java
   @@ -1297,6 +1297,7 @@ public class GlobalStateManagerImplTest {
            stateManager.initialize();
    
            assertTrue(deserializerInvoked.get());
   +        System.out.println("GlobalStateManager reprocessing handler 
headers: " + capturedHeaders.get());
            assertEquals(sourceHeaders, capturedHeaders.get());
        }
    
   diff --git 
a/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateTaskTest.java
 
b/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateTaskTest.java
   index 40be008481..e7051fd8da 100644
   --- 
a/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateTaskTest.java
   +++ 
b/streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStateTaskTest.java
   @@ -317,6 +317,7 @@ public class GlobalStateTaskTest {
                Optional.empty()
            ));
    
   +        System.out.println("GlobalStateTask handler headers: " + 
capturedHeaders.get());
            assertEquals(sourceHeaders, capturedHeaders.get());
        }
    
   @@ -562,6 +563,8 @@ public class GlobalStateTaskTest {
            );
            globalStateTask.initialize();
            globalStateTask.update(record(topic1, 1, 1, "foo".getBytes(), 
"bar".getBytes()));
   +        System.out.println("Global handler sourceRawKey: " + 
(capturedContext.get().sourceRawKey() == null ? "null" : new 
String(capturedContext.get().sourceRawKey())));
   +        System.out.println("Global handler sourceRawValue: " + 
(capturedContext.get().sourceRawValue() == null ? "null" : new 
String(capturedContext.get().sourceRawValue())));
    
            assertArrayEquals("foo".getBytes(), 
capturedContext.get().sourceRawKey());
            assertArrayEquals("bar".getBytes(), 
capturedContext.get().sourceRawValue());
   PATCH
   ```
   
   </details>
   
   ```text
   bash add-handler-prints.sh
   ./gradlew --rerun-tasks \
     :streams:test \
       --tests 
'org.apache.kafka.streams.processor.internals.GlobalStateTaskTest.shouldPreserveHeadersWhenGlobalStateDeserializationMutatesHeaders'
 \
       --tests 
'org.apache.kafka.streams.processor.internals.GlobalStateManagerImplTest.shouldPreserveHeadersWhenDeserializationMutatesHeadersDuringReprocessing'
 \
       --tests 
'org.apache.kafka.streams.processor.internals.GlobalStateTaskTest.shouldExposeSourceRawKeyAndValueToProcessingExceptionHandler'
 \
     :streams:integration-tests:test \
       --tests 
'org.apache.kafka.streams.integration.ProcessingExceptionHandlerIntegrationTest.shouldExposeForwardedHeadersWhenPunctuatorForwardFailsDownstream'
 \
     -x checkstyleMain -x checkstyleTest -x spotbugsMain -x spotbugsTest --info
   ```
   
   Printed values and build result:
   
   ```text
   Punctuator handler record headers: RecordHeaders(headers = [RecordHeader(key 
= punctuator-header, value = [102, 111, 114, 119, 97, 114, 100, 101, 100])], 
isReadOnly = false)
   Punctuator handler context headers: RecordHeaders(headers = 
[RecordHeader(key = punctuator-header, value = [102, 111, 114, 119, 97, 114, 
100, 101, 100])], isReadOnly = false)
   GlobalStateTask handler headers: RecordHeaders(headers = [RecordHeader(key = 
source-only, value = [107, 101, 112, 116])], isReadOnly = false)
   Global handler sourceRawKey: foo
   Global handler sourceRawValue: bar
   GlobalStateManager reprocessing handler headers: RecordHeaders(headers = 
[RecordHeader(key = source-only, value = [107, 101, 112, 116])], isReadOnly = 
false)
   BUILD SUCCESSFUL in 14s
   ```
   


-- 
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