diff --git a/build.sbt b/build.sbt index 70e37a534..d8fde9863 100644 --- a/build.sbt +++ b/build.sbt @@ -123,7 +123,6 @@ val sharedSettings: Seq[Def.Setting[_]] = Defaults.coreDefaultSettings ++ Seq( ), envVars := Map("SCALACTIC_FILL_FILE_PATHNAMES" -> "yes"), gitTagName in ThisBuild := s"version=${scalaVersion.value}", - testFrameworks in Test ++= Seq(new TestFramework("org.scalameter.ScalaMeterFramework")), parallelExecution in ThisBuild := false ) ++ VersionManagement.newSettings ++ GitProject.gitSettings ++ @@ -212,6 +211,7 @@ lazy val phantomFinagle = (project in file("phantom-finagle")) name := "phantom-finagle", moduleName := "phantom-finagle", crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.1"), + testFrameworks in Test ++= Seq(new TestFramework("org.scalameter.ScalaMeterFramework")), libraryDependencies ++= Seq( "com.twitter" %% "util-core" % Versions.twitterUtil(scalaVersion.value), "com.outworkers" %% "util-testing" % Versions.util % Test, @@ -266,6 +266,7 @@ lazy val phantomStreams = (project in file("phantom-streams")) .settings( name := "phantom-streams", moduleName := "phantom-streams", + testFrameworks in Test ++= Seq(new TestFramework("org.scalameter.ScalaMeterFramework")), crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.1"), libraryDependencies ++= Seq( "com.typesafe" % "config" % Versions.typesafeConfig force(), diff --git a/phantom-dsl/src/main/scala/com/outworkers/phantom/builder/query/CassandraOperations.scala b/phantom-dsl/src/main/scala/com/outworkers/phantom/builder/query/CassandraOperations.scala index 79581c4f9..35722dd40 100644 --- a/phantom-dsl/src/main/scala/com/outworkers/phantom/builder/query/CassandraOperations.scala +++ b/phantom-dsl/src/main/scala/com/outworkers/phantom/builder/query/CassandraOperations.scala @@ -31,32 +31,6 @@ private[phantom] trait CassandraOperations extends SessionAugmenterImplicits { scalaQueryStringToPromise(st).future } - protected[this] def preparedStatementToPromise(st: String)( - implicit session: Session, - executor: ExecutionContextExecutor - ): ScalaPromise[PreparedStatement] = { - Manager.logger.debug(s"Executing prepared statement: ${st.toString}") - - val promise = ScalaPromise[PreparedStatement]() - - val future = session.prepareAsync(st) - - val callback = new FutureCallback[PreparedStatement] { - def onSuccess(result: PreparedStatement): Unit = { - promise success result - } - - def onFailure(err: Throwable): Unit = { - Manager.logger.error(err.getMessage) - promise failure err - } - } - - Futures.addCallback(future, callback, executor) - promise - } - - protected[this] def scalaQueryStringToPromise(st: Statement)( implicit session: Session, executor: ExecutionContextExecutor diff --git a/phantom-dsl/src/main/scala/com/outworkers/phantom/column/MapColumn.scala b/phantom-dsl/src/main/scala/com/outworkers/phantom/column/MapColumn.scala index 56815656b..30160f43d 100644 --- a/phantom-dsl/src/main/scala/com/outworkers/phantom/column/MapColumn.scala +++ b/phantom-dsl/src/main/scala/com/outworkers/phantom/column/MapColumn.scala @@ -60,7 +60,7 @@ class MapColumn[ implicit ev: Primitive[Map[K, V]], keyPrimitive: Primitive[K], val valuePrimitive: Primitive[V] -) extends AbstractMapColumn[Owner, Record, K, V](table) with PrimitiveCollectionValue[V] { +) extends AbstractMapColumn[Owner, Record, K, V](table) { override def keyAsCql(v: K): String = keyPrimitive.asCql(v) diff --git a/phantom-dsl/src/main/scala/com/outworkers/phantom/column/PrimitiveCollectionValue.scala b/phantom-dsl/src/main/scala/com/outworkers/phantom/column/PrimitiveCollectionValue.scala deleted file mode 100644 index b5175ab4b..000000000 --- a/phantom-dsl/src/main/scala/com/outworkers/phantom/column/PrimitiveCollectionValue.scala +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2013 - 2017 Outworkers Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.outworkers.phantom.column - -import com.outworkers.phantom.builder.primitives.Primitive - - -trait PrimitiveCollectionValue[R] extends CollectionValueDefinition[R] { - - def valuePrimitive: Primitive[R] - - def valueAsCql(v: R): String = valuePrimitive.asCql(v) -} diff --git a/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/Jdk8TimeuuidConvertTests.scala b/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/Jdk8TimeuuidConvertTests.scala index a397a65ad..f929b8965 100644 --- a/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/Jdk8TimeuuidConvertTests.scala +++ b/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/Jdk8TimeuuidConvertTests.scala @@ -15,37 +15,16 @@ */ package com.outworkers.phantom.jdk8 -import java.time.{Instant, OffsetDateTime, ZoneId, ZonedDateTime} -import org.scalacheck.Gen import org.scalatest.prop.GeneratorDrivenPropertyChecks import org.scalatest.{FlatSpec, Matchers} -import scala.collection.JavaConverters._ +import com.outworkers.phantom.jdk8.tables._ class Jdk8TimeuuidConvertTests extends FlatSpec with Matchers with GeneratorDrivenPropertyChecks { - private[this] val genLower: Int = -100000 - private[this] val genHigher: Int = -genLower - implicit override val generatorDrivenConfig: PropertyCheckConfiguration = { PropertyCheckConfiguration(minSuccessful = 300) } - val zoneIdGen: Gen[ZoneId] = Gen.oneOf(ZoneId.getAvailableZoneIds.asScala.toSeq) map ZoneId.of - - val zonedDateTimeGen: Gen[ZonedDateTime] = for { - offset <- Gen.choose(genLower, genHigher) - time = Instant.now().toEpochMilli - dt = time + offset - zone <- zoneIdGen - } yield ZonedDateTime.ofInstant(Instant.ofEpochMilli(dt), zone) - - val offsetDateTimeGen: Gen[OffsetDateTime] = for { - offset <- Gen.choose(genLower, genHigher) - time = Instant.now().toEpochMilli - dt = time + offset - zone <- zoneIdGen - } yield OffsetDateTime.ofInstant(Instant.ofEpochMilli(dt), zone) - it should "convert a ZonedDateTime to a Timeuuid and back using the ZoneID argument method" in { forAll(zonedDateTimeGen) { dt => dt.timeuuid.zonedDateTime(dt.getZone) shouldEqual dt diff --git a/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/indexed/IndexedRoundtripTests.scala b/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/indexed/IndexedRoundtripTests.scala new file mode 100644 index 000000000..974ffca51 --- /dev/null +++ b/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/indexed/IndexedRoundtripTests.scala @@ -0,0 +1,57 @@ +/* + * Copyright 2013 - 2017 Outworkers Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.outworkers.phantom.jdk8.indexed + +import java.time.ZoneOffset + +import com.outworkers.phantom.builder.primitives.Primitive +import com.outworkers.phantom.jdk8.tables._ +import org.scalacheck.Gen +import org.scalatest.prop.GeneratorDrivenPropertyChecks +import org.scalatest.{Assertion, FlatSpec, Matchers} + +class IndexedRoundtripTests extends FlatSpec with Matchers with GeneratorDrivenPropertyChecks { + + private[this] val genLower: Int = -100000 + private[this] val genHigher: Int = -genLower + + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = { + PropertyCheckConfiguration(minSuccessful = 300) + } + + + def roundtrip[T](gen: Gen[T])(fn: T => T)(implicit ev: Primitive[T]): Assertion = { + forAll(gen, protocolGen) { (sample, version) => + ev.deserialize(ev.serialize(sample, version), version) shouldEqual fn(sample) + } + } + + it should "serialize and deserialize ZonedDateTime instances using indexed primitives" in { + roundtrip(zonedDateTimeGen)(_.withZoneSameInstant(ZoneOffset.UTC)) + } + + it should "serialize and deserialize OffsetDateTime instances using indexed primitives" in { + roundtrip(offsetDateTimeGen)(_.withOffsetSameInstant(ZoneOffset.UTC)) + } + + it should "serialize and deserialize LocalDate instances using indexed primitives" in { + roundtrip(localDateGen)(identity) + } + + it should "serialize and deserialize LocalDateTime instances using indexed primitives" in { + roundtrip(localDateTimeGen)(identity) + } +} \ No newline at end of file diff --git a/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/tables/package.scala b/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/tables/package.scala index 07b139483..35c6ae912 100644 --- a/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/tables/package.scala +++ b/phantom-jdk8/src/test/scala/com/outworkers/phantom/jdk8/tables/package.scala @@ -17,14 +17,43 @@ package com.outworkers.phantom.jdk8 import java.time._ +import com.datastax.driver.core.ProtocolVersion import com.outworkers.util.samplers._ -import org.scalacheck.Arbitrary +import org.scalacheck.{Arbitrary, Gen} import scala.collection.JavaConverters._ import scala.util.Random package object tables { + private[this] val genLower: Int = -100000 + private[this] val genHigher: Int = -genLower + + val protocolGen: Gen[ProtocolVersion] = Gen.oneOf(ProtocolVersion.values()) + + val zoneIdGen: Gen[ZoneId] = Gen.oneOf(ZoneId.getAvailableZoneIds.asScala.toSeq) map ZoneId.of + + val zonedDateTimeGen: Gen[ZonedDateTime] = for { + offset <- Gen.choose(genLower, genHigher) + time = Instant.now().toEpochMilli + dt = time + offset + zone <- zoneIdGen + } yield ZonedDateTime.ofInstant(Instant.ofEpochMilli(dt), zone) + + + val localDateGen: Gen[LocalDate] = zonedDateTimeGen.map(_.toLocalDate) + + val localDateTimeGen: Gen[LocalDateTime] = zonedDateTimeGen.map(_.toLocalDateTime) + + + val offsetDateTimeGen: Gen[OffsetDateTime] = for { + offset <- Gen.choose(genLower, genHigher) + time = Instant.now().toEpochMilli + dt = time + offset + zone <- zoneIdGen + } yield OffsetDateTime.ofInstant(Instant.ofEpochMilli(dt), zone) + + implicit object ZoneIdSampler extends Sample[ZoneId] { override def sample: ZoneId = ZoneId.of(Generators.oneOf(ZoneId.getAvailableZoneIds.asScala.toSeq)) }