Skip to content

Commit

Permalink
Fixed a regression with callerStateHint and await()
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlauer committed May 3, 2011
1 parent 1fe4cf7 commit 804fad6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
Expand Up @@ -281,15 +281,15 @@ public boolean await() throws InterruptedException {

@Override
public boolean await(long timeoutMillis) throws InterruptedException {
// k, if someone actually calls this method -- make sure to set the flag
// this may have already been set earlier, but if not its safe to set here
this.setCallerStateHint(CALLER_WAITING);

// if already done, return immediately
if (isDone()) {
return true;
}

// k, if someone actually calls this method -- make sure to set the flag
// this may have already been set earlier, but if not its safe to set here
this.setCallerStateHint(CALLER_WAITING);

long startTime = System.currentTimeMillis();
// try to acquire lock within given amount of time
if (!windowLock.tryLock(timeoutMillis, TimeUnit.MILLISECONDS)) {
Expand Down Expand Up @@ -317,8 +317,6 @@ public boolean await(long timeoutMillis) throws InterruptedException {
windowLock.unlock();
}

// if we get here, then this future completed successfully
this.setCallerStateHint(CALLER_NOT_WAITING);
return true;
}
}
Expand Up @@ -225,39 +225,6 @@ public void waitingFlagNotOriginallySetButAddedOnAwait() throws Exception {

Assert.assertEquals(WindowFuture.CALLER_WAITING_TIMEOUT, requestFuture0.getCallerStateHint());
}

@Test
public void callerStateHintResetBackToNotWaitingAtCompletion() throws Exception {
Window<Integer,String,String> window = new Window<Integer,String,String>(1);
final WindowFuture<Integer,String,String> future0 = window.offer(0, "Request0", 100, 100, true);
Assert.assertEquals(WindowFuture.CALLER_WAITING, future0.getCallerStateHint());
Assert.assertTrue(future0.isCallerWaiting());

// start up a new thread to mark the future as completed in near future
Thread completer = new Thread() {
@Override
public void run() {
try {
Thread.sleep(100);
} catch (Exception e) { }
future0.cancel();
}
};
completer.start();

// now wait for the future up to 3 times the other thread's sleep
Assert.assertTrue(future0.await(300));

// after await finishes, check hints
Assert.assertEquals(WindowFuture.CALLER_NOT_WAITING, future0.getCallerStateHint());
Assert.assertFalse(future0.isCallerWaiting());

// call await again -- it should immediately succeed
// this is to check that the callerStateHint isn't reset to a new value
Assert.assertTrue(future0.await(300));
Assert.assertEquals(WindowFuture.CALLER_NOT_WAITING, future0.getCallerStateHint());
Assert.assertFalse(future0.isCallerWaiting());
}

@Test
public void cancel() throws Exception {
Expand Down

0 comments on commit 804fad6

Please sign in to comment.