-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up a way to test with the actual dockerised Solr instance
The search data is still not shareable so this is downloaded from S3 at CI time
- Loading branch information
Showing
8 changed files
with
123 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,16 @@ jobs: | |
- name: Checkout | ||
uses: actions/checkout@v1 | ||
|
||
# Download data file used for config testing | ||
- uses: keithweaver/[email protected] | ||
with: | ||
command: cp | ||
source: s3://ehri-data/solr_test_data/searchdata.json | ||
destination: ./test/resources/searchdata.json | ||
aws_access_key_id: ${{ secrets.AWS_S3_ACCESS_KEY }} | ||
aws_secret_access_key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} | ||
aws_region: us-west-1 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package integration.search | ||
|
||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.Http | ||
import akka.http.scaladsl.model._ | ||
import akka.stream.Materializer | ||
import akka.util.ByteString | ||
import config.ServiceConfig | ||
import helpers.SearchTestRunner | ||
import play.api.{Application, Configuration, Environment, Logger} | ||
import services.search._ | ||
import utils.PageParams | ||
|
||
import java.nio.file.Paths | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
|
||
/** | ||
* Spec to test the ingest UI and websocket monitoring. | ||
*/ | ||
class SolrSearchSpec extends SearchTestRunner { | ||
|
||
val logger = Logger(classOf[SolrSearchSpec]) | ||
|
||
private def initSolr(): Unit = { | ||
val env = Environment.simple() | ||
val config = Configuration.load(env) | ||
val port = config.get[Int]("services.solr.port") | ||
if (port == 8983) { | ||
throw new RuntimeException(s"Solr port is set to default value: $port, bailing out...") | ||
} | ||
|
||
implicit val as: ActorSystem = ActorSystem() | ||
val mat = Materializer(as) | ||
implicit val ec: ExecutionContext = mat.executionContext | ||
|
||
def req(payload: UniversalEntity): Future[HttpResponse] = { | ||
val url = ServiceConfig("solr", config).baseUrl + "/update?commit=true" | ||
Http().singleRequest(HttpRequest(HttpMethods.POST, url).withEntity(payload)) | ||
} | ||
|
||
logger.debug("Clearing Solr data...") | ||
val json = ByteString.fromString("""{"delete": {"query": "*:*"}}""") | ||
await(req(HttpEntity.apply(ContentTypes.`application/json`, json))) | ||
|
||
logger.debug("Loading Solr data...") | ||
val resource = Paths.get(getClass.getResource("/searchdata.json").toURI) | ||
val entity = HttpEntity.fromPath(ContentTypes.`application/json`, resource) | ||
await(req(entity)) | ||
|
||
await(as.terminate()) | ||
} | ||
initSolr() | ||
|
||
|
||
def engine(implicit app: Application) = app.injector.instanceOf[SearchEngine] | ||
|
||
def simpleSearch(engine: SearchEngine, q: String): Future[SearchResult[SearchHit]] = | ||
engine.search(SearchQuery( | ||
params = SearchParams(query = Some(q)), | ||
paging = PageParams.empty.withoutLimit)) | ||
|
||
"Solr search engine should" should { | ||
"find things" in new ITestApp { | ||
val r = await(simpleSearch(engine, "USHMM")) | ||
r.page.size must be_>(0) | ||
} | ||
|
||
"find other things" in new ITestApp { | ||
val r = await(simpleSearch(engine, "Wiener Library")) | ||
r.page.size must be_>(0) | ||
} | ||
} | ||
} |