Permalink
Browse files

Found bug in batch request handler, wrote test and squashed bug

  • Loading branch information...
1 parent c2d4e5d commit 53bfeb5524de90d9c0c784bf26ba311d91885c4e @samhendley samhendley committed May 10, 2012
@@ -104,7 +104,10 @@ trait BatchRestOperationsImpl extends BatchRestOperations with DerivedRestOperat
def nextBatch(prevFailed: Option[ReefServiceException], pending: List[QueuedRequest[_]], totalSize: Int, promise: OpenPromise[java.lang.Integer]) {
prevFailed match {
- case Some(rse) => promise.setFailure(rse)
+ case Some(rse) =>
+ // if an early request failed, fail all of the future promises as well
+ pending.foreach(_.promise.setFailure(rse))
+ promise.setFailure(rse)
case None => pending match {
case Nil => promise.setSuccess(totalSize)
case remains =>
@@ -151,27 +151,31 @@ class BatchServiceOperationsTest extends FunSuite with ShouldMatchers {
}
test("Handles Partial Failures") {
- val ops = new MockBatch(conditionalSuccess(List(None, Some("partial failure"))))
+ val ops = new MockBatch(conditionalSuccess(List(None, Some("partial failure"), None)))
val successFuture = ops.request(Envelope.Verb.PUT, SomeInteger(100))
val failureFuture = ops.request(Envelope.Verb.PUT, SomeInteger(200))
+ val afterFailure = ops.request(Envelope.Verb.PUT, SomeInteger(300))
- val batchResult = ops.flush()
+ val batchResult = ops.batchedFlush(1)
intercept[BadRequestException] {
batchResult.await
}.getMessage should include("partial failure")
- successFuture.isComplete should equal(true)
- failureFuture.isComplete should equal(true)
+ val futures = List(successFuture, failureFuture, afterFailure)
- intercept[BadRequestException] {
- successFuture.await
- }.getMessage should include("partial failure")
+ futures.map { _.isComplete } should equal(List(true, true, true))
- intercept[BadRequestException] {
- failureFuture.await
- }.getMessage should include("partial failure")
+ // check that all three futures have same error message
+ val errors = futures.map { f =>
+ intercept[BadRequestException] {
+ f.await
+ }.getMessage
+ }.distinct
+
+ errors.size should equal(1)
+ errors.head should include("partial failure")
}
test("BatchedFlush will send in chunks") {

0 comments on commit 53bfeb5

Please sign in to comment.