@@ -43,7 +43,12 @@ def repo_config():
43
43
)
44
44
45
45
46
- def test_online_store_config_default ():
46
+ @pytest .fixture
47
+ def dynamodb_online_store ():
48
+ return DynamoDBOnlineStore ()
49
+
50
+
51
+ def test_dynamodb_online_store_config_default ():
47
52
"""Test DynamoDBOnlineStoreConfig default parameters."""
48
53
aws_region = "us-west-2"
49
54
dynamodb_store_config = DynamoDBOnlineStoreConfig (region = aws_region )
@@ -66,7 +71,7 @@ def test_dynamodb_table_default_params():
66
71
assert dynamodb_table ._dynamodb_resource is None
67
72
68
73
69
- def test_online_store_config_custom_params ():
74
+ def test_dynamodb_online_store_config_custom_params ():
70
75
"""Test DynamoDBOnlineStoreConfig custom parameters."""
71
76
aws_region = "us-west-2"
72
77
batch_size = 20
@@ -98,15 +103,14 @@ def test_dynamodb_table_custom_params():
98
103
assert dynamodb_table ._dynamodb_resource is None
99
104
100
105
101
- def test_online_store_config_dynamodb_client ( ):
106
+ def test_dynamodb_online_store_config_dynamodb_client ( dynamodb_online_store ):
102
107
"""Test DynamoDBOnlineStoreConfig configure DynamoDB client with endpoint_url."""
103
108
aws_region = "us-west-2"
104
109
endpoint_url = "http://localhost:8000"
105
- dynamodb_store = DynamoDBOnlineStore ()
106
110
dynamodb_store_config = DynamoDBOnlineStoreConfig (
107
111
region = aws_region , endpoint_url = endpoint_url
108
112
)
109
- dynamodb_client = dynamodb_store ._get_dynamodb_client (
113
+ dynamodb_client = dynamodb_online_store ._get_dynamodb_client (
110
114
dynamodb_store_config .region , dynamodb_store_config .endpoint_url
111
115
)
112
116
assert dynamodb_client .meta .region_name == aws_region
@@ -126,15 +130,14 @@ def test_dynamodb_table_dynamodb_client():
126
130
assert dynamodb_client .meta .endpoint_url == endpoint_url
127
131
128
132
129
- def test_online_store_config_dynamodb_resource ( ):
133
+ def test_dynamodb_online_store_config_dynamodb_resource ( dynamodb_online_store ):
130
134
"""Test DynamoDBOnlineStoreConfig configure DynamoDB Resource with endpoint_url."""
131
135
aws_region = "us-west-2"
132
136
endpoint_url = "http://localhost:8000"
133
- dynamodb_store = DynamoDBOnlineStore ()
134
137
dynamodb_store_config = DynamoDBOnlineStoreConfig (
135
138
region = aws_region , endpoint_url = endpoint_url
136
139
)
137
- dynamodb_resource = dynamodb_store ._get_dynamodb_resource (
140
+ dynamodb_resource = dynamodb_online_store ._get_dynamodb_resource (
138
141
dynamodb_store_config .region , dynamodb_store_config .endpoint_url
139
142
)
140
143
assert dynamodb_resource .meta .client .meta .region_name == aws_region
@@ -156,36 +159,123 @@ def test_dynamodb_table_dynamodb_resource():
156
159
157
160
@mock_dynamodb2
158
161
@pytest .mark .parametrize ("n_samples" , [5 , 50 , 100 ])
159
- def test_online_read (repo_config , n_samples ):
162
+ def test_dynamodb_online_store_online_read (
163
+ repo_config , dynamodb_online_store , n_samples
164
+ ):
160
165
"""Test DynamoDBOnlineStore online_read method."""
161
- _create_test_table (PROJECT , f"{ TABLE_NAME } _{ n_samples } " , REGION )
166
+ db_table_name = f"{ TABLE_NAME } _online_read_{ n_samples } "
167
+ _create_test_table (PROJECT , db_table_name , REGION )
162
168
data = _create_n_customer_test_samples (n = n_samples )
163
- _insert_data_test_table (data , PROJECT , f" { TABLE_NAME } _ { n_samples } " , REGION )
169
+ _insert_data_test_table (data , PROJECT , db_table_name , REGION )
164
170
165
171
entity_keys , features , * rest = zip (* data )
166
- dynamodb_store = DynamoDBOnlineStore ()
167
- returned_items = dynamodb_store .online_read (
172
+ returned_items = dynamodb_online_store .online_read (
168
173
config = repo_config ,
169
- table = MockFeatureView (name = f" { TABLE_NAME } _ { n_samples } " ),
174
+ table = MockFeatureView (name = db_table_name ),
170
175
entity_keys = entity_keys ,
171
176
)
172
177
assert len (returned_items ) == len (data )
173
178
assert [item [1 ] for item in returned_items ] == list (features )
174
179
175
180
176
181
@mock_dynamodb2
177
- def test_online_read_unknown_entity (repo_config ):
182
+ @pytest .mark .parametrize ("n_samples" , [5 , 50 , 100 ])
183
+ def test_dynamodb_online_store_online_write_batch (
184
+ repo_config , dynamodb_online_store , n_samples
185
+ ):
186
+ """Test DynamoDBOnlineStore online_write_batch method."""
187
+ db_table_name = f"{ TABLE_NAME } _online_write_batch_{ n_samples } "
188
+ _create_test_table (PROJECT , db_table_name , REGION )
189
+ data = _create_n_customer_test_samples ()
190
+
191
+ entity_keys , features , * rest = zip (* data )
192
+ dynamodb_online_store .online_write_batch (
193
+ config = repo_config ,
194
+ table = MockFeatureView (name = db_table_name ),
195
+ data = data ,
196
+ progress = None ,
197
+ )
198
+ stored_items = dynamodb_online_store .online_read (
199
+ config = repo_config ,
200
+ table = MockFeatureView (name = db_table_name ),
201
+ entity_keys = entity_keys ,
202
+ )
203
+ assert stored_items is not None
204
+ assert len (stored_items ) == len (data )
205
+ assert [item [1 ] for item in stored_items ] == list (features )
206
+
207
+
208
+ @mock_dynamodb2
209
+ def test_dynamodb_online_store_update (repo_config , dynamodb_online_store ):
210
+ """Test DynamoDBOnlineStore update method."""
211
+ # create dummy table to keep
212
+ db_table_keep_name = f"{ TABLE_NAME } _keep_update"
213
+ _create_test_table (PROJECT , db_table_keep_name , REGION )
214
+ # create dummy table to delete
215
+ db_table_delete_name = f"{ TABLE_NAME } _delete_update"
216
+ _create_test_table (PROJECT , db_table_delete_name , REGION )
217
+
218
+ dynamodb_online_store .update (
219
+ config = repo_config ,
220
+ tables_to_delete = [MockFeatureView (name = db_table_delete_name )],
221
+ tables_to_keep = [MockFeatureView (name = db_table_keep_name )],
222
+ entities_to_delete = None ,
223
+ entities_to_keep = None ,
224
+ partial = None ,
225
+ )
226
+
227
+ # check only db_table_keep_name exists
228
+ dynamodb_client = dynamodb_online_store ._get_dynamodb_client (REGION )
229
+ existing_tables = dynamodb_client .list_tables ()
230
+ existing_tables = existing_tables .get ("TableNames" , None )
231
+
232
+ assert existing_tables is not None
233
+ assert len (existing_tables ) == 1
234
+ assert existing_tables [0 ] == f"test_aws.{ db_table_keep_name } "
235
+
236
+
237
+ @mock_dynamodb2
238
+ def test_dynamodb_online_store_teardown (repo_config , dynamodb_online_store ):
239
+ """Test DynamoDBOnlineStore teardown method."""
240
+ db_table_delete_name_one = f"{ TABLE_NAME } _delete_teardown_1"
241
+ db_table_delete_name_two = f"{ TABLE_NAME } _delete_teardown_2"
242
+ _create_test_table (PROJECT , db_table_delete_name_one , REGION )
243
+ _create_test_table (PROJECT , db_table_delete_name_two , REGION )
244
+
245
+ dynamodb_online_store .teardown (
246
+ config = repo_config ,
247
+ tables = [
248
+ MockFeatureView (name = db_table_delete_name_one ),
249
+ MockFeatureView (name = db_table_delete_name_two ),
250
+ ],
251
+ entities = None ,
252
+ )
253
+
254
+ # Check tables non exist
255
+ dynamodb_client = dynamodb_online_store ._get_dynamodb_client (REGION )
256
+ existing_tables = dynamodb_client .list_tables ()
257
+ existing_tables = existing_tables .get ("TableNames" , None )
258
+
259
+ assert existing_tables is not None
260
+ assert len (existing_tables ) == 0
261
+
262
+
263
+ @mock_dynamodb2
264
+ def test_dynamodb_online_store_online_read_unknown_entity (
265
+ repo_config , dynamodb_online_store
266
+ ):
178
267
"""Test DynamoDBOnlineStore online_read method."""
179
268
n_samples = 2
180
- _create_test_table (PROJECT , f"{ TABLE_NAME } _ { n_samples } " , REGION )
269
+ _create_test_table (PROJECT , f"{ TABLE_NAME } _unknown_entity_ { n_samples } " , REGION )
181
270
data = _create_n_customer_test_samples (n = n_samples )
182
- _insert_data_test_table (data , PROJECT , f"{ TABLE_NAME } _{ n_samples } " , REGION )
271
+ _insert_data_test_table (
272
+ data , PROJECT , f"{ TABLE_NAME } _unknown_entity_{ n_samples } " , REGION
273
+ )
183
274
184
275
entity_keys , features , * rest = zip (* data )
185
276
# Append a nonsensical entity to search for
186
277
entity_keys = list (entity_keys )
187
278
features = list (features )
188
- dynamodb_store = DynamoDBOnlineStore ()
189
279
190
280
# Have the unknown entity be in the beginning, middle, and end of the list of entities.
191
281
for pos in range (len (entity_keys )):
@@ -198,9 +288,9 @@ def test_online_read_unknown_entity(repo_config):
198
288
)
199
289
features_with_none = deepcopy (features )
200
290
features_with_none .insert (pos , None )
201
- returned_items = dynamodb_store .online_read (
291
+ returned_items = dynamodb_online_store .online_read (
202
292
config = repo_config ,
203
- table = MockFeatureView (name = f"{ TABLE_NAME } _ { n_samples } " ),
293
+ table = MockFeatureView (name = f"{ TABLE_NAME } _unknown_entity_ { n_samples } " ),
204
294
entity_keys = entity_keys_with_unknown ,
205
295
)
206
296
assert len (returned_items ) == len (entity_keys_with_unknown )
@@ -210,17 +300,16 @@ def test_online_read_unknown_entity(repo_config):
210
300
211
301
212
302
@mock_dynamodb2
213
- def test_write_batch_non_duplicates (repo_config ):
303
+ def test_write_batch_non_duplicates (repo_config , dynamodb_online_store ):
214
304
"""Test DynamoDBOnline Store deduplicate write batch request items."""
215
305
dynamodb_tbl = f"{ TABLE_NAME } _batch_non_duplicates"
216
306
_create_test_table (PROJECT , dynamodb_tbl , REGION )
217
307
data = _create_n_customer_test_samples ()
218
308
data_duplicate = deepcopy (data )
219
309
dynamodb_resource = boto3 .resource ("dynamodb" , region_name = REGION )
220
310
table_instance = dynamodb_resource .Table (f"{ PROJECT } .{ dynamodb_tbl } " )
221
- dynamodb_store = DynamoDBOnlineStore ()
222
311
# Insert duplicate data
223
- dynamodb_store ._write_batch_non_duplicates (
312
+ dynamodb_online_store ._write_batch_non_duplicates (
224
313
table_instance , data + data_duplicate , progress = None
225
314
)
226
315
# Request more items than inserted
0 commit comments