-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add LogMessageWaitStrategy #322
Conversation
|
||
@Test | ||
public void testWaitUntilReady_Success() { | ||
waitUntilReadyAndSucceed("while true; do sleep 1; echo -e \"" + READY_MESSAGE + "\"; done"); |
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 would avoid sleep here because it adds a static delay to the test execution, how about "print & infinite sleep" instead?
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 wanted a delay between the prints to avoid excessive printing, your version sounds better though.
container.followOutput(waitingConsumer); | ||
|
||
Predicate<OutputFrame> waitPredicate = outputFrame -> | ||
outputFrame.getUtf8String().contains(expectedLogPart); |
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'm wondering if simple contains()
is enough or not... Maybe some pattern based solution would be better?
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.
At first I wanted to expose a method forPredicate()
, but I think something like OutputFrame
shouldn't be part of the public API?
WDYT about using matches()
instead?
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'd imagine an overloaded withExpectedLogPart
method that accepts a Pattern
could be flexible enough, couldn't it?
@Override | ||
protected void waitUntilReady() { | ||
WaitingConsumer waitingConsumer = new WaitingConsumer(); | ||
container.followOutput(waitingConsumer); |
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.
@rnorth correct me if I'm wrong, but I think here will be a race because WaitingConsumer doesn't use .since(0)
and if container prints something immediately after the launch then this code will fail. WDYT?
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 think you're right. The WaitingConsumer
will start following output after the container was started and will only receive new frames.
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.
Ah yes, I think so. Just thinking, would there be any reason not to amend WaitingConsumer
to use since(0)
? I can't think of anything off the top of my head...
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.
@rnorth sounds good to me 👍 I would even expect such behavior :)
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.
Should I do the change in this PR then?
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.
So I did a change, but I'm not entirely sure if this was the code you were thinking about ;)
I also wonder if this is really necessary, since the Javadoc says
* @param since
* - UNIX timestamp (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default:
* 0 (unfiltered)
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.
Ah, good. Should be no need then.
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.
Or we keep the change, in order to document the intent more clearly. I'm fine with either way.
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.
Sure, let's keep the withSince(0)
there now that it's in - no harm, and like you say, it documents the intent.
The failing codacy check is because of an underscore inside the test method BTW, but I wanted the test class to look similar to the existing |
LGTM /cc @rnorth |
Regarding the problem with postgres #317, the |
I'd like to implement multi line matching in |
How shall we go about implementing the multi-line matching? A few options spring to mind:
Personally I think the first option is probably good enough for now, and we could make it more sophisticated if/when we find a compelling need. Or maybe there's another way? WDYT? |
@rnorth AFAIK the docker-maven-plugin keeps on continuously building one single multi line String, using a
. I think this is nice from an API user perspective, but it doesn't work that well with the current Would it be okay to switch from using On the other hand, regarding your proposed solutions, I'd agree with implementing the |
I've implemented a solution by adding a |
This looks good to me - thanks for this! |
I'll look into fixing #317 tomorrow by using |
Added a
LogMessageWaitStrategy
which checks, if a log message contains the specified String. This might help in fixing #317 when incorporating it intoPostgreSQLContainer
in the future.