Skip to content

Commit 287ff3f

Browse files
committed
Reduce some duplication in import tests
1 parent f30cb54 commit 287ff3f

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePathImportDataTest.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void importComprehensiveData() {
126126
context.commit();
127127
}
128128

129-
copyData(root.path("company"));
129+
copyData(root.path("company"), root.path("company"));
130130

131131
// Verify all different KeyType values were handled correctly during import
132132
try (FDBRecordContext context = database.openContext()) {
@@ -202,7 +202,7 @@ void importDataWithDirectoryLayer() {
202202
final KeySpacePath dataPath = root.path("tenant").add("user_id", 999L);
203203
setSingleKey(dataPath, Tuple.from("data"), Tuple.from("directory_test"));
204204

205-
copyData(root.path("tenant"));
205+
copyData(root.path("tenant"), root.path("tenant"));
206206

207207
verifySingleKey(dataPath, Tuple.from("data"), Tuple.from("directory_test"));
208208
}
@@ -222,9 +222,8 @@ void importDataWithMismatchedPath() {
222222

223223
setSingleKey(keySpace.path("root1").add("data", 1L), Tuple.from("record"), Tuple.from("other"));
224224

225-
// Now try to ipmort that into keySpace2
226-
List<DataInKeySpacePath> exportedData = getExportedData(keySpace.path("root1"));
227-
assertBadImport(keySpace.path("root2"), exportedData);
225+
// Now try to import that into keySpace2
226+
assertBadImport(keySpace.path("root1"), keySpace.path("root2"));
228227
}
229228

230229
@Test
@@ -245,8 +244,7 @@ void importDataWithInvalidPath() {
245244
setSingleKey(keySpace1.path("root1").add("data", 1L), Tuple.from("record"), Tuple.from("other"));
246245

247246
// Now try to import that into keySpace2
248-
List<DataInKeySpacePath> exportedData = getExportedData(keySpace1.path("root1"));
249-
assertBadImport(keySpace2.path("root2"), exportedData);
247+
assertBadImport(keySpace1.path("root1"), keySpace2.path("root2"));
250248
}
251249

252250
@Test
@@ -263,12 +261,7 @@ void importDataWithSubdirectoryPath() {
263261
setSingleKey(level1Path, Tuple.from("item1"), Tuple.from("value1"));
264262

265263
// Export from root, import to subdirectory
266-
List<DataInKeySpacePath> exportedData = getExportedData(root.path("root"));
267-
268-
clearPath(database, root.path("root"));
269-
270-
// Import only to level1 subdirectory
271-
importData(database, level1Path, exportedData);
264+
copyData(root.path("root"), level1Path);
272265

273266
verifySingleKey(level1Path, Tuple.from("item1"), Tuple.from("value1"));
274267
}
@@ -288,12 +281,7 @@ void importDataWithSubdirectoryPathFailure() {
288281
setSingleKey(root.path("root").add("level1", 2L), Tuple.from("item1"), Tuple.from("value1"));
289282

290283
// Export from root, import to subdirectory
291-
List<DataInKeySpacePath> exportedData = getExportedData(root.path("root"));
292-
293-
clearPath(database, root.path("root"));
294-
295-
// Import only to level1 subdirectory
296-
assertBadImport(level1Path, exportedData);
284+
assertBadImport(root.path("root"), level1Path);
297285
}
298286

299287
@Test
@@ -329,7 +317,7 @@ void importDataWithWrapperClasses() {
329317

330318
EnvironmentKeySpace.DataPath dataStore = keySpace.root().userid(100L).application("app1").dataStore();
331319

332-
copyData(keySpace.root());
320+
copyData(keySpace.root(), keySpace.root());
333321

334322
verifySingleKey(dataStore, Tuple.from("record2", 0), Tuple.from("user100_app1_data2_0"));
335323
}
@@ -385,19 +373,19 @@ private static Tuple getTuple(final FDBRecordContext context, final byte[] key)
385373
return Tuple.fromBytes(context.ensureActive().get(key).join());
386374
}
387375

388-
private void copyData(final KeySpacePath path) {
376+
private void copyData(final KeySpacePath sourcePath, KeySpacePath destinationPath) {
389377
// Export the data
390-
final List<DataInKeySpacePath> exportedData = getExportedData(path);
378+
final List<DataInKeySpacePath> exportedData = getExportedData(sourcePath);
391379

392380
if (databases.size() > 1) {
393381
database = databases.get(1);
394382
} else {
395383
// Clear the data and import it back
396-
clearPath(database, path);
384+
clearPath(database, sourcePath);
397385
}
398386

399387
// Import the data
400-
importData(database, path, exportedData);
388+
importData(database, destinationPath, exportedData);
401389
}
402390

403391
private static void importData(final FDBDatabase database, final KeySpacePath path, final List<DataInKeySpacePath> exportedData) {
@@ -407,6 +395,11 @@ private static void importData(final FDBDatabase database, final KeySpacePath pa
407395
}
408396
}
409397

398+
private void assertBadImport(KeySpacePath sourcePath, KeySpacePath destinationPath) {
399+
List<DataInKeySpacePath> exportedData = getExportedData(sourcePath);
400+
assertBadImport(destinationPath, exportedData);
401+
}
402+
410403
private void assertBadImport(final KeySpacePath path, final List<DataInKeySpacePath> invalidData) {
411404
// Try to import into keySpace1 - should fail
412405
try (FDBRecordContext context = database.openContext()) {

0 commit comments

Comments
 (0)