Skip to content

Commit

Permalink
Resolve warnings (#3117)
Browse files Browse the repository at this point in the history
* Replace deprecated get(id)

* Replace deprecated update(id)

* Replace deprecated updateIn(indexes)

* Undeprecate string and bytes methods

* Remove unused imports

* Replace deprecated schedule with scheduleWithFixedDelay

* Replace deprecated send with send(sttpBackend)

* Replace deprecated unsafeCompat with unsafe

* Avoid deprecated DenseVectorField apply method

* Replace deprecated removeAlias and addAlias methods

* Replace deprecated .right.value syntax
  • Loading branch information
Philippus authored Jul 16, 2024
1 parent 2808d63 commit 90321b2
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class SttpRequestHttpClient(nodeEndpoint: ElasticNodeEndpoint)(
*/
override def send(request: ElasticRequest, callback: Either[Throwable, HttpResponse] => Unit): Unit = {
val f = request.entity match {
case Some(entity) => async(request.method, request.endpoint, request.params, request.headers, entity).send()
case None => async(request.method, request.endpoint, request.params, request.headers).send()
case Some(entity) => async(request.method, request.endpoint, request.params, request.headers, entity).send(sttpBackend)
case None => async(request.method, request.endpoint, request.params, request.headers).send(sttpBackend)
}
f.onComplete {
case Success(resp) => callback(Right(processResponse(resp)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sksamuel.elastic4s.requests.searches.aggs.builders

import com.sksamuel.elastic4s.handlers.searches.queries
import com.sksamuel.elastic4s.handlers.searches.queries.QueryBuilderFn
import com.sksamuel.elastic4s.json.{XContentBuilder, XContentFactory}
import com.sksamuel.elastic4s.requests.searches.aggs.{AbstractAggregation, AggMetaDataFn, FilterAggregation, SubAggsBuilderFn}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sksamuel.elastic4s.requests.searches.aggs.builders

import com.sksamuel.elastic4s.handlers.searches.queries
import com.sksamuel.elastic4s.handlers.searches.queries.QueryBuilderFn
import com.sksamuel.elastic4s.json.{XContentBuilder, XContentFactory}
import com.sksamuel.elastic4s.requests.searches.aggs.{AbstractAggregation, AggMetaDataFn, KeyedFiltersAggregation, SubAggsBuilderFn}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class DenseVectorFieldTest extends AnyFlatSpec with Matchers with ElasticApi {
private val denseVectorIndexOptions = DenseVectorIndexOptions(Int8Hnsw, Some(10), Some(100), Some(1.0f))

"A DenseVectorField" should "support dims property" in {
val field = DenseVectorField(name = "myfield", dims = 3)
val field = DenseVectorField(name = "myfield").dims(3)
DenseVectorFieldBuilderFn.build(field).string shouldBe
"""{"type":"dense_vector","dims":3,"index":false}"""
"""{"type":"dense_vector","dims":3}"""
}

it should "support all similarity options" in {
val field = DenseVectorField(name = "myfield", dims = 3, index = true, similarity = L2Norm)
val field = DenseVectorField(name = "myfield").dims(3).index(true).similarity(L2Norm)
DenseVectorFieldBuilderFn.build(field).string shouldBe
"""{"type":"dense_vector","dims":3,"index":true,"similarity":"l2_norm"}"""
DenseVectorFieldBuilderFn.build(field.similarity(DotProduct)).string shouldBe
Expand All @@ -29,9 +29,9 @@ class DenseVectorFieldTest extends AnyFlatSpec with Matchers with ElasticApi {
}

it should "support elementType property" in {
val field = DenseVectorField(name = "myfield", dims = 3).elementType("byte")
val field = DenseVectorField(name = "myfield").dims(3).elementType("byte")
DenseVectorFieldBuilderFn.build(field).string shouldBe
"""{"type":"dense_vector","element_type":"byte","dims":3,"index":false}"""
"""{"type":"dense_vector","element_type":"byte","dims":3}"""
}

it should "not set similarity or indexOptions when index = false" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MultiSearchHandlerTest extends AnyFlatSpec with Matchers with EitherValues
| ]
|}""".stripMargin
val response = HttpResponse(200, Some(StringEntity(responseBody, None)), Map.empty)
val mResponse = MultiSearchHandler.responseHandler.handle(response).right.value
val mResponse = MultiSearchHandler.responseHandler.handle(response).value
mResponse.items should have size 2
mResponse.items.map(_.status) shouldEqual Seq(200, 400)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class UpdateByQueryBodyFnTest extends AnyWordSpec with JsonSugar {
"update by query" should {
"generate correct body" when {
"script is specified" in {
val q = updateIn("test").query(matchQuery("field", 123)).script(Script("script", Some("painless")))
val q = updateByQuerySync("test", matchQuery("field", 123)).script(Script("script", Some("painless")))
UpdateByQueryBodyFn(q).string should matchJson(
"""{"query":{"match":{"field":{"query":123}}},"script":{"lang":"painless","source":"script"}}"""
)
}
"script is not specified" in {
val q = updateIn("test").query(matchQuery("field", 123))
val q = updateByQuerySync("test", matchQuery("field", 123))
UpdateByQueryBodyFn(q).string should matchJson(
"""{"query":{"match":{"field":{"query":123}}}}"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ZIOTaskTest extends AnyFlatSpec with Matchers with DockerTests with Before

implicit class RichZIO[A](task: Task[A]) {
def unsafeRun: Either[Throwable, A] = {
Unsafe.unsafeCompat { implicit u =>
Unsafe.unsafe { implicit u =>
zio.Runtime.default.unsafe.run(task).toEither
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BulkActor[T](client: ElasticClient,
// It has been suggested we can use ReceiveTimeout here, but one reason we can't is because BulkResult messages,
// will cause the timeout period to be reset, but they shouldn't interfere with the flush interval.
private val flushIntervalScheduler: Option[Cancellable] = config.flushInterval.map { interval =>
system.scheduler.schedule(interval, interval, self, BulkActor.ForceIndexing)
system.scheduler.scheduleWithFixedDelay(interval, interval, self, BulkActor.ForceIndexing)
}

// If flushAfter is specified then after each message, a scheduler is created to force indexing if no documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class XContentBuilder(root: JsonValue) {
def value: JsonValue = root

// generate a json string from the contents of the builder
@deprecated("will be replaced with a pluggable system")
def string: String = JacksonBuilder.writeAsString(root)

@deprecated("will be replaced with a pluggable system")
def bytes: Array[Byte] = JacksonBuilder.writeAsString(root).getBytes

def array(field: String, strings: Array[String]): XContentBuilder = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ trait ElasticSugar extends ElasticDsl {
blockUntil(s"Expected document $id to have version $version") { () =>
client
.execute {
get(id).from(index)
get(index, id)
}
.await
.result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ trait IndexMatchers extends Matchers {
new Matcher[String] {

override def apply(left: String): MatchResult = {
val exists = client.execute(get(expectedId.toString).from(left)).await(timeout).result.exists
val exists = client.execute(get(left, expectedId.toString)).await(timeout).result.exists
MatchResult(
exists,
s"Index $left did not contain expected document $expectedId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ class HitReaderTest extends AnyFlatSpec with MockitoSugar with DockerTests with

it should "unmarshall safely a get response" in {
val team = client.execute {
get("1").from(IndexName)
get(IndexName, "1")
}.await.result.safeTo[Team]

team shouldBe Success(Team("Middlesbrough", "Fortress Riverside", 1876))
}

it should "unmarshall a get response" in {
val team = client.execute {
get("1").from(IndexName)
get(IndexName, "1")
}.await.result.to[Team]

team shouldBe Team("Middlesbrough", "Fortress Riverside", 1876)
Expand All @@ -104,8 +104,8 @@ class HitReaderTest extends AnyFlatSpec with MockitoSugar with DockerTests with
it should "unmarshall safely multi get results" in {
val teams = client.execute {
multiget(
get("1").from(IndexName),
get("2").from(IndexName)
get(IndexName, "1"),
get(IndexName, "2")
)
}.await.result.safeTo[Team]

Expand All @@ -118,8 +118,8 @@ class HitReaderTest extends AnyFlatSpec with MockitoSugar with DockerTests with
it should "unmarshall multi get results" in {
val teams = client.execute {
multiget(
get("1").from(IndexName),
get("2").from(IndexName)
get(IndexName, "1"),
get(IndexName, "2")
)
}.await.result.to[Team]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class AliasesHttpTest extends AnyWordSpec with Matchers with DockerTests {
"multiple operations" in {
client.execute {
aliases(
removeAlias("beaches_alias").on("beaches"),
addAlias("mountains_alias").on("mountains")
removeAlias("beaches_alias", "beaches"),
addAlias("mountains_alias", "mountains")
)
}.await.result should be(AliasActionResponse(true))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
"A Get request" should "retrieve a document by id" in {

val resp = client.execute {
get("8") from "beer"
get("beer", "8")
}.await.result

resp.exists shouldBe true
Expand All @@ -53,7 +53,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "retrieve a document by id with source" in {

val resp = client.execute {
get("8") from "beer"
get("beer", "8")
}.await.result

resp.exists shouldBe true
Expand All @@ -64,7 +64,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "retrieve a document by id without source" in {

val resp = client.execute {
get("8") from "beer" fetchSourceContext false
get("beer", "8") fetchSourceContext false
}.await.result

resp.exists should be(true)
Expand All @@ -76,7 +76,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "support source includes" in {

val resp = client.execute {
get("8") from "beer" fetchSourceInclude "brand"
get("beer", "8") fetchSourceInclude "brand"
}.await.result

resp.exists should be(true)
Expand All @@ -87,7 +87,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "support source excludes" in {

val resp = client.execute {
get("8") from "beer" fetchSourceExclude "brand"
get("beer", "8") fetchSourceExclude "brand"
}.await.result

resp.exists should be(true)
Expand All @@ -98,7 +98,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "support source includes and excludes" in {

val resp = client.execute {
get("8") from "beer" fetchSourceContext(List("name"), List("brand"))
get("beer", "8") fetchSourceContext(List("name"), List("brand"))
}.await.result

resp.exists should be(true)
Expand All @@ -109,7 +109,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "support specifying source includes and excludes separately" in {

val resp = client.execute {
get("8") from "beer" fetchSourceInclude(List("name")) fetchSourceExclude(List("bran"))
get("beer", "8") fetchSourceInclude(List("name")) fetchSourceExclude(List("bran"))
}.await.result

resp.exists should be(true)
Expand All @@ -120,7 +120,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "retrieve a document supporting stored fields" in {

val resp = client.execute {
get("4") from "beer" storedFields("name", "brand")
get("beer", "4") storedFields("name", "brand")
}.await.result

resp.exists should be(true)
Expand All @@ -132,7 +132,7 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
it should "retrieve multi value fields" in {

val resp = client.execute {
get("4") from "beer" storedFields "ingredients"
get("beer", "4") storedFields "ingredients"
}.await.result

val field = resp.storedField("ingredients")
Expand All @@ -141,13 +141,13 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {

it should "return Left[RequestFailure] when index does not exist" in {
client.execute {
get("4") from "qqqqqqqqqq"
get("qqqqqqqqqq", "4")
}.await.error.`type` shouldBe "index_not_found_exception"
}

it should "return Right with exists=false when the doc does not exist" in {
client.execute {
get("111111") from "beer"
get("beer", "111111")
}.await.result.exists shouldBe false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class MultiGetTest extends AnyFlatSpec with MockitoSugar with DockerTests {

val resp = client.execute(
multiget(
get("3").from("coldplay"),
get("5") from "coldplay",
get("7") from "coldplay"
get("coldplay", "3"),
get("coldplay", "5"),
get("coldplay", "7")
)
).await.result

Expand All @@ -60,8 +60,8 @@ class MultiGetTest extends AnyFlatSpec with MockitoSugar with DockerTests {

val resp = client.execute(
multiget(
get("3").from("coldplay"),
get("711111") from "coldplay"
get("coldplay", "3"),
get("coldplay", "711111")
)
).await.result

Expand All @@ -74,8 +74,8 @@ class MultiGetTest extends AnyFlatSpec with MockitoSugar with DockerTests {

val resp = client.execute(
multiget(
get("3") from "coldplay" storedFields("name", "year"),
get("5") from "coldplay" storedFields "name"
get("coldplay", "3") storedFields("name", "year"),
get("coldplay", "5") storedFields "name"
)
).await.result

Expand All @@ -88,8 +88,8 @@ class MultiGetTest extends AnyFlatSpec with MockitoSugar with DockerTests {

val resp = client.execute(
multiget(
get("3") from "coldplay" fetchSourceContext Seq("name", "year"),
get("5") from "coldplay" fetchSourceContext Seq("name")
get("coldplay", "3") fetchSourceContext Seq("name", "year"),
get("coldplay", "5") fetchSourceContext Seq("name")
)
).await.result
resp.size shouldBe 2
Expand All @@ -99,7 +99,7 @@ class MultiGetTest extends AnyFlatSpec with MockitoSugar with DockerTests {
it should "retrieve documents by id with routing spec" in {

val resp = client.execute(
multiget(get("3") from "coldplay" routing "3")
multiget(get("coldplay", "3") routing "3")
).await.result

resp.size shouldBe 1
Expand Down
Loading

0 comments on commit 90321b2

Please sign in to comment.