philadelphia
philadelphia copied to clipboard
philadelphia-client: Add expect command
Thank you @khsergvl! I'll have a look. 🔍
@khsergvl I'm currently preparing for a Philadelphia 1.1.0 release to take place later this week. I'll get back to this and other open pull requests after that. 🙂
@jvirtanen N.p., if you need any help with Philadelphia release - let me know
Hi @khsergvl, just an update to remind you that I haven't forgotten this. As a matter of fact, I'm just trying to remind myself how the expect
utility works. 🙂
@jvirtanen Lol, it was take me some time to remind too. So basical logic is to await specified mesassage with ability, to check that the tag is correct but the value is not checked.
Expect also ignores some messages & tags, like you proposed.
So for now it's works like, on expect:
35=8|37|11=3|41=2|17|150=4|39=4|55=AAPL|54=1|38=0|151=0|14=0|6=0.00|6=0.00
on recieve of something like:
35=8|37=...|11=3|41=2|17=...|150=4|39=4|55=AAPL|38=50|151=0|14=0|6=0.00
it will be printed.
Let me know, if you have any ideas.
@jvirtanen could you have a look?
Hi @khsergvl! What do you think if instead of repurposing Message
and Field
to be used for matching as well, we would have something like this?
-
class MessageMatcher
-
boolean MessageMatcher#match(Message)
-
interface FieldMatcher
-
boolean FieldMatcher#match(Field)
-
class TagMatcher implements FieldMatcher
-
class ValueMatcher implements FieldMatcher
Then the actual logic would be outside the ExpectCommand
class and could be tested the same way Message
and Field
are currently tested.
I would also simplify ExpectCommand
so that instead of tracking and updating offset
it would just record fromIndex
at the beginning similarly to WaitCommand
and on each wake-up simply match against all messages since fromIndex
. For example:
while (true) {
try {
Thread.sleep(WAIT_TIME_MILLIS);
for (Message message : getMessages(client.getMessages(), fromIndex)) {
if (matcher.matches(message))
break;
}
} catch (InterruptedException e) {
break;
}
}
...
private static List<Message> getMessages(Messages messages, int fromIndex) {
List<Message> collection = messages.collect();
return collection.subList(fromIndex, collection.size());
}
@jvirtanen will improve next days.
Closing this for now.