-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
[FLINK-5101] Refactor CassandraConnectorITCase #2866
Conversation
try { | ||
updatesPending.wait(); | ||
} catch (InterruptedException e) { | ||
} |
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.
Good practice is to set the interruption flag back: Thread.currentThread().interrupt();
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.
Probably better here even: Throw an exception, because closing is incomplete when interrupted (and cannot guarantee correctness)
@@ -94,5 +122,9 @@ public void close() { | |||
} catch (Exception e) { | |||
LOG.error("Error while closing cluster.", e); | |||
} | |||
Throwable e = exception.get(); | |||
if (e != null) { | |||
LOG.error("Error while sending value.", e); |
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 needs to be rethrown, otherwise close() may complete without an exception, but the result may be incomplete.
try { | ||
Thread.sleep(1000 * 10); | ||
} catch (InterruptedException e) { //give cassandra a few seconds to start up | ||
// give cassandra a few seconds to start up |
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.
Can we skip this and simply rely on the loop below that tries to connect?
throw e; | ||
} | ||
try { | ||
Thread.sleep(2000); |
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.
How about reducing this to, say 500ms, to make it react a bit sooner once the connection can be established.
cluster = builder.getCluster(); | ||
session = cluster.connect(); | ||
// start establishing a connection within 30 seconds | ||
start = System.currentTimeMillis(); |
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 suggest to use System.nanoTime()
, because System.curremtTimeMillis
is not stable. Seems especially unstable on Travis.
|
||
ResultSet rs = session.execute(SELECT_DATA_QUERY); | ||
synchronized (sink.updatesPending) { |
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.
Is this needed when close()
already waits for pending requests?
|
||
sink.close(); | ||
|
||
synchronized (sink.updatesPending) { |
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.
Same as above
Good set of changes. Some comments for small adjustments, otherwise +1 for the approch |
4c74937
to
350a75c
Compare
@StephanEwen I've addressed your comments and Travis is passing :) |
} catch (InterruptedException e) { //give cassandra a few seconds to start up | ||
// start establishing a connection within 30 seconds | ||
long start = System.nanoTime(); | ||
long deadline = start + 1000 * 30; |
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 needs to be long deadline = start + 30_000_000_000
(because its nanos)
session = cluster.connect(); | ||
break; | ||
} catch (Exception e) { | ||
if (System.currentTimeMillis() > deadline) { |
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 should also be System.nanoTime()
@@ -40,26 +42,42 @@ | |||
protected transient Cluster cluster; | |||
protected transient Session session; | |||
|
|||
protected transient Throwable exception = null; | |||
protected transient AtomicReference<Throwable> exception; |
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.
Does exception
have to be an AtomicReference
, or does a volatile variable suffice?
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.
it can be volatile.
Looks much better, one mixup is still in the tests. |
364f96e
to
9a75b6e
Compare
@StephanEwen I've addressed your comments and rebased the branch. |
Will start merging this; it's blocking #3810. |
This PR refactors the CassandraConnectorITCase to be a bit more stable and easier to debug.
The following changes were made:
=> the pojo sink was modified to use a method that returns an actually useful
Future
=> since the sink waits in
close()
for pending updates it can no longer occur that a test checks a condition prematurely, improving stability