Skip to content

Commit

Permalink
Bump scala-lru-map to 0.5.0 (close #158)
Browse files Browse the repository at this point in the history
  • Loading branch information
istreeter committed Aug 11, 2021
1 parent 2e1a77e commit 342bf4b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 56 deletions.
16 changes: 2 additions & 14 deletions README.md
Expand Up @@ -64,22 +64,10 @@ result.ipLocation match {
}
```

`cats.Eval` and `cats.Id` are also supported:
`cats.Id` is also supported:

```scala
import cats.{Eval, Id}

val evalResult: Eval[IpLookupResult] = for {
ipLookups <- CreateIpLookups[Eval].createFromFilenames(
geoFile = Some("/opt/maxmind/GeoLite2-City.mmdb")
ispFile = None,
domainFile = None,
connectionTypeFile = None,
memCache = false,
lruCacheSize = 20000
)
lookup <- ipLookups.performLookups("175.16.199.0")
} yield lookup
import cats.Id

val idResult: IpLookupResult = {
val ipLookups = CreateIpLookups[Id].createFromFilenames(
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Expand Up @@ -16,7 +16,7 @@ object Dependencies {
val maxmind = "com.maxmind.geoip2" % "geoip2" % "2.15.0"
val catsEffect = "org.typelevel" %% "cats-effect" % "2.5.3"
val cats = "org.typelevel" %% "cats-core" % "2.6.1"
val lruMap = "com.snowplowanalytics" %% "scala-lru-map" % "0.4.0"
val lruMap = "com.snowplowanalytics" %% "scala-lru-map" % "0.5.0"
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.14.3" % Test
val specs2 = "org.specs2" %% "specs2-core" % "4.10.0" % Test
}
Expand Up @@ -14,7 +14,7 @@ package com.snowplowanalytics.maxmind.iplookups

import java.net.UnknownHostException

import cats.{Eval, Id}
import cats.Id
import cats.effect.IO
import cats.syntax.either._
import cats.syntax.option._
Expand Down Expand Up @@ -44,19 +44,6 @@ object IpLookupsTest {
)
.unsafeRunSync()

def evalIpLookupsFromFiles(memCache: Boolean, lruCache: Int): IpLookups[Eval] =
CreateIpLookups[Eval]
.createFromFilenames(
Some(geoFile),
Some(ispFile),
Some(domainFile),
Some(connectionTypeFile),
Some(anonymousFile),
memCache,
lruCache
)
.value

def idIpLookupsFromFiles(memCache: Boolean, lruCache: Int): IpLookups[Id] =
CreateIpLookups[Id]
.createFromFilenames(
Expand Down Expand Up @@ -207,28 +194,24 @@ class IpLookupsTest extends Specification with Tables {
lruCache <- Seq(0, 1000, 10000)
} {

val ioIpLookups = ioIpLookupsFromFiles(memCache, lruCache)
val evalIpLookups = evalIpLookupsFromFiles(memCache, lruCache)
val idIpLookups = idIpLookupsFromFiles(memCache, lruCache)
val ioIpLookups = ioIpLookupsFromFiles(memCache, lruCache)
val idIpLookups = idIpLookupsFromFiles(memCache, lruCache)

testData foreach {
case (ip, expected) =>
formatter(ip, memCache, lruCache) should {
val ioActual = ioIpLookups.performLookups(ip).unsafeRunSync()
val evalActual = evalIpLookups.performLookups(ip).value
val idActual = idIpLookups.performLookups(ip)
val ioActual = ioIpLookups.performLookups(ip).unsafeRunSync()
val idActual = idIpLookups.performLookups(ip)
matchIpLookupResult(ioActual, expected)
matchIpLookupResult(evalActual, expected)
matchIpLookupResult(idActual, expected)
}
}
}

// If this test fails, see https://github.com/snowplow/scala-maxmind-iplookups/issues/96
"providing an invalid ip should fail" in {
val ioIpLookups = ioIpLookupsFromFiles(true, 0)
val evalIpLookups = evalIpLookupsFromFiles(true, 0)
val idIpLookups = idIpLookupsFromFiles(true, 0)
val ioIpLookups = ioIpLookupsFromFiles(true, 0)
val idIpLookups = idIpLookupsFromFiles(true, 0)
val ioExpected = IpLookupResult(
new UnknownHostException("not: Name or service not known").asLeft.some,
new UnknownHostException("not: Name or service not known").asLeft.some,
Expand All @@ -237,14 +220,6 @@ class IpLookupsTest extends Specification with Tables {
new UnknownHostException("not: Name or service not known").asLeft.some,
new UnknownHostException("not: Name or service not known").asLeft.some
)
val evalExpected = IpLookupResult(
new UnknownHostException("not").asLeft.some,
new UnknownHostException("not").asLeft.some,
new UnknownHostException("not").asLeft.some,
new UnknownHostException("not").asLeft.some,
new UnknownHostException("not").asLeft.some,
new UnknownHostException("not").asLeft.some
)
val idExpected = IpLookupResult(
new UnknownHostException("not").asLeft.some,
new UnknownHostException("not").asLeft.some,
Expand All @@ -253,11 +228,9 @@ class IpLookupsTest extends Specification with Tables {
new UnknownHostException("not").asLeft.some,
new UnknownHostException("not").asLeft.some
)
val ioActual = ioIpLookups.performLookups("not").unsafeRunSync()
val evalActual = evalIpLookups.performLookups("not").value
val idActual = idIpLookups.performLookups("not")
val ioActual = ioIpLookups.performLookups("not").unsafeRunSync()
val idActual = idIpLookups.performLookups("not")
matchIpLookupResult(ioActual, ioExpected)
matchIpLookupResult(evalActual, evalExpected)
matchIpLookupResult(idActual, idExpected)
}

Expand All @@ -266,16 +239,11 @@ class IpLookupsTest extends Specification with Tables {
ipLookups <- CreateIpLookups[IO].createFromFiles(None, None, None, None, None, true, 0)
res <- ipLookups.performLookups("67.43.156.0")
} yield res).unsafeRunSync()
val evalActual = (for {
ipLookups <- CreateIpLookups[Eval].createFromFiles(None, None, None, None, None, true, 0)
res <- ipLookups.performLookups("67.43.156.0")
} yield res).value
val idActual = CreateIpLookups[Id]
.createFromFiles(None, None, None, None, None, true, 0)
.performLookups("67.43.156.0")
val expected = IpLookupResult(None, None, None, None, None, None)
matchIpLookupResult(ioActual, expected)
matchIpLookupResult(evalActual, expected)
matchIpLookupResult(idActual, expected)
}
}
Expand Down

0 comments on commit 342bf4b

Please sign in to comment.