19
loading...
This website collects cookies to deliver better user experience
DynamoDBProxyServer
backed by sqlite4java
,
which is available on most platforms.Feature | tempest-testing-jvm | tempest-testing-docker |
---|---|---|
Start up time | ~1s | ~10s |
Memory usage | Less | More |
Dependency | sqlite4java native library | Docker |
tempest-testing
, first add this library as a test dependency:dependencies {
testImplementation "app.cash.tempest:tempest-testing-jvm:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest-testing-junit5:{{ versions.tempest }}"
}
// Or
dependencies {
testImplementation "app.cash.tempest:tempest-testing-docker:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest-testing-junit5:{{ versions.tempest }}"
}
dependencies {
testImplementation "app.cash.tempest:tempest2-testing-jvm:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest2-testing-junit5:{{ versions.tempest }}"
}
// Or
dependencies {
testImplementation "app.cash.tempest:tempest2-testing-docker:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest2-testing-junit5:{{ versions.tempest }}"
}
@org.junit.jupiter.api.Test
, you may add TestDynamoDb
as a testclass MyTest {
@RegisterExtension
@JvmField
val db = TestDynamoDb.Builder(JvmDynamoDbServer.Factory)
// `MusicItem` is annotated with `@DynamoDBTable`. Tempest recreates this table before each test.
.addTable(TestTable.create(MusicItem.TABLE_NAME, MusicItem::class.java))
.build()
private val musicTable by lazy { db.logicalDb<MusicDb>().music }
@Test
fun test() {
val albumInfo = AlbumInfo(
"ALBUM_1",
"after hours - EP",
"53 Thieves",
LocalDate.of(2020, 2, 21),
"Contemporary R&B"
)
// Talk to DynamoDB using Tempest's API.
musicTable.albumInfo.save(albumInfo)
}
@Test
fun anotherTest() {
// Talk to DynamoDB using the AWS SDK.
val result = db.dynamoDb.describeTable(
DescribeTableRequest.builder().tableName(MusicItem.TABLE_NAME).build()
)
// Do something with the result...
}
}
CreateTableRequest
in a lambda.fun testDb() = TestDynamoDb.Builder(JvmDynamoDbServer.Factory)
.addTable(
TestTable.create<MusicItem> { createTableRequest ->
for (gsi in createTableRequest.globalSecondaryIndexes) {
gsi.withProjection(Projection().withProjectionType(ProjectionType.ALL))
}
createTableRequest
}
)
.build()
fun testDb() = TestDynamoDb.Builder(DockerDynamoDbServer.Factory)
.addTable(TestTable.create<MusicItem>())
.build()
tempest-testing
, first add this library as a test dependency:dependencies {
testImplementation "app.cash.tempest:tempest-testing-jvm:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest-testing-junit4:{{ versions.tempest }}"
}
// Or
dependencies {
testImplementation "app.cash.tempest:tempest-testing-docker:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest-testing-junit4:{{ versions.tempest }}"
}
dependencies {
testImplementation "app.cash.tempest:tempest2-testing-jvm:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest2-testing-junit4:{{ versions.tempest }}"
}
// Or
dependencies {
testImplementation "app.cash.tempest:tempest2-testing-docker:{{ versions.tempest }}"
testImplementation "app.cash.tempest:tempest2-testing-junit4:{{ versions.tempest }}"
}
@org.junit.Test
, you may add TestDynamoDb
as aclass MyTest {
@get:Rule
val db = TestDynamoDb.Builder(JvmDynamoDbServer.Factory)
// `MusicItem` is annotated with `@DynamoDBTable`. Tempest recreates this table before each test.
.addTable(TestTable.create(MusicItem.TABLE_NAME, MusicItem::class.java))
.build()
private val musicTable by lazy { db.logicalDb<MusicDb>().music }
@Test
fun test() {
val albumInfo = AlbumInfo(
"ALBUM_1",
"after hours - EP",
"53 Thieves",
LocalDate.of(2020, 2, 21),
"Contemporary R&B"
)
// Talk to DynamoDB using Tempest's API.
musicTable.albumInfo.save(albumInfo)
}
@Test
fun anotherTest() {
// Talk to DynamoDB using the AWS SDK.
val result = db.dynamoDb.describeTable(
DescribeTableRequest.builder().tableName(MusicItem.TABLE_NAME).build()
)
// Do something with the result...
}
}
CreateTableRequest
in a lambda.fun testDb() = TestDynamoDb.Builder(JvmDynamoDbServer.Factory)
.addTable(
TestTable.create<MusicItem> { createTableRequest ->
for (gsi in createTableRequest.globalSecondaryIndexes) {
gsi.withProjection(Projection().withProjectionType(ProjectionType.ALL))
}
createTableRequest
}
)
.build()
fun testDb() = TestDynamoDb.Builder(DockerDynamoDbServer.Factory)
.addTable(TestTable.create<MusicItem>())
.build()
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
// ...
class JUnit5TestDynamoDb(
private val testTables: List<TestTable>,
) : BeforeEachCallback, AfterEachCallback {
private val service = TestDynamoDbService.create(JvmDynamoDbServer.Factory, testTables, 8000)
override fun beforeEach(context: ExtensionContext) {
service.startAsync()
service.awaitRunning()
}
override fun afterEach(context: ExtensionContext?) {
service.stopAsync()
service.awaitTerminated()
}
}
19