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

Added support for JDBC testing in ServiceTest #1179

Merged
merged 5 commits into from Jan 15, 2018

Conversation

octonato
Copy link
Member

This PR adds the possibility to configure ServiceTest to be used for JDBC test.

Fixes: #304

Copy link
Member Author

@octonato octonato left a comment

Choose a reason for hiding this comment

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

@TimMoore this PR is much larger than the initially planned. I took the time to add some minor improvements in formatting and API usage.

With respect to functionality, it doesn't have more than originally agreed, ie: it adds support for JDBC in ServiceTest and it only affects test code.

I manually tested with Hello Scala (Cassandra and JDBC) and with Hello Java (Cassandra and JDBC) and with mvn and sbt. Works as expected.

We can discuss if that's something we want to include in 1.4.0 or in 1.4.1.


//#setup2
private final Setup setup2 = defaultSetup().withCluster(true);
Copy link
Member Author

Choose a reason for hiding this comment

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

Some minor improvements. Each example in its own java class to avoid setup1, setup2, etc

*
* @return A copy of this setup.
*/
def withCassandra(): Setup = withCassandra(true)
Copy link
Member Author

@octonato octonato Jan 12, 2018

Choose a reason for hiding this comment

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

Duplicated with methods with a parameterless variant. No need to be so verbose.
withCassandra(), withJdbc() and withCluster() are clear enough. We don't need to pass true each time.

On the other hand, to disable it, one has to call withCassandra(false). Which will probably never be used because it's disabled by default.

Should we consider deprecation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally agree. Thanks!

.bindings(sBind[TestServiceLocatorPort].to(testServiceLocatorPort))
.bindings(sBind[ServiceLocator].to(classOf[TestServiceLocator]))
.bindings(sBind[TopicFactory].to(classOf[TestTopicFactory]))
.configure("play.akka.actor-system", testName)

val log = Logger(getClass)

val b3 =
val finalBuilder =
Copy link
Member Author

@octonato octonato Jan 12, 2018

Choose a reason for hiding this comment

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

The following code was very cluttered and poorly formatted. Did some cosmetics rearrangement to make it more readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fantastic!

/**
* Enriches [[GuiceApplicationBuilder]] with a `disableModules` method.
*/
private implicit class GuiceBuilderOps(val builder: GuiceApplicationBuilder) extends AnyVal {
Copy link
Member Author

Choose a reason for hiding this comment

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

Method extensions is a good option for this kind of API. We just add one more method to the already existing fluent API.

build.sbt Outdated
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.lightbend.lagom.javadsl.testkit.ServiceTest#Setup.withJdbc"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.lightbend.lagom.javadsl.testkit.ServiceTest#Setup.withCassandra"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.lightbend.lagom.javadsl.testkit.ServiceTest#Setup.jdbc"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.lightbend.lagom.javadsl.testkit.ServiceTest#Setup.withJdbc")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we exclude the testkit projects from MiMa entirely?

*
* @return A copy of this setup.
*/
def withCassandra(): Setup = withCassandra(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Totally agree. Thanks!

.bindings(sBind[TestServiceLocatorPort].to(testServiceLocatorPort))
.bindings(sBind[ServiceLocator].to(classOf[TestServiceLocator]))
.bindings(sBind[TopicFactory].to(classOf[TestTopicFactory]))
.configure("play.akka.actor-system", testName)

val log = Logger(getClass)

val b3 =
val finalBuilder =
Copy link
Contributor

Choose a reason for hiding this comment

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

Fantastic!

} else if (setup.jdbc) {

initialBuilder
.configure(CassandraTestConfig.clusterConfig())
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we should move it somewhere other than CassandraTestConfig (doesn't have to be in this PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do it on this PR. Otherwise, that will be another open issue filling the backlog

Copy link
Member Author

Choose a reason for hiding this comment

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

After a further look, it seems that this whole CassandraTestConfig needs a re-arrangement.

Java and Scala modules are not aligned. Java has CassandraTestConfig and TestUtil while the Scala one has two variants of TestUtil.

CassandraTestConfig (in java dsl) is also confusing, because it's not in persistence-cassandra module, but in persistence. I won't refactor it in this PR and send another one for that. Seems too intrusive and doesn't relates to this one. Is more about re-arrangement and clean-up.

@TimMoore TimMoore merged commit 66d1fe2 into lagom:master Jan 15, 2018
@TimMoore
Copy link
Contributor

TimMoore commented Jan 16, 2018

1.4.x 22ad2e1

TimMoore pushed a commit that referenced this pull request Jan 16, 2018
@octonato octonato deleted the service-test-jdbc branch August 8, 2018 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants