-
Notifications
You must be signed in to change notification settings - Fork 28
/
AsyncSolrClientSpec.scala
52 lines (36 loc) · 1.47 KB
/
AsyncSolrClientSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package io.ino.solrs
import com.ning.http.client.AsyncHttpClient
import org.apache.solr.client.solrj.response.QueryResponse
import org.scalatest.mock.MockitoSugar
import org.scalatest.{Matchers, FunSpec}
import org.mockito.Mockito.{verify, times}
import scala.concurrent.Future
import org.apache.solr.client.solrj.SolrQuery
import java.net.ConnectException
import scala.concurrent.duration._
class AsyncSolrClientSpec extends FunSpec with Matchers with FutureAwaits with MockitoSugar {
private val query = new SolrQuery("*:*")
private implicit val timeout = 1.second
describe("Solr") {
it("should return failed future on connection refused") {
val solr = AsyncSolrClient("http://localhost:12345/solr")
val response: Future[QueryResponse] = solr.query(query)
awaitReady(response)
a [ConnectException] should be thrownBy await(response)
}
it("should shutdown http client if it was not provided") {
val ahcMock = mock[AsyncHttpClient]
val solr = new AsyncSolrClient.Builder("http://localhost:12345/solr") {
override def createHttpClient = ahcMock
}.build
solr.shutdown()
verify(ahcMock).closeAsynchronously()
}
it("should not shutdown http client if it was provided") {
val ahcMock = mock[AsyncHttpClient]
val solr = AsyncSolrClient.Builder("http://localhost:12345/solr").withHttpClient(ahcMock).build
solr.shutdown()
verify(ahcMock, times(0)).closeAsynchronously()
}
}
}