philadelphia icon indicating copy to clipboard operation
philadelphia copied to clipboard

philadelphia-client: Add expect command

Open khsergvl opened this issue 5 years ago • 8 comments

khsergvl avatar Jun 17 '19 08:06 khsergvl

Thank you @khsergvl! I'll have a look. 🔍

jvirtanen avatar Jun 17 '19 15:06 jvirtanen

@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 avatar Jun 18 '19 18:06 jvirtanen

@jvirtanen N.p., if you need any help with Philadelphia release - let me know

khsergvl avatar Jun 19 '19 07:06 khsergvl

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 avatar Jul 25 '19 19:07 jvirtanen

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

khsergvl avatar Jul 27 '19 20:07 khsergvl

@jvirtanen could you have a look?

khsergvl avatar Mar 25 '20 21:03 khsergvl

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 avatar Mar 29 '20 09:03 jvirtanen

@jvirtanen will improve next days.

khsergvl avatar Mar 29 '20 20:03 khsergvl

Closing this for now.

jvirtanen avatar Oct 16 '22 08:10 jvirtanen