Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a module for finagle bijections. #197

Merged
merged 2 commits into from
Feb 23, 2015
Merged

Conversation

folone
Copy link
Contributor

@folone folone commented Feb 20, 2015

As suggested in twitter/finagle#341, implemented Bijections and Injections for finagle-mysql datatypes.

/cc @mosesn @fwbrasil @williamboxhall

> bijection-finagle/console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_20).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import com.twitter.finagle.exp.mysql._
import com.twitter.finagle.exp.mysql._

scala> import com.twitter.bijection.Conversion.asMethod
import com.twitter.bijection.Conversion.asMethod

scala> import com.twitter.bijection.twitter_finagle.MySqlConversions._
import com.twitter.bijection.twitter_finagle.MySqlConversions._

scala> NullValue.as[Option[String]]
res1: Option[String] = None

scala> StringValue("Hej").as[String]
res2: String = Hej

scala> IntValue(10).as[Option[Int]]
res3: Option[Int] = Some(10)

@mosesn
Copy link
Contributor

mosesn commented Feb 20, 2015

@johnynek @folone is this the right place to put this? I was thinking that it would be OK to just make finagle-mysql take a dependency on bijections, but I don't have really strong opinions about this. Although it might make more sense to make this a bijection-finagle-mysql lib than bijection-finagle.

limitations under the License.
*/

package com.twitter.bijection.twitter_finagle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

twitter_finagle? are there other finagle projects? should drop the twitter_

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, also note the com.twitter prefix.

@johnynek
Copy link
Collaborator

This looks great, aside from a few minor suggestions. Thanks so much for doing this!

@folone
Copy link
Contributor Author

folone commented Feb 22, 2015

Addressed the review in 55b7e8b.

@mosesn
Copy link
Contributor

mosesn commented Feb 22, 2015

LGTM

private val UTC = java.util.TimeZone.getTimeZone("UTC")
private val timestampValue = new TimestampValue(UTC, UTC)
def apply(t: Timestamp) = timestampValue(t)
override def invert(v: Value) = Inversion.attempt(timestampValue.unapply(v).get)(identity)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not how attempt works. Yours will throw if the inversion fails. It should be:

Inversion.attempt(v) { v => timestampValue.unapply(v).get }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Thanks, fixed!

@johnynek
Copy link
Collaborator

one minor issue.

@johnynek
Copy link
Collaborator

Thanks!

johnynek added a commit that referenced this pull request Feb 23, 2015
Add a module for finagle bijections.
@johnynek johnynek merged commit 3162abc into twitter:develop Feb 23, 2015
@folone
Copy link
Contributor Author

folone commented Feb 23, 2015

YES

@folone folone deleted the finagle-mysql branch February 23, 2015 19:42
@folone
Copy link
Contributor Author

folone commented Feb 23, 2015

Thanks!

@MansurAshraf
Copy link
Contributor

@folone your tests are failing. Instead of extending PropertyChecks can you extend CheckProperties from #198 and rerun your tests?

[info] Compiling 1 Scala source to bijection/bijection-finagle-mysql/target/scala-2.10/test-classes...
[info] MySqlConversionLaws:
[info] - Byte
[info] - Short
[info] - Int
[info] - Long
[info] - Float
[info] - Double
[info] - String
[info] - Boolean *** FAILED ***
[info]   GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info]    (CheckProperties.scala:12)
[info]     Falsified after 0 successful property evaluations.
[info]     Location: (CheckProperties.scala:12)
[info]     Occurred when passed generated values (
[info]       arg0 = ByteValue(127)
[info]     )
[info] - Timestamp *** FAILED ***
[info]   GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info]    (CheckProperties.scala:12)
[info]     Falsified after 0 successful property evaluations.
[info]     Location: (CheckProperties.scala:12)
[info]     Occurred when passed generated values (
[info]       arg0 = 24501659-11-03 14:26:24.675
[info]     )
[info] - Empty *** FAILED ***
[info]   GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info]    (CheckProperties.scala:12)
[info]     Falsified after 0 successful property evaluations.
[info]     Location: (CheckProperties.scala:12)
[info]     Occurred when passed generated values (
[info]       arg0 = EmptyValue
[info]     )
[info] - Null *** FAILED ***
[info]   GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info]    (CheckProperties.scala:12)
[info]     Falsified after 0 successful property evaluations.
[info]     Location: (CheckProperties.scala:12)
[info]     Occurred when passed generated values (
[info]       arg0 = NullValue
[info]     )
[info] ScalaTest
[info] Run completed in 635 milliseconds.
[info] Total number of tests run: 11
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 7, failed 4, canceled 0, ignored 0, pending 0
[info] *** 4 TESTS FAILED ***

@folone
Copy link
Contributor Author

folone commented Feb 23, 2015

@MansurAshraf I believe @johnynek already merged this PR though. Should I send another one against your branch?

@MansurAshraf
Copy link
Contributor

@folone yes thats fine. Thank you!

@folone
Copy link
Contributor Author

folone commented Feb 24, 2015

@MansurAshraf I just tried extending CheckProperties, same errors. Here's the diff:

Compiling garden.css...
diff --git a/bijection-finagle-mysql/src/test/scala/com/twitter/bijection/finagle_mysql/MySqlConversionLaws.scala b/bijection-finagle-mysql/src/test/scala/com/twitter/bijection/finagle_mysql/MySqlConversionLaws.scala
index 7328abd..ffc64f7 100644
--- a/bijection-finagle-mysql/src/test/scala/com/twitter/bijection/finagle_mysql/MySqlConversionLaws.scala
+++ b/bijection-finagle-mysql/src/test/scala/com/twitter/bijection/finagle_mysql/MySqlConversionLaws.scala
@@ -18,8 +18,6 @@ package com.twitter.bijection.finagle_mysql

 import com.twitter.bijection.{ CheckProperties, BaseProperties, Bijection }
 import org.scalacheck.Arbitrary
-import org.scalatest.{ PropSpec, MustMatchers }
-import org.scalatest.prop.PropertyChecks
 import com.twitter.finagle.exp.mysql._
 import java.sql.Timestamp
 import java.util.Date
@@ -29,7 +27,7 @@ import org.scalacheck.Gen
 import org.scalacheck.Arbitrary
 import org.scalacheck.Arbitrary.arbitrary

-class MySqlConversionLaws extends PropSpec with PropertyChecks with MustMatchers with BaseProperties {
+class MySqlConversionLaws extends CheckProperties with BaseProperties {
   import MySqlConversions._

   implicit val byteValueArb = Arbitrary(arbitrary[Byte].map(ByteValue.apply))

@MansurAshraf
Copy link
Contributor

@folone are these valid test failures? Do you think you can fix them otherwise we will have to revert the change. @johnynek what do you think?

@folone
Copy link
Contributor Author

folone commented Feb 25, 2015

@MansurAshraf I'll have some time to look at it on Friday. I'm wondering how those tests were working before #198 though.

@MansurAshraf
Copy link
Contributor

@folone they were not running. See twitter/algebird#421 (its for algebird but same issue was happening in this project)

@johnynek
Copy link
Collaborator

@MansurAshraf is right. I missed that in the review. We had a bug in some our tests after the migration to scalatest, and your code copied that pattern.

@folone
Copy link
Contributor Author

folone commented Feb 26, 2015

Here's the fix: #201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants