Skip to content

Commit

Permalink
* addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
benedeki committed Nov 27, 2024
1 parent b287a66 commit d04d23b
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object JsonSyntaxExtensions {
}
}

def asSafe[T: Decoder]: Either[io.circe.Error, T] = {
private def asSafe[T: Decoder]: Either[io.circe.Error, T] = {
decode[T](jsonStr)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package za.co.absa.atum.model.dto
import org.scalatest.flatspec.AnyFlatSpecLike
import za.co.absa.atum.model.ResultValueType
import za.co.absa.atum.model.dto.MeasureResultDTO.TypedValue
import za.co.absa.atum.model.testing.implicits.StringImplicits.StringLinearization
import za.co.absa.atum.model.utils.JsonSyntaxExtensions._
import za.co.absa.atum.testing.implicits.StringImplicits.StringLinearization

import java.time.{ZoneId, ZoneOffset, ZonedDateTime}
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package za.co.absa.atum.model.testing.implicits
package za.co.absa.atum.testing.implicits

object StringImplicits {
implicit class StringLinearization(val str: String) extends AnyVal {
Expand Down
11 changes: 1 addition & 10 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ object Dependencies {
}

def readerDependencies(scalaVersion: Version): Seq[ModuleID] = {
val zioOrg = "dev.zio"
val sbtOrg = "com.github.sbt"
val sttpClient3Org = "com.softwaremill.sttp.client3"
val typeLevelOrg = "org.typelevel"
Expand All @@ -251,19 +250,11 @@ object Dependencies {
val catsEffect = typeLevelOrg %% "cats-effect" % Versions.catsEffect % Optional
val sttpCats = sttpClient3Org %% "cats" % Versions.sttpClient % Optional

// ZIO backend
val sttpZio = sttpClient3Org %% "zio" % Versions.sttpClient % Optional

// testing
val zioTest = zioOrg %% "zio-test" % Versions.zio % Test

Seq(
sttpCore,
sttpCirce,
sttpCats,
catsEffect,
sttpZio,
zioTest
catsEffect
) ++
testDependencies ++
jsonSerdeDependencies
Expand Down

This file was deleted.

5 changes: 3 additions & 2 deletions reader/src/main/scala/za/co/absa/atum/reader/FlowReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package za.co.absa.atum.reader
import sttp.client3.SttpBackend
import sttp.monad.MonadError
import za.co.absa.atum.model.types.basic.AtumPartitions
import za.co.absa.atum.reader.basic.ReaderWithPartitioningId
import za.co.absa.atum.reader.basic.{PartitioningIdProvider, Reader}
import za.co.absa.atum.reader.server.ServerConfig

/**
Expand All @@ -32,7 +32,8 @@ import za.co.absa.atum.reader.server.ServerConfig
* @tparam F - the effect type (e.g. Future, IO, Task, etc.)
*/
class FlowReader[F[_]](val mainFlowPartitioning: AtumPartitions)
(implicit serverConfig: ServerConfig, backend: SttpBackend[F, Any], ev: MonadError[F]) extends ReaderWithPartitioningId[F] {
(implicit serverConfig: ServerConfig, backend: SttpBackend[F, Any], ev: MonadError[F])
extends Reader[F] with PartitioningIdProvider[F]{

override def partitioning: AtumPartitions = mainFlowPartitioning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package za.co.absa.atum.reader
import sttp.client3.SttpBackend
import sttp.monad.MonadError
import za.co.absa.atum.model.types.basic.AtumPartitions
import za.co.absa.atum.reader.basic.ReaderWithPartitioningId
import za.co.absa.atum.reader.basic.{PartitioningIdProvider, Reader}
import za.co.absa.atum.reader.server.ServerConfig

/**
Expand All @@ -33,7 +33,7 @@ import za.co.absa.atum.reader.server.ServerConfig
*/
case class PartitioningReader[F[_]](partitioning: AtumPartitions)
(implicit serverConfig: ServerConfig, backend: SttpBackend[F, Any], ev: MonadError[F])
extends ReaderWithPartitioningId[F] {
extends Reader[F] with PartitioningIdProvider[F]{
def foo(): String = {
// just to have some testable content
"bar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package za.co.absa.atum.reader.basic

import sttp.client3.SttpBackend
import sttp.monad.MonadError
import sttp.monad.syntax._
import za.co.absa.atum.model.dto.PartitioningWithIdDTO
Expand All @@ -25,13 +24,11 @@ import za.co.absa.atum.model.types.basic.AtumPartitions
import za.co.absa.atum.model.types.basic.AtumPartitionsOps
import za.co.absa.atum.model.utils.JsonSyntaxExtensions.JsonSerializationSyntax
import za.co.absa.atum.reader.basic.RequestResult.RequestResult
import za.co.absa.atum.reader.server.ServerConfig

abstract class ReaderWithPartitioningId[F[_]: MonadError](implicit serverConfig: ServerConfig, backend: SttpBackend[F, Any])
extends Reader[F] {
trait PartitioningIdProvider[F[_]] {self: Reader[F] =>
def partitioning: AtumPartitions

protected def partitioningId(): F[RequestResult[Long]] = {
def partitioningId()(implicit monad: MonadError[F]): F[RequestResult[Long]] = {
val encodedPartitioning = partitioning.toPartitioningDTO.asBase64EncodedJsonString
val queryResult = getQuery[SingleSuccessResponse[PartitioningWithIdDTO]]("/api/v2/partitionings", Map("partitioning" -> encodedPartitioning))
queryResult.map{result =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,3 @@ abstract class Reader[F[_]: MonadError](implicit val serverConfig: ServerConfig,
response.map(_.toRequestResult)
}
}

object Reader {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import sttp.monad.{FutureMonad => SttpFutureMonad}
import scala.concurrent.ExecutionContext.Implicits.global

object future {
implicit val FutureMonad: SttpFutureMonad = new SttpFutureMonad
final implicit val futureMonadError: SttpFutureMonad = new SttpFutureMonad
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ import cats.effect.IO
import sttp.client3.impl.cats.CatsMonadAsyncError

object io {
implicit val CatsIOMonad: CatsMonadAsyncError[IO] = new CatsMonadAsyncError[IO]
final implicit val catsIOMonadError: CatsMonadAsyncError[IO] = new CatsMonadAsyncError[IO]
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import sttp.client3.SttpBackend
import sttp.client3.testing.SttpBackendStub
import za.co.absa.atum.model.types.basic.AtumPartitions
import za.co.absa.atum.reader.server.ServerConfig
import za.co.absa.atum.reader.implicits.future.FutureMonad
import za.co.absa.atum.reader.implicits.future.futureMonadError

import scala.concurrent.Future

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import sttp.client3.SttpBackend
import sttp.client3.testing.SttpBackendStub
import za.co.absa.atum.model.types.basic.AtumPartitions
import za.co.absa.atum.reader.server.ServerConfig
import za.co.absa.atum.reader.implicits.future.FutureMonad
import za.co.absa.atum.reader.implicits.future.futureMonadError

import scala.concurrent.Future

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import sttp.client3._
import sttp.client3.monad.IdMonad
import sttp.client3.testing.SttpBackendStub
import sttp.model._
import sttp.monad.MonadError
import za.co.absa.atum.model.dto.PartitioningWithIdDTO
import za.co.absa.atum.model.envelopes.NotFoundErrorResponse
import za.co.absa.atum.model.envelopes.SuccessResponse.SingleSuccessResponse
Expand All @@ -30,7 +31,7 @@ import za.co.absa.atum.model.utils.JsonSyntaxExtensions.JsonSerializationSyntax
import za.co.absa.atum.reader.basic.RequestResult._
import za.co.absa.atum.reader.server.ServerConfig

class ReaderWithPartitioningIdUnitTests extends AnyFunSuiteLike {
class PartitioningIdProviderUnitTests extends AnyFunSuiteLike {
private val serverUrl = "http://localhost:8080"
private val atumPartitionsToReply = AtumPartitions("a", "b")
private val atumPartitionsToFailedDecode = AtumPartitions("c", "d")
Expand All @@ -53,10 +54,11 @@ class ReaderWithPartitioningIdUnitTests extends AnyFunSuiteLike {
}


private case class ReaderWithPartitioningIdForTest[F[_]](partitioning: AtumPartitions)
private case class ReaderWithPartitioningIdForTest(partitioning: AtumPartitions)
(implicit serverConfig: ServerConfig)
extends ReaderWithPartitioningId {
override def partitioningId(): Identity[RequestResult[Long]] = super.partitioningId()
extends Reader[Identity] with PartitioningIdProvider[Identity]{

override def partitioningId()(implicit monad: MonadError[Identity]): Identity[RequestResult[Long]] = super.partitioningId()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Reader_CatsIOUnitTests extends AnyFunSuiteLike {

test("Using Cats IO based backend") {
import cats.effect.IO
import za.co.absa.atum.reader.implicits.io.CatsIOMonad
import za.co.absa.atum.reader.implicits.io.catsIOMonadError

val partitionDTO = PartitionDTO("someKey", "someValue")
implicit val server: SttpBackendStub[IO, Any] = SttpBackendStub[IO, Any](implicitly[MonadAsyncError[IO]])
Expand All @@ -47,11 +47,6 @@ class Reader_CatsIOUnitTests extends AnyFunSuiteLike {
val query = reader.getQuery[PartitionDTO]("/test", Map.empty)
val result = query.unsafeRunSync()
assert(result == Right(partitionDTO))


// .map { result =>
// fail("This test is expected to fail")
// }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Reader_FutureUnitTests extends AnyFunSuiteLike {
}

test("Using Future based backend") {
import za.co.absa.atum.reader.implicits.future.FutureMonad
import za.co.absa.atum.reader.implicits.future.futureMonadError

val partitionDTO = PartitionDTO("someKey", "someValue")
implicit val server: SttpBackend[Future, Any] = SttpBackendStub.asynchronousFuture
Expand Down

0 comments on commit d04d23b

Please sign in to comment.