New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MINOR: Improve usage of LogCaptureAppender #8508
Conversation
422aae9
to
ccab82c
Compare
@@ -30,7 +30,7 @@ | |||
import static org.apache.kafka.streams.state.ValueAndTimestamp.getValueOrNull; | |||
|
|||
class KStreamKTableJoinProcessor<K1, K2, V1, V2, R> extends AbstractProcessor<K1, V1> { | |||
private static final Logger LOG = LoggerFactory.getLogger(KStreamKTableJoinProcessor.class); | |||
private static final Logger LOG = LoggerFactory.getLogger(KStreamKTableJoin.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an actual change -- in all other processor, we use the "top level class" for the logger and not the Processor
class -- changing this for alignment.
@@ -659,7 +657,6 @@ public void shouldCountWindowed() { | |||
@Test | |||
public void shouldCountWindowedWithInternalStoreName() { | |||
final MockProcessorSupplier<Windowed<String>, Long> supplier = new MockProcessorSupplier<>(); | |||
final List<KeyValue<Windowed<String>, KeyValue<Long, Long>>> results = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed because unused.
@@ -186,15 +189,12 @@ public void shouldThrowExceptionWhenOtherJoinStoreSetsRetainDuplicatesFalse() { | |||
@Test | |||
public void shouldBuildJoinWithCustomStoresAndCorrectWindowSettings() { | |||
//Case where everything matches up | |||
final WindowBytesStoreSupplier thisStoreSupplier = buildWindowBytesStoreSupplier("in-memory-join-store", 150, 100, true); | |||
final WindowBytesStoreSupplier otherStoreSupplier = buildWindowBytesStoreSupplier("in-memory-join-store-other", 150, 100, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed because unused.
processors.get(1).checkAndClearProcessResult(new KeyValueTimestamp[0]); | ||
processors.get(2).checkAndClearProcessResult(new KeyValueTimestamp[0]); | ||
processors.get(1).checkAndClearProcessResult(); | ||
processors.get(2).checkAndClearProcessResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed because the parameter is variadic
|
||
private void verifyLogMessagesSkippedRecordsForDeserializationException(final LogCaptureAppender appender) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is only called once and thus its merged into the main test method
@@ -80,8 +81,6 @@ | |||
|
|||
abstract String getMetricsScope(); | |||
|
|||
abstract void setClassLoggerToDebug(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't capture any debug logs and thus it's getting removed
|
||
private void verifyLogMessagesForSkippedRecordsForInvalidTimestamps(final LogCaptureAppender appender) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is only called once and thus its merged into the main test method
Did you consider using try with resources? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @mjsax ! This is awesome. I'm wondering if we can formalize the pattern you've adopted by implementing AutoCloseable in LogCaptureAppender, and making the close method unregister the appender, so we can convert all those try/finally blocks to try-with-resources? Of course, we'd have to move the assertions inside the block, which we have sometimes and not other times, but it doesn't seem like a big deal either way.
@@ -801,8 +801,11 @@ public void shouldWarnAboutRocksDBConfigSetterIsNotGuaranteedToBeBackwardsCompat | |||
props.setProperty(StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG, TestRocksDbConfigSetter.class.getName()); | |||
|
|||
final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this appender could also be scoped to the class that logs the message we want to capture, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not; I tied it and it fails. The issue is, we would want to register the LogCaptureAppender only for KafkaStreams.class
but at this point in the test, the corresponding logger does not exist yet: it's only created in the constructor call, that we actually test. Does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @mjsax ! It seems like we should look into the try-with-resources thing, unless you already rejected that option for some reason. I also registered one complaint below.
But I don't want to block on either one, if you really prefer the current code.
Other than those two issues, it's a really nice cleanup. Thanks!
@@ -512,19 +512,24 @@ private Bytes serializeKey(final Windowed<String> key) { | |||
final StateSerdes<String, Long> stateSerdes = StateSerdes.withBuiltinTypes("dummy", String.class, Long.class); | |||
while (iterator.hasNext()) { | |||
final KeyValue<Bytes, byte[]> next = iterator.next(); | |||
final KeyValue<Windowed<String>, Long> deserialized; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of this particular "clean up". We're trading a tightly defined scope for de-duplicating the trivial line results.add(deserialization)
. It doesn't seem like a good trade to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel "strong" about it -- it was an IntelliJ warning/suggestion to "share common code".
I did not consider using try-with-resource. Great idea! |
8a9d0aa
to
81d042b
Compare
Updated this. Call for review. |
b594d46
to
4b65333
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @mjsax ; this is awesome!
I just had one question about renaming the test thread. Otherwise, it LGTM!
// When executing on Jenkins, the thread name is set to an unknown value, | ||
// hence, we need to set it explicitly to make our log-assertions pass | ||
Thread.currentThread().setName(threadName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this might be surprising. Won't this cause the test executor thread to be called "threadName" from now until the end of the build?
Do you think we could instead get the currentThread's name and use that in the assertions? Or otherwise make the assertions agnostic to the name of the thread?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the name is much better! Should have done this for the beginning on...
Java 8 passed. Retest this please. |
Updated this PR. Will merge after Jenkins passe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks.
Java 8: Retest this please. |
Java 8 and Java 11 passed. |
I started a "small" cleanup, and it ended up to become a "big" cleanup...
LogCaptureAppender
to the class under test (if possible)Call for review @vvcephei