Skip to content
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

Missing ability to prime queries that are used only once #134

Open
manuelkiessling opened this issue Feb 2, 2016 · 1 comment
Open

Missing ability to prime queries that are used only once #134

manuelkiessling opened this issue Feb 2, 2016 · 1 comment

Comments

@manuelkiessling
Copy link
Contributor

I would like to use scassandra to verify that my code under test re-tries its Cassandra queries 2 times if encountering read timeouts, and only gives up if 3 consecutive read timeouts occur (but works if one of the tries results in a success).

To do so, I prime scassandra with the following pattern:

1. query is "SELECT * FROM foo;" -> result in ReadTimeout
2. query is "SELECT * FROM foo;" -> result in ReadTimeout
3. query is "SELECT * FROM foo;" -> respond with rows

The problem here is that as far as I can see, priming strictly works with a "last prime for a given query wins". Thus, the priming pattern above will always respond with a success and the primed rows, ignoring prime 1. and 2. completely, because all three queries are identical.

What I would like to actually prime is the following behaviour:

1. For the first  "SELECT * FROM foo;" query -> result in ReadTimeout
2. For the second "SELECT * FROM foo;" query -> result in ReadTimeout
3. For the third  "SELECT * FROM foo;" query -> respond with rows

But it seems that this isn't possible right now. I'm now utilizing a rather hacky workaround by adding a CQL comment that denotes the (re)try number to my queries in my code under test, which allows to prime like this:

1. query is "SELECT * FROM foo; /* 1. try */" -> result in ReadTimeout
2. query is "SELECT * FROM foo; /* 2. try */" -> result in ReadTimeout
3. query is "SELECT * FROM foo; /* 3. try */" -> respond with rows

Which gives me 3 logically identical CQL queries denoted by 3 physically different query strings.

(See https://github.com/journeymonitor/analyze/blob/c639c491f4deda8a41f0bcb3f9c5622bcb88f5ea/api/app/repositories/CassandraRepository.scala#L15 and https://github.com/journeymonitor/analyze/blob/c639c491f4deda8a41f0bcb3f9c5622bcb88f5ea/api/test/IntegrationWithFailingCassandraSpec.scala#L22)

@chbatey
Copy link
Member

chbatey commented Mar 4, 2016

I think this is a good feature. What I have done in the past to test retry behaviour is to prime it to fail and expect the behaviour from my application for when it can't talk to cassandra then verify via the Activity client that the failed query was executed N times.

To add this we can add an optional field to a prime that is the # of times with a default of unlimited to preserve existing behaviour.

I won't have time to work on this anytime soon but would happily accept a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants