@@ -40,7 +40,7 @@ class DynamoDBEcho(urlWithMappedPort: URI, accessKey: String, secretKey: String,
40
40
for {
41
41
_ <- createTable()
42
42
_ <- writeItems(noOfItems)
43
- result <- readItems()
43
+ result <- readItems(noOfItems )
44
44
} yield result
45
45
}
46
46
@@ -53,7 +53,7 @@ class DynamoDBEcho(urlWithMappedPort: URI, accessKey: String, secretKey: String,
53
53
.via(DynamoDb .flow(parallelism = 1 ))
54
54
55
55
source
56
- .map (descTableResponse => logger.info(s " Successfully created table: ${descTableResponse.table.tableName}" ))
56
+ .wireTap (descTableResponse => logger.info(s " Successfully created table: ${descTableResponse.table.tableName}" ))
57
57
.runWith(Sink .ignore)
58
58
}
59
59
@@ -95,7 +95,7 @@ class DynamoDBEcho(urlWithMappedPort: URI, accessKey: String, secretKey: String,
95
95
val request = PutItemRequest .builder().tableName(testTableName).item(Map (
96
96
" Id" -> AttributeValue .builder().s(item.toString).build(),
97
97
" att1" -> AttributeValue .builder().s(s " att1- $item" ).build(),
98
- " att2" -> AttributeValue .builder().s (s " att2- $item" ).build()
98
+ " att2" -> AttributeValue .builder().n (s " $item" ).build()
99
99
).asJava).build()
100
100
(request, RequestContext (testTableName, requestId))
101
101
})
@@ -114,23 +114,34 @@ class DynamoDBEcho(urlWithMappedPort: URI, accessKey: String, secretKey: String,
114
114
.runWith(Sink .ignore)
115
115
}
116
116
117
- private def readItems () = {
118
- logger.info(s " About to read items... " )
117
+ private def readItems (noOfItems : Int ) = {
118
+ logger.info(s " About to read 2nd half of all items... " )
119
+
120
+ val filterExpression = " #att2 > :val"
121
+ val expressionAttrNames = new java.util.HashMap [String , String ]()
122
+ expressionAttrNames.put(" #att2" , " att2" )
123
+
124
+ val expressionAttrValues = new java.util.HashMap [String , AttributeValue ]()
125
+ expressionAttrValues.put(" :val" , AttributeValue .builder().n((noOfItems / 2 ).toString).build())
126
+
127
+ val scanRequest = ScanRequest .builder()
128
+ .tableName(testTableName) // This hangs when no table is available
129
+ .filterExpression(filterExpression)
130
+ .expressionAttributeNames(expressionAttrNames)
131
+ .expressionAttributeValues(expressionAttrValues)
132
+ .build()
119
133
120
- // This hangs when no table is available
121
- val scanRequest = ScanRequest .builder().tableName(testTableName).build()
122
134
val scanPageInFlow : Source [ScanResponse , NotUsed ] =
123
135
Source
124
136
.single(scanRequest)
125
137
.via(DynamoDb .flowPaginated())
126
138
127
- scanPageInFlow.map { (response : ScanResponse ) => {
128
- val count = response.scannedCount()
129
- logger.info(s " Successfully read $count items " )
130
- response.items().forEach(item => logger.info(s " Item: $item" ))
131
- response.items().size()
132
- }
133
-
139
+ scanPageInFlow.map { scanResponse =>
140
+ val count = scanResponse.scannedCount()
141
+ val resultCount = scanResponse.items().size()
142
+ logger.info(s " Successfully read $resultCount/ $count items " )
143
+ scanResponse.items().forEach(item => logger.info(s " Item: $item" ))
144
+ resultCount
134
145
}.runWith(Sink .head)
135
146
}
136
147
0 commit comments