-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from findify/fix/cache-leak
More tests
- Loading branch information
Showing
8 changed files
with
152 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.findify.flinkadt | ||
|
||
import cats.data.NonEmptyList | ||
import io.findify.flinkadt.AnyTest.FAny | ||
import io.findify.flinkadt.AnyTest.Filter.{FTerm, StringTerm, TermFilter} | ||
import org.apache.flink.api.common.typeinfo.TypeInformation | ||
import org.apache.flink.api.common.typeutils.TypeSerializer | ||
import org.apache.flink.core.memory.{DataInputViewStreamWrapper, DataOutputViewStreamWrapper} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import java.io.{ByteArrayInputStream, ByteArrayOutputStream} | ||
|
||
class AnyTest extends AnyFlatSpec with Matchers with TestUtils { | ||
import io.findify.flinkadt.api._ | ||
|
||
it should "serialize concrete class" in { | ||
val ser = implicitly[TypeInformation[StringTerm]].createSerializer(null) | ||
roundtrip(ser, StringTerm("fo")) | ||
} | ||
|
||
it should "serialize ADT" in { | ||
val ser = implicitly[TypeInformation[FAny]].createSerializer(null) | ||
roundtrip(ser, StringTerm("fo")) | ||
} | ||
|
||
it should "serialize NEL" in { | ||
val ser = implicitly[TypeInformation[NonEmptyList[FTerm]]].createSerializer(null) | ||
roundtrip(ser, NonEmptyList.one(StringTerm("fo"))) | ||
} | ||
|
||
it should "serialize nested nel" in { | ||
val ser = implicitly[TypeInformation[TermFilter]].createSerializer(null) | ||
roundtrip(ser, TermFilter("a", NonEmptyList.one(StringTerm("fo")))) | ||
} | ||
|
||
} | ||
|
||
object AnyTest { | ||
sealed trait FAny | ||
|
||
sealed trait FValueAny extends FAny { | ||
def value: Any | ||
} | ||
object Filter { | ||
sealed trait FTerm extends FValueAny | ||
case class StringTerm(value: String) extends FTerm { | ||
type T = String | ||
} | ||
case class NumericTerm(value: Double) extends FTerm { | ||
type T = Double | ||
} | ||
|
||
case class TermFilter( | ||
field: String, | ||
values: NonEmptyList[FTerm] | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.findify.flinkadt | ||
|
||
import cats.data.NonEmptyList | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class CatsTest extends AnyFlatSpec with Matchers with TestUtils { | ||
import io.findify.flinkadt.api._ | ||
it should "derive for NEL[String]" in { | ||
val ser = deriveTypeInformation[NonEmptyList[String]].createSerializer(null) | ||
roundtrip(ser, NonEmptyList.one("doo")) | ||
} | ||
it should "derive for NEL[Int]" in { | ||
val ser = deriveTypeInformation[NonEmptyList[Int]].createSerializer(null) | ||
roundtrip(ser, NonEmptyList.one(1)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.findify.flinkadt | ||
|
||
import org.apache.flink.api.common.typeutils.TypeSerializer | ||
import org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer | ||
import org.apache.flink.api.scala.typeutils.ScalaCaseClassSerializer | ||
import org.apache.flink.core.memory.{DataInputViewStreamWrapper, DataOutputViewStreamWrapper} | ||
import org.scalatest.{Inspectors, Suite} | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream} | ||
|
||
trait TestUtils extends Matchers with Inspectors { | ||
def roundtrip[T](ser: TypeSerializer[T], in: T) = { | ||
val out = new ByteArrayOutputStream() | ||
ser.serialize(in, new DataOutputViewStreamWrapper(out)) | ||
val copy = ser.deserialize(new DataInputViewStreamWrapper(new ByteArrayInputStream(out.toByteArray))) | ||
in shouldBe copy | ||
} | ||
|
||
def noKryo[T](ser: TypeSerializer[T]): Unit = | ||
ser match { | ||
case p: ScalaCaseClassSerializer[_] => | ||
forAll(p.getFieldSerializers) { param => | ||
noKryo(param) | ||
} | ||
case _: KryoSerializer[_] => | ||
throw new IllegalArgumentException("kryo detected") | ||
case _ => // ok | ||
} | ||
|
||
def serializable[T](ser: TypeSerializer[T]) = { | ||
val stream = new ObjectOutputStream(new ByteArrayOutputStream()) | ||
stream.writeObject(ser) | ||
} | ||
|
||
def all[T](ser: TypeSerializer[T], in: T) = { | ||
roundtrip(ser, in) | ||
noKryo(ser) | ||
serializable(ser) | ||
} | ||
|
||
} |