Add support for supplying your own Queue implementation to the InMemoryQueue

This will make it a bit easier to test inside of Spock with pre-configured/set
up queues
This commit is contained in:
R. Tyler Croy 2014-12-30 21:23:12 -08:00
parent 2689feb2cd
commit 8087920b71
2 changed files with 25 additions and 2 deletions

View File

@ -1,18 +1,28 @@
package com.github.lookout.whoas
import java.util.Queue
import java.util.concurrent.LinkedBlockingQueue
/**
* A simple in-memory queue that offers no persistence between process restarts
*/
class InMemoryQueue implements IHookQueue {
private LinkedBlockingQueue internalQueue
private Queue internalQueue
/**
* Create the InMemoryQueue with it's own internal queueing implementation
*/
InMemoryQueue() {
this.internalQueue = new LinkedBlockingQueue()
}
/**
* Create the InMemoryQueue with the given Queue object
*/
InMemoryQueue(Queue queue) {
this.internalQueue = queue
}
Long getSize() {
return this.internalQueue.size()
}

View File

@ -1,5 +1,6 @@
package com.github.lookout.whoas
import java.util.concurrent.ArrayBlockingQueue
import spock.lang.*
class InMemoryQueueSpec extends Specification {
@ -12,3 +13,15 @@ class InMemoryQueueSpec extends Specification {
queue.size == 0
}
}
class InMemoryQueueWithGivenQueueSpec extends Specification {
def "getSize() should return 0 by default"() {
given:
ArrayBlockingQueue internal = new ArrayBlockingQueue(1)
InMemoryQueue queue = new InMemoryQueue(internal)
expect:
queue.size == 0
}
}