diff --git a/build.sbt b/build.sbt index 302600c..87ba701 100644 --- a/build.sbt +++ b/build.sbt @@ -53,12 +53,12 @@ lazy val scassandra = (project in file("scassandra")) ) ) .settings( - libraryDependencies ++= List(Pureconfig.pureconfig) - // libraryDependencies ++= crossSettings( - // scalaVersion.value, - // if3 = List(Pureconfig.core), - // if2 = List(Pureconfig.pureconfig), - // ) + libraryDependencies ++= List(Pureconfig.pureconfig), + libraryDependencies ++= crossSettings( + scalaVersion.value, + if3 = List(Pureconfig.core), + if2 = List(Pureconfig.pureconfig), + ) ) lazy val tests = (project in file("tests")) diff --git a/scassandra/src/main/scala/com/evolutiongaming/scassandra/AuthenticationConfigImplicits.scala b/scassandra/src/main/scala/com/evolutiongaming/scassandra/AuthenticationConfigImplicits.scala index 133e22e..cd398bd 100644 --- a/scassandra/src/main/scala/com/evolutiongaming/scassandra/AuthenticationConfigImplicits.scala +++ b/scassandra/src/main/scala/com/evolutiongaming/scassandra/AuthenticationConfigImplicits.scala @@ -1,8 +1,8 @@ package com.evolutiongaming.scassandra import pureconfig.ConfigReader -import pureconfig.generic.semiauto.deriveReader trait AuthenticationConfigImplicits { - implicit val configReaderAuthenticationConfig: ConfigReader[AuthenticationConfig] = deriveReader + implicit val configReaderAuthenticationConfig: ConfigReader[AuthenticationConfig] = + ConfigReader.forProduct2[AuthenticationConfig, String, Masked[String]]("username", "password")(AuthenticationConfig.apply) } diff --git a/scassandra/src/main/scala/com/evolutiongaming/scassandra/LoadBalancingConfigImplicits.scala b/scassandra/src/main/scala/com/evolutiongaming/scassandra/LoadBalancingConfigImplicits.scala index 4885c50..29103f4 100644 --- a/scassandra/src/main/scala/com/evolutiongaming/scassandra/LoadBalancingConfigImplicits.scala +++ b/scassandra/src/main/scala/com/evolutiongaming/scassandra/LoadBalancingConfigImplicits.scala @@ -1,8 +1,16 @@ package com.evolutiongaming.scassandra import pureconfig.ConfigReader -import pureconfig.generic.semiauto.deriveReader trait LoadBalancingConfigImplicits { - implicit val configReaderLoadBalancingConfig: ConfigReader[LoadBalancingConfig] = deriveReader + implicit val configReaderLoadBalancingConfig: ConfigReader[LoadBalancingConfig] = + ConfigReader.forProduct2[LoadBalancingConfig, Option[String], Option[Boolean]]("local-dc", "allow-remote-dcs-for-local-consistency-level") { + (localDc, allowRemoteDcsForLocalConsistencyLevel) => + val defaultConfig = LoadBalancingConfig() + + LoadBalancingConfig( + localDc.getOrElse(defaultConfig.localDc), + allowRemoteDcsForLocalConsistencyLevel.getOrElse(defaultConfig.allowRemoteDcsForLocalConsistencyLevel) + ) + } } \ No newline at end of file diff --git a/scassandra/src/main/scala/com/evolutiongaming/scassandra/QueryConfigImplicits.scala b/scassandra/src/main/scala/com/evolutiongaming/scassandra/QueryConfigImplicits.scala index 3c1a9d7..d6aad8d 100644 --- a/scassandra/src/main/scala/com/evolutiongaming/scassandra/QueryConfigImplicits.scala +++ b/scassandra/src/main/scala/com/evolutiongaming/scassandra/QueryConfigImplicits.scala @@ -3,10 +3,60 @@ package com.evolutiongaming.scassandra import com.datastax.driver.core.ConsistencyLevel import com.evolutiongaming.scassandra.util.ConfigReaderFromEnum import pureconfig.ConfigReader -import pureconfig.generic.semiauto.deriveReader + +import scala.concurrent.duration._ trait QueryConfigImplicits { implicit val configReaderConsistencyLevel: ConfigReader[ConsistencyLevel] = ConfigReaderFromEnum(ConsistencyLevel.values()) - implicit val configReaderQueryConfig: ConfigReader[QueryConfig] = deriveReader + implicit val configReaderQueryConfig: ConfigReader[QueryConfig] = + ConfigReader.forProduct13[ + QueryConfig, + Option[ConsistencyLevel], + Option[ConsistencyLevel], + Option[Int], + Option[Boolean], + Option[Int], + Option[Int], + Option[Int], + Option[FiniteDuration], + Option[FiniteDuration], + Option[FiniteDuration], + Option[Boolean], + Option[Boolean], + Option[Boolean] + ]( + "consistency", + "serial-consistency", + "fetch-size", + "default-idempotence", + "max-pending-refresh-node-list-requests", + "max-pending-refresh-node-requests", + "max-pending-refresh-schema-requests", + "refresh-node-list-interval", + "refresh-node-interval", + "refresh-schema-interval", + "metadata", + "re-prepare-on-up", + "prepare-on-all-hosts" + ) { (consistency, serialConsistency, fetchSize, defaultIdempotence, maxPendingRefreshNodeListRequests, maxPendingRefreshNodeRequests, maxPendingRefreshSchemaRequests, refreshNodeListInterval, refreshNodeInterval, refreshSchemaInterval, metadata, rePrepareOnUp, prepareOnAllHosts) => + val defaultConfig = QueryConfig() + + QueryConfig( + consistency.getOrElse(defaultConfig.consistency), + serialConsistency.getOrElse(defaultConfig.serialConsistency), + fetchSize.getOrElse(defaultConfig.fetchSize), + defaultIdempotence.getOrElse(defaultConfig.defaultIdempotence), + maxPendingRefreshNodeListRequests.getOrElse(defaultConfig.maxPendingRefreshNodeListRequests), + maxPendingRefreshNodeRequests.getOrElse(defaultConfig.maxPendingRefreshNodeRequests), + maxPendingRefreshSchemaRequests.getOrElse(defaultConfig.maxPendingRefreshSchemaRequests), + refreshNodeListInterval.getOrElse(defaultConfig.refreshNodeListInterval), + refreshNodeInterval.getOrElse(defaultConfig.refreshNodeInterval), + refreshSchemaInterval.getOrElse(defaultConfig.refreshSchemaInterval), + metadata.getOrElse(defaultConfig.metadata), + rePrepareOnUp.getOrElse(defaultConfig.rePrepareOnUp), + prepareOnAllHosts.getOrElse(defaultConfig.prepareOnAllHosts) + ) + } + } diff --git a/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReconnectionConfigImplicits.scala b/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReconnectionConfigImplicits.scala index dd62906..48051ec 100644 --- a/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReconnectionConfigImplicits.scala +++ b/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReconnectionConfigImplicits.scala @@ -1,8 +1,17 @@ package com.evolutiongaming.scassandra import pureconfig.ConfigReader -import pureconfig.generic.semiauto.deriveReader +import scala.concurrent.duration.FiniteDuration trait ReconnectionConfigImplicits { - implicit val configReaderReconnectionConfig: ConfigReader[ReconnectionConfig] = deriveReader + implicit val configReaderReconnectionConfig: ConfigReader[ReconnectionConfig] = + ConfigReader.forProduct2[ReconnectionConfig, Option[FiniteDuration], Option[FiniteDuration]]("min-delay", "max-delay") { + (minDelay, maxDelay) => + val defaultConfig = ReconnectionConfig() + + ReconnectionConfig( + minDelay.getOrElse(defaultConfig.minDelay), + maxDelay.getOrElse(defaultConfig.maxDelay) + ) + } } diff --git a/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReplicationStrategyConfigImplicits.scala b/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReplicationStrategyConfigImplicits.scala index 15805b4..da3fafb 100644 --- a/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReplicationStrategyConfigImplicits.scala +++ b/scassandra/src/main/scala/com/evolutiongaming/scassandra/ReplicationStrategyConfigImplicits.scala @@ -1,9 +1,13 @@ package com.evolutiongaming.scassandra import pureconfig.ConfigReader -import pureconfig.generic.semiauto.deriveReader import com.evolutiongaming.scassandra.ReplicationStrategyConfig.* trait ReplicationStrategyConfigImplicits { - implicit val configReaderSimple: ConfigReader[Simple] = deriveReader + implicit val configReaderSimple: ConfigReader[Simple] = + ConfigReader.forProduct1[Simple, Option[Int]]("replication-factor") { replicationFactor => + val defaultConfig = Simple() + + Simple(replicationFactor.getOrElse(defaultConfig.replicationFactor)) + } } diff --git a/scassandra/src/main/scala/com/evolutiongaming/scassandra/SocketConfigImplicits.scala b/scassandra/src/main/scala/com/evolutiongaming/scassandra/SocketConfigImplicits.scala index 56d2a28..8eecf3d 100644 --- a/scassandra/src/main/scala/com/evolutiongaming/scassandra/SocketConfigImplicits.scala +++ b/scassandra/src/main/scala/com/evolutiongaming/scassandra/SocketConfigImplicits.scala @@ -1,8 +1,41 @@ package com.evolutiongaming.scassandra import pureconfig.ConfigReader -import pureconfig.generic.semiauto.deriveReader +import scala.concurrent.duration.FiniteDuration trait SocketConfigImplicits { - implicit val configReaderSocketConfig: ConfigReader[SocketConfig] = deriveReader + implicit val configReaderSocketConfig: ConfigReader[SocketConfig] = + ConfigReader.forProduct8[ + SocketConfig, + Option[FiniteDuration], + Option[FiniteDuration], + Option[Boolean], + Option[Boolean], + Option[Int], + Option[Boolean], + Option[Int], + Option[Int] + ]( + "connect-timeout", + "read-timeout", + "keep-alive", + "reuse-address", + "so-linger", + "tcp-no-delay", + "receive-buffer-size", + "send-buffer-size", + ) { (connectTimeout, readTimeout, keepAlive, reuseAddress, soLinger, tcpNoDelay, receiveBufferSize, sendBufferSize) => + val defaultConfig = SocketConfig() + + SocketConfig( + connectTimeout.getOrElse(defaultConfig.connectTimeout), + readTimeout.getOrElse(defaultConfig.readTimeout), + keepAlive.orElse(defaultConfig.keepAlive), + reuseAddress.orElse(defaultConfig.reuseAddress), + soLinger.orElse(defaultConfig.soLinger), + tcpNoDelay.orElse(defaultConfig.tcpNoDelay), + receiveBufferSize.orElse(defaultConfig.receiveBufferSize), + sendBufferSize.orElse(defaultConfig.sendBufferSize) + ) + } } diff --git a/scassandra/src/main/scala/com/evolutiongaming/scassandra/SpeculativeConfigImplicits.scala b/scassandra/src/main/scala/com/evolutiongaming/scassandra/SpeculativeConfigImplicits.scala index ea2f1a4..c9ec18b 100644 --- a/scassandra/src/main/scala/com/evolutiongaming/scassandra/SpeculativeConfigImplicits.scala +++ b/scassandra/src/main/scala/com/evolutiongaming/scassandra/SpeculativeConfigImplicits.scala @@ -1,8 +1,17 @@ package com.evolutiongaming.scassandra import pureconfig.ConfigReader -import pureconfig.generic.semiauto.deriveReader +import scala.concurrent.duration.FiniteDuration trait SpeculativeConfigImplicits { - implicit val configReaderSpeculativeExecutionConfig: ConfigReader[SpeculativeExecutionConfig] = deriveReader + implicit val configReaderSpeculativeExecutionConfig: ConfigReader[SpeculativeExecutionConfig] = + ConfigReader.forProduct2[SpeculativeExecutionConfig, Option[FiniteDuration], Option[Int]]("delay", "max-executions") { + (delay, maxExecutions) => + val defaultConfig = SpeculativeExecutionConfig() + + SpeculativeExecutionConfig( + delay.getOrElse(defaultConfig.delay), + maxExecutions.getOrElse(defaultConfig.maxExecutions) + ) + } }