Permalink
Browse files

Merge pull request #20 from holdenk/master

Timer updates
  • Loading branch information...
2 parents 267f4b4 + 0c0e2d1 commit 6cf7e02b524c41e7b5f71c5d99b74cd2abc88cbc @adamalix adamalix committed Mar 23, 2012
View
@@ -1,6 +1,6 @@
name := "slashem"
-version := "0.9.6"
+version := "0.9.7"
organization := "com.foursquare"
@@ -467,6 +467,7 @@ trait ElasticSchema[M <: Record[M]] extends SlashemSchema[M] {
def elasticQueryFuture[Ord, Lim, MM <: MinimumMatchType, Y, H <: Highlighting, Q <: QualityFilter, FC <: FacetCount, FLim](qb: QueryBuilder[M, Ord, Lim, MM, Y, H, Q, FC, FLim], query: ElasticQueryBuilder, timeoutOpt: Option[Duration]): Future[SearchResults[M, Y]] = {
val esfp = meta.executorServiceFuturePool
+ val searchResultsFuture = esfp {
val client = meta.client
val from = qb.start.map(_.toInt).getOrElse(qb.DefaultStart)
val limit = qb.limit.map(_.toInt).getOrElse(qb.DefaultLimit)
@@ -502,23 +503,25 @@ trait ElasticSchema[M <: Record[M]] extends SlashemSchema[M] {
timeLimmitedRequest
}
}
-
- val searchResultsFuture = esfp {
val response : SearchResponse = facetedRequest.execute().get()
+ response
+ }
+
+ timeFuture(searchResultsFuture).map( {
+ case (queryTime, result) => {
+ meta.logger.log("e" + meta.indexName + ".query",query.toString(), queryTime)
+ result
+ }}).map({
+ response =>
meta.logger.debug("Search response "+response.toString())
val results = constructSearchResults(qb.creator,
qb.start.map(_.toInt).getOrElse(qb.DefaultStart),
qb.fallOf,
qb.min,
response)
- results
- }
- timeFuture(searchResultsFuture).map( {
- case (queryTime, result) => {
- meta.logger.log("e" + meta.indexName + ".query",query.toString(), queryTime)
- result
- }})
+ results
+ })
}
def constructSearchResults[Y](creator: Option[Response.RawDoc => Y],
start: Int,
@@ -24,7 +24,7 @@ import java.util.UUID
import scalaj.collection.Imports._
-import com.twitter.util.{Duration, ExecutorServiceFuturePool, Future, FuturePool, FutureTask}
+import com.twitter.util.{Duration, ExecutorServiceFuturePool, Future, FuturePool, FutureTask, Throw, TimeoutException}
import java.util.concurrent.{Executors, ExecutorService}
object ElasticNode {
@@ -48,8 +48,29 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
Thread.sleep(100)
1
})
- Assert.assertEquals(1,future.get())
+ Assert.assertEquals(1,future.apply(Duration(200,TimeUnit.MILLISECONDS)))
}
+
+ @Test(expected=classOf[TimeoutException])
+ def futureTestBlock {
+ val executor = Executors.newCachedThreadPool()
+ val esfp = FuturePool(executor)
+ var x = 1
+ val future : Future[Int]= esfp({
+ Thread.sleep(200)
+ 1
+ })
+ future.apply(Duration(10,TimeUnit.MILLISECONDS))
+ }
+
+ @Test(expected=classOf[TimeoutException])
+ def testRecipGeoBoostTimeout {
+ val geoLat = 74
+ val geoLong = -31
+ val r = ESimpleGeoPanda where (_.name contains "lolerskates") scoreBoostField(_.pos recipSqeGeoDistance(geoLat, geoLong, 1, 5000, 1)) fetch(Duration(0,TimeUnit.MILLISECONDS))
+ }
+
+
@Test
def testEmptySearch {
try {

0 comments on commit 6cf7e02

Please sign in to comment.