-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure the TTL_ATTRIBUTE_NAME of the Hadoop job if TTL is enabled …
…on a table attribute
- Loading branch information
Showing
4 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/src/test/configurations/dynamodb-to-alternator-ttl.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
source: | ||
type: dynamodb | ||
table: TtlTable | ||
region: dummy | ||
endpoint: | ||
host: http://dynamodb | ||
port: 8000 | ||
credentials: | ||
accessKey: dummy | ||
secretKey: dummy | ||
|
||
target: | ||
type: dynamodb | ||
table: TtlTable | ||
region: dummy | ||
endpoint: | ||
host: http://scylla | ||
port: 8000 | ||
credentials: | ||
accessKey: dummy | ||
secretKey: dummy | ||
streamChanges: false | ||
|
||
savepoints: | ||
path: /app/savepoints | ||
intervalSeconds: 300 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
tests/src/test/scala/com/scylladb/migrator/alternator/SkippedItemsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.scylladb.migrator.alternator | ||
|
||
import com.scylladb.migrator.SparkUtils.successfullyPerformMigration | ||
import software.amazon.awssdk.services.dynamodb.model.{AttributeValue, GetItemRequest, PutItemRequest, TimeToLiveSpecification, UpdateTimeToLiveRequest} | ||
|
||
import scala.jdk.CollectionConverters._ | ||
import scala.util.chaining._ | ||
|
||
class SkippedItemsTest extends MigratorSuite { | ||
|
||
withTable("TtlTable").test("Expired items should be filtered out from the source table") { tableName => | ||
// Insert two items, one of them is expired | ||
val oneDay = 24 * 60 * 60 // seconds | ||
val now = System.currentTimeMillis() / 1000 // seconds | ||
val keys1 = Map("id" -> AttributeValue.fromS("12345")) | ||
val attrs1 = Map("foo" -> AttributeValue.fromN((now + oneDay).toString)) | ||
val item1Data = keys1 ++ attrs1 | ||
sourceDDb.putItem( | ||
PutItemRequest.builder().tableName(tableName).item(item1Data.asJava).build() | ||
) | ||
val keys2 = Map("id" -> AttributeValue.fromS("67890")) | ||
val attrs2 = Map("foo" -> AttributeValue.fromN((now - oneDay).toString)) | ||
val item2Data = keys2 ++ attrs2 | ||
sourceDDb.putItem( | ||
PutItemRequest.builder().tableName(tableName).item(item2Data.asJava).build() | ||
) | ||
|
||
// Enable TTL | ||
sourceDDb.updateTimeToLive( | ||
UpdateTimeToLiveRequest | ||
.builder() | ||
.tableName(tableName) | ||
.timeToLiveSpecification( | ||
TimeToLiveSpecification | ||
.builder() | ||
.enabled(true) | ||
.attributeName("foo") | ||
.build() | ||
) | ||
.build() | ||
) | ||
.sdkHttpResponse() | ||
.statusCode() | ||
.tap { statusCode => | ||
assertEquals(statusCode, 200) | ||
} | ||
|
||
// Check that expired item is still present in the source before the migration | ||
val getItem2Request = | ||
GetItemRequest.builder().tableName(tableName).key(keys2.asJava).build() | ||
sourceDDb | ||
.getItem(getItem2Request) | ||
.tap { itemResult => | ||
assert(itemResult.hasItem) | ||
assertEquals(itemResult.item.asScala.toMap, item2Data) | ||
} | ||
|
||
successfullyPerformMigration("dynamodb-to-alternator-ttl.yaml") | ||
|
||
checkItemWasMigrated(tableName, keys1, item1Data) | ||
|
||
// Expired item has been skipped | ||
targetAlternator | ||
.getItem(getItem2Request) | ||
.tap { itemResult => | ||
assert(!itemResult.hasItem) | ||
} | ||
|
||
} | ||
|
||
} |