-
Notifications
You must be signed in to change notification settings - Fork 15
[Conjure Java Runtime] Part 17: 🚨🚚🚨 Optionals for Paxos Learners #4361
Conversation
Generate changelog in
|
assertThat(learner.getGreatestLearnedValue().getData()).isEqualTo(PAXOS_DATA); | ||
|
||
assertThat(learner.getGreatestLearnedValue()) | ||
.isPresent() |
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.
Call to isPresent
can be removed, hasValueSatisfying
will also assert that the value is present.
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.
you're right! Will change this
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 go further:
Optional<PaxosValue> value = learner.getGreatestLearnedValue();
assertThat(value).map(PaxosValue::getLeaderUUID).contains(PAXOS_UUID);
assertThat(value).map(PaxosValue::getData).contains(PAXOS_DATA);
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.
note, map
is a method on the OptionalAssert
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.
(yep, changed to OptionalAssert
's map)
if (!state.isEmpty()) { | ||
return state.get(state.lastKey()); | ||
return Optional.ofNullable(state.get(state.lastKey())); |
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.
If I understood correctly that empty result is a "non-standard" path I would invert the if.
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.
unrelated to above: this shouldn't be null
right? since the map is not empty, unless you're thinking it has null values, but non-null keys
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.
Agree on inverting if (didn't as I just translated what was there, but yeah it does make sense).
I wrote Optional.of()
first, but there were some tests that failed. Possibly a bad test, I didn't investigate in detail
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.
Sadness is sad
@@ -84,7 +84,7 @@ public void learn(long seq, PaxosValue value) { | |||
Function<Optional<PaxosValue>, T> mapper) { | |||
return PaxosQuorumChecker.collectQuorumResponses( | |||
allLearners, | |||
learner -> mapper.apply(Optional.ofNullable(learner.getLearnedValue(seq))), | |||
learner -> mapper.apply(learner.getLearnedValue(seq)), |
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.
💃
@PathParam("useCase") PaxosUseCase paxosUseCase, | ||
@PathParam("client") String client, | ||
@PathParam("seq") long seq); | ||
|
||
@Nullable | ||
@Nonnull |
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.
Don't think we need the @Nonnull
annotations, since that should be implied with code wide Nonnull
by default and also the fact that it's a huge code smell to pass around a null
Optional
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 was done for consistency with the other methods in the client. I guess now all of them are nonnull it's probably fine to remove them.
dbd7fc0
to
330b47c
Compare
Thanks! |
Goals (and why):
Implementation Description (bullets):
PaxosLearner
to returnOptional<PaxosValue>
and fix attendant breaks.TimelockPaxosLearnerRpcClient
to use this.Testing (What was existing testing like? What have you done to improve it?):
Concerns (what feedback would you like?):
Where should we start reviewing?:
PaxosLearner
Priority (whenever / two weeks / yesterday): this week please