-
Notifications
You must be signed in to change notification settings - Fork 33
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 tempest testing #33
Conversation
import com.google.common.util.concurrent.Service | ||
import kotlin.reflect.KClass | ||
|
||
interface TestDynamoDbClient : Service { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
/** | ||
* A DynamoDB test server running in-process or in a local Docker container. | ||
*/ | ||
interface TestDynamoDbServer : Service { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New API
* Use [configureTable] to customize the table creation request for testing, such as to configure | ||
* the secondary indexes required by `ProjectionType.ALL`. | ||
*/ | ||
data class TestTable internal constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New API
import software.amazon.awssdk.services.dynamodb.model.DeleteTableRequest | ||
import software.amazon.awssdk.services.dynamodb.model.DynamoDbException | ||
|
||
object DockerDynamoDbServer : AbstractIdleService(), TestDynamoDbServer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New API
import com.google.common.util.concurrent.AbstractIdleService | ||
import java.io.File | ||
|
||
object JvmDynamoDbServer : AbstractIdleService(), TestDynamoDbServer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New API
import com.amazonaws.services.dynamodbv2.model.Projection | ||
import com.amazonaws.services.dynamodbv2.model.ProjectionType | ||
|
||
fun testDb() = TestDynamoDb.Builder(JvmDynamoDbServer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome.
val module = MusicDbTestModule() | ||
@RegisterExtension | ||
@JvmField | ||
val db = testDb() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
junit5 API usage
@@ -20,9 +24,6 @@ ext.dep = [ | |||
"ktlintVersion": "0.40.0", | |||
"loggingApi": "io.github.microutils:kotlin-logging:1.7.9", | |||
"mavenPublishGradlePlugin": "com.vanniktech:gradle-maven-publish-plugin:0.12.0", | |||
"miskAws2DynamodbTesting": "com.squareup.misk:misk-aws2-dynamodb-testing:0.17.0-20210210.0438-e43f047", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing misk dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very very good.
I’d like for you to land this as-is, and then optionally address any feedback in follow-ups. I hope to be a lot faster on the turnaround for those.
|
||
public class InteropTestUtils { | ||
|
||
public static TestDynamoDb testDb() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API looks great.
import com.amazonaws.services.dynamodbv2.model.Projection | ||
import com.amazonaws.services.dynamodbv2.model.ProjectionType | ||
|
||
fun testDb() = TestDynamoDb.Builder(JvmDynamoDbServer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome.
|
||
@Inject lateinit var aliasDb: AliasDb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needing Guice in these tests is nice for the library.
private val musicTable get() = musicDb.music | ||
private val reservedWordsTable get() = reservedWordsDb.table | ||
private val musicTable by lazy { db.logicalDb<MusicDb>().music } | ||
private val reservedWordsTable by lazy { db.logicalDb<ReservedWordsDb>().table } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there’s a way to make these lazy internally rather than in the public API. For testing it could initialize on demand or assert if it isn’t or something.
Just to save boilerplate in the tests themselves!
@@ -20,9 +24,6 @@ ext.dep = [ | |||
"ktlintVersion": "0.40.0", | |||
"loggingApi": "io.github.microutils:kotlin-logging:1.7.9", | |||
"mavenPublishGradlePlugin": "com.vanniktech:gradle-maven-publish-plugin:0.12.0", | |||
"miskAws2DynamodbTesting": "com.squareup.misk:misk-aws2-dynamodb-testing:0.17.0-20210210.0438-e43f047", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreams | ||
import com.google.common.util.concurrent.AbstractIdleService | ||
|
||
class DefaultTestDynamoDbClient( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular, what’s the difference between this and the TestDynamoDbClient base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestDynamoDbClient is just the interface?
tempest-testing-internal/src/main/kotlin/app/cash/tempest/testing/Logger.kt
Outdated
Show resolved
Hide resolved
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput | ||
|
||
object TestUtils { | ||
val port: Int = pickPort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t like the stateful port on this object. Is there an object the caller could use instead?
tempest-testing-internal/src/main/kotlin/app/cash/tempest/testing/TestUtils.kt
Outdated
Show resolved
Hide resolved
import org.junit.rules.ExternalResource | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
class TestDynamoDb private constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document that it stays running?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you could get away with a single JUnit4 and JUnit5 extension by using only Guava service as the public API?
There’s nothing particularly Dynamo2 or Dynamo1 specific in this, just the types it imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need 2 different TestTable
classes tho to allow developers to create GSIs in SDK 1 and 2
This PR adds two ways to test interaction with DynamoDB
tempest-testing-docker
tempest-testing-jvm
with support for
tempest-testing-junit4
tempest-testing-junit5
This PR also removes the dependency on
misk-testing
andmisk-dynamodb-testing