Commit 98810ff7 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add local test which requires elasticsearch connection.

parent 133af479
......@@ -2,10 +2,16 @@ package ch.memobase
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import org.apache.http.HttpHost
import org.elasticsearch.client.RequestOptions
import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestHighLevelClient
import org.elasticsearch.index.query.QueryBuilders
import org.elasticsearch.index.reindex.BulkByScrollResponse
import org.elasticsearch.index.reindex.UpdateByQueryRequest
import org.elasticsearch.script.Script
import org.elasticsearch.script.ScriptType
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.memobase.UpdateQuery
......@@ -15,13 +21,22 @@ import java.io.File
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestUpdateQueries {
private val mapper = ObjectMapper().registerKotlinModule()
private val path = "src/test/resources/data/"
private fun read(fileName: String): UpdateQuery {
return mapper.readValue<UpdateQuery>(File("$path$fileName.json"), UpdateQuery::class.java)!!
}
private val client = RestHighLevelClient(
RestClient.builder(
HttpHost("localhost", 8080)
)
)
@Test
fun `test update query request creation`() {
val mapper = ObjectMapper().registerKotlinModule()
val updateQuery =
mapper.readValue<UpdateQuery>(File("src/test/resources/data/update-query.json"), UpdateQuery::class.java)!!
val updateQuery = read("update-query")
val request = UpdateByQueryRequest("index")
request.isAbortOnVersionConflict = true
request.setQuery(QueryBuilders.termQuery(updateQuery.term, updateQuery.value))
......@@ -29,4 +44,27 @@ class TestUpdateQueries {
ScriptType.INLINE, "painless", updateQuery.source, updateQuery.params
)
}
@Test
@Disabled
fun `test four queries after each other`() {
val messages = listOf(
read("message1"), read("message2"),
read("message3"), read("message4")
)
val responses = mutableListOf<BulkByScrollResponse>()
for (message in messages) {
val request = UpdateByQueryRequest("documents-test-v1")
request.isAbortOnVersionConflict = false
request.setQuery(QueryBuilders.termQuery(message.term, message.value))
request.script = Script(
ScriptType.INLINE, "painless", message.source, message.params
)
val response = client.updateByQuery(request, RequestOptions.DEFAULT)
responses.add(response)
}
print(responses)
}
}
\ No newline at end of file
{
"params": {
"containers": [
{
"facet": [],
"filter": "csa",
"name": {
"de": [
"Cinémathèque suisse"
],
"fr": [
"Cinémathèque suisse"
],
"it": [
"Cinémathèque suisses"
],
"un": []
}
}
]
},
"source": "ctx._source['accessInstitution'] = params.containers",
"term": "recordSet.facet",
"value": "clg-001"
}
\ No newline at end of file
{
"params": {
"containers": [
{
"facet": [],
"filter": "csa",
"name": {
"de": [
"Cinémathèque suisse"
],
"fr": [
"Cinémathèque suisse"
],
"it": [
"Cinémathèque suisses"
],
"un": []
}
}
]
},
"source": "ctx._source['masterInstitution'] = params.containers",
"term": "recordSet.facet",
"value": "clg-001"
}
\ No newline at end of file
{
"params": {
"containers": [
{
"facet": [],
"filter": "csa",
"name": {
"de": [
"Cinémathèque suisse"
],
"fr": [
"Cinémathèque suisse"
],
"it": [
"Cinémathèque suisses"
],
"un": []
}
}
]
},
"source": "ctx._source['originalInstitution'] = params.containers",
"term": "recordSet.facet",
"value": "clg-001"
}
\ No newline at end of file
{
"params": {
"containers": [
{
"facet": [],
"filter": "csa",
"name": {
"de": [
"Cinémathèque suisse"
],
"fr": [
"Cinémathèque suisse"
],
"it": [
"Cinémathèque suisses"
],
"un": []
}
}
]
},
"source": "ctx._source['institution'] = params.containers",
"term": "recordSet.facet",
"value": "clg-001"
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment