Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Jan 18, 2025
1 parent 4ed8b89 commit 6340c11
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ sealed private[optics] trait PathPart {
}
final private[optics] case class Field(name: String) extends PathPart
final private[optics] case class Index(index: Int) extends PathPart
final private[optics] case object Traverse extends PathPart
private[optics] case object Traverse extends PathPart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import oolong.bson.*
import oolong.bson.given
import org.mongodb.scala.MongoClient.DEFAULT_CODEC_REGISTRY
import org.mongodb.scala.MongoCollection
import org.mongodb.scala.Observer
import org.mongodb.scala.SingleObservableFuture
import org.mongodb.scala.bson.*
import org.mongodb.scala.bson.conversions.Bson
import org.mongodb.scala.model.IndexOptions
import org.mongodb.scala.model.changestream.*

import ru.tinkoff.tcb.bson.PatchGenerator
import ru.tinkoff.tcb.dataaccess.UpdateResult
Expand Down Expand Up @@ -168,33 +166,6 @@ abstract class DAOBase[T: BsonDecoder: BsonEncoder](
insert(create).map(UpdateResult(0, _))
}

override def subscribe(consumer: ChangeStreamDocument[T] => Unit): Unit =
collection
.watch()
.fullDocument(FullDocument.UPDATE_LOOKUP)
.subscribe(new Observer[ChangeStreamDocument[BsonDocument]] {
override def onNext(result: ChangeStreamDocument[BsonDocument]): Unit =
consumer(
new ChangeStreamDocument[T](
result.getOperationType,
result.getResumeToken,
result.getNamespaceDocument,
result.getDestinationNamespaceDocument,
BsonDecoder[T].fromBson(result.getFullDocument).get,
result.getDocumentKey,
result.getClusterTime,
result.getUpdateDescription,
result.getTxnNumber,
result.getLsid
)
)

override def onError(e: Throwable): Unit =
subscribe(consumer)

override def onComplete(): Unit = ()
})

override def createIndex(defn: Sort, options: IndexOptions): Task[Unit] =
ZIO.fromFuture(implicit ec => collection.createIndex(defn, options).head()).unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import oolong.bson.given
import org.mongodb.scala.bson.Document
import org.mongodb.scala.bson.conversions.Bson
import org.mongodb.scala.model.IndexOptions
import org.mongodb.scala.model.changestream.ChangeStreamDocument

import ru.tinkoff.tcb.dataaccess.DAO
import ru.tinkoff.tcb.dataaccess.UpdateResult
Expand Down Expand Up @@ -53,8 +52,6 @@ trait MongoDAO[F[_], T] extends DAO[F, T] {
ps: PropSubset[P, T]
): F[UpdateResult]

def subscribe(consumer: ChangeStreamDocument[T] => Unit): Unit

def createIndex(fields: Sort, options: IndexOptions = IndexOptions()): F[Unit]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.net.http.HttpClient
import java.security.SecureRandom
import javax.net.ssl.KeyManagerFactory
import javax.net.ssl.SSLContext
import scala.annotation.nowarn
import scala.jdk.DurationConverters.*

import com.mongodb.ConnectionString
Expand Down Expand Up @@ -213,6 +214,7 @@ object Mockingbird {
_ = builder.build().start()
} yield ()

@nowarn("name=ValueDiscarding")
def main(args: Array[String]): Unit =
Unsafe.unsafe { implicit us =>
wldRuntime.unsafe.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.security.cert.X509Certificate
import javax.net.ssl.SSLEngine
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509ExtendedTrustManager
import scala.annotation.nowarn
import scala.util.boundary

/*
Rewritten from https://github.com/line/armeria/blob/main/core/src/main/java/com/linecorp/armeria/client/IgnoreHostsTrustManager.java
Expand Down Expand Up @@ -48,15 +48,15 @@ class TrustSomeHostsManager(delegate: X509ExtendedTrustManager, insecureHosts: S
}

object TrustSomeHostsManager {
@nowarn("cat=lint-nonlocal-return")
def of(insecureHosts: Set[String]): TrustSomeHostsManager = {
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
trustManagerFactory.init(null.asInstanceOf[KeyStore])
val trustManagers = trustManagerFactory.getTrustManagers
for (tm <- trustManagers)
if (tm.isInstanceOf[X509ExtendedTrustManager])
return new TrustSomeHostsManager(tm.asInstanceOf[X509ExtendedTrustManager], insecureHosts)

throw new NoSuchElementException("cannot resolve default trust manager")
}
def of(insecureHosts: Set[String]): TrustSomeHostsManager =
boundary {
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
trustManagerFactory.init(null.asInstanceOf[KeyStore])
val trustManagers = trustManagerFactory.getTrustManagers
for (tm <- trustManagers)
if (tm.isInstanceOf[X509ExtendedTrustManager])
boundary.break(new TrustSomeHostsManager(tm.asInstanceOf[X509ExtendedTrustManager], insecureHosts))

throw new NoSuchElementException("cannot resolve default trust manager")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ sealed trait HttpStubRequest derives BsonDecoder, BsonEncoder {

def checkHeaders(hs: Map[String, String]): Boolean =
headers.forall { case (k, v) =>
hs.exists {
case (kx, vx) => k.toLowerCase == kx.toLowerCase && v == vx
case _ => false
hs.exists { case (kx, vx) =>
k.toLowerCase == kx.toLowerCase && v == vx
}
}

Expand Down Expand Up @@ -235,9 +234,8 @@ sealed trait RequestPart derives BsonDecoder, BsonEncoder {

def checkHeaders(hs: Map[String, String]): Boolean =
headers.forall { case (k, v) =>
hs.exists {
case (kx, vx) => k.toLowerCase == kx.toLowerCase && v == vx
case _ => false
hs.exists { case (kx, vx) =>
k.toLowerCase == kx.toLowerCase && v == vx
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object Settings {
"-Yretain-trees", //for accessing default values by magnolia
prelude(), // standart imports + zio
// warning settings
//"-Wconf:any:wv", // shows warning categories for nowarn (https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html)
"-Wconf:any:v", // shows warning categories for nowarn (https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html)
"-Wunused:imports",
"-Wunused:privates",
"-Wvalue-discard"
Expand Down

0 comments on commit 6340c11

Please sign in to comment.