Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c4c6174
Enabling client-side compression in the library, with an option to
davidtorres Feb 22, 2017
27338a4
Merge remote-tracking branch 'upstream/master'
davidtorres Feb 23, 2017
d6a1043
Revert "Enabling client-side compression in the library, with an opti…
davidtorres Feb 23, 2017
823ad09
Merge remote-tracking branch 'upstream/master'
davidtorres Mar 15, 2017
ec14abe
Changing the AckReplyConsumer interface to comply to just the Java 8 …
davidtorres Mar 15, 2017
652894a
Merge remote-tracking branch 'upstream/master'
davidtorres Mar 20, 2017
3e906e6
Example fixes to comply with changes to the AckReplyConsumer interface.
davidtorres Mar 20, 2017
32af932
Allowing for setting a maximum for message lease extensions.
davidtorres Mar 29, 2017
7779e37
Setting so the max ack deadline duration is always respected even when
davidtorres Mar 30, 2017
45248f0
Merge branch 'master' into max-ack-ext
davidtorres Apr 5, 2017
d4f0048
Merge remote-tracking branch 'upstream/master' into max-ack-ext
davidtorres Apr 5, 2017
140b6bc
Merge branch 'master' into max-ack-ext
davidtorres Apr 10, 2017
4debcbb
Align with the changes to ApiClock
davidtorres Apr 10, 2017
4883e6f
Adding a test for testing the default max ack extension duration is
davidtorres Apr 11, 2017
347c661
Addressing feedback:
davidtorres Apr 11, 2017
09172a6
Fixing race conditions in tests that for thread scheduling reason
davidtorres Apr 11, 2017
6a21a54
Addressing codacy warnings
davidtorres Apr 11, 2017
204438c
Adding documentation to the new added method in the
davidtorres Apr 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.concurrent.AbstractExecutorService;
Expand Down Expand Up @@ -79,6 +81,26 @@ public ScheduledFuture<?> scheduleWithFixedDelay(
Duration.millis(unit.toMillis(initialDelay)), command, PendingCallableType.FIXED_DELAY));
}

private Deque<Duration> expectedWorkQueue = new LinkedList<>();

public void setupScheduleExpectation(Duration delay) {

This comment was marked as spam.

synchronized (expectedWorkQueue) {
expectedWorkQueue.add(delay);
}
}

public void waitForExpectedWork() {
synchronized (expectedWorkQueue) {
while (!expectedWorkQueue.isEmpty()) {
try {
expectedWorkQueue.wait();
} catch (InterruptedException e) {
// Wait uninterruptibly
}
}
}
}

/**
* This will advance the reference time of the executor and execute (in the same thread) any
* outstanding callable which execution time has passed.
Expand All @@ -100,7 +122,7 @@ private void work() {
callable = pendingCallables.poll();
}
if (callable != null) {
try{
try {
callable.call();
} catch (Exception e) {
// We ignore any callable exception, which should be set to the future but not relevant to
Expand Down Expand Up @@ -182,6 +204,13 @@ <V> ScheduledFuture<V> schedulePendingCallable(PendingCallable<V> callable) {
pendingCallables.add(callable);
}
work();
synchronized (expectedWorkQueue) {

This comment was marked as spam.

This comment was marked as spam.

if (!expectedWorkQueue.isEmpty() && expectedWorkQueue.peek().equals(callable.delay)) {

This comment was marked as spam.

This comment was marked as spam.

expectedWorkQueue.poll();
}
expectedWorkQueue.notifyAll();
}

return callable.getScheduledFuture();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ public void testModifyAckDeadline() throws Exception {
// Send messages to be acked
List<String> testAckIdsBatch = ImmutableList.of("A", "B", "C");
testReceiver.setExplicitAck(true);
// A modify ack deadline should be schedule for the next 9s

This comment was marked as spam.

This comment was marked as spam.

fakeExecutor.setupScheduleExpectation(Duration.standardSeconds(9));
sendMessages(testAckIdsBatch);
// To ensure first modify ack deadline got scheduled
fakeExecutor.waitForExpectedWork();

// Trigger modify ack deadline sending - 10s initial stream ack deadline - 1 padding
fakeExecutor.advanceTime(Duration.standardSeconds(9));

assertEquivalentWithTransformation(
Expand All @@ -299,17 +302,16 @@ public ModifyAckDeadline apply(String ack) {
}
});

// Trigger modify ack deadline sending - 2s of the renewed deadlines
fakeExecutor.advanceTime(Duration.standardSeconds(2));
fakeExecutor.advanceTime(Duration.standardSeconds(1));

assertEquivalentWithTransformation(
testAckIdsBatch,
fakeSubscriberServiceImpl.waitAndConsumeModifyAckDeadlines(3),
new Function<String, ModifyAckDeadline>() {
@Override
public ModifyAckDeadline apply(String ack) {
return new ModifyAckDeadline(ack, 2); // It is expected that the deadline is renewed
// only two more seconds to not pass the max
return new ModifyAckDeadline(ack, 3); // It is expected that the deadline is renewed
// only three more seconds to not pass the max
// ack deadline ext.
}
});
Expand All @@ -332,9 +334,13 @@ public void testModifyAckDeadline_defaultMaxExtensionPeriod() throws Exception {
// Send messages to be acked
List<String> testAckIdsBatch = ImmutableList.of("A", "B", "C");
testReceiver.setExplicitAck(true);
// A modify ack deadline should be schedule for the next 9s
fakeExecutor.setupScheduleExpectation(Duration.standardSeconds(9));
sendMessages(testAckIdsBatch);
// To ensure the first modify ack deadlines got scheduled
fakeExecutor.waitForExpectedWork();

// Trigger modify ack deadline sending - 10s initial stream ack deadline - 1 padding
// Next modify ack deadline should be schedule in the next 1s
fakeExecutor.advanceTime(Duration.standardSeconds(9));

assertEquivalentWithTransformation(
Expand All @@ -347,12 +353,12 @@ public ModifyAckDeadline apply(String ack) {
}
});

int timeIncrementSecs = INITIAL_ACK_DEADLINE_EXTENSION_SECS * 2; // Second time increment
fakeExecutor.advanceTime(Duration.standardSeconds(1));
int timeIncrementSecs = INITIAL_ACK_DEADLINE_EXTENSION_SECS; // Second time increment

// Check ack deadline extensions while the current time has not reached 60 minutes
while (fakeExecutor.getClock().millisTime() + (timeIncrementSecs * 1000) < 1000 * 60 * 60) {
fakeExecutor.advanceTime(Duration.standardSeconds(timeIncrementSecs));

while (fakeExecutor.getClock().millisTime() + timeIncrementSecs - 1 < 1000 * 60 * 60) {
timeIncrementSecs *= 2;
final int expectedIncrementSecs = Math.min(600, timeIncrementSecs);
assertEquivalentWithTransformation(
testAckIdsBatch,
Expand All @@ -363,7 +369,7 @@ public ModifyAckDeadline apply(String ack) {
return new ModifyAckDeadline(ack, expectedIncrementSecs);
}
});
timeIncrementSecs *= 2;
fakeExecutor.advanceTime(Duration.standardSeconds(timeIncrementSecs - 1));
}

// No more modify ack deadline extension should be triggered at this point
Expand Down