3636import org .junit .jupiter .params .ParameterizedTest ;
3737import org .junit .jupiter .params .provider .ValueSource ;
3838
39+ import java .util .List ;
3940import java .util .UUID ;
4041import java .util .concurrent .CompletableFuture ;
4142
@@ -53,19 +54,23 @@ class DataInKeySpacePathTest {
5354 @ RegisterExtension
5455 final FDBDatabaseExtension dbExtension = new FDBDatabaseExtension ();
5556
56- @ Test
57- void testSimpleTwoLevelPath () {
57+ @ ParameterizedTest
58+ @ ValueSource (ints = {0 , 1 , 2 })
59+ void testSimpleTwoLevelPath (int depth ) {
5860 KeySpace root = new KeySpace (
5961 new KeySpaceDirectory ("app" , KeyType .STRING , UUID .randomUUID ().toString ())
60- .addSubdirectory (new KeySpaceDirectory ("user" , KeyType .LONG )));
62+ .addSubdirectory (new KeySpaceDirectory ("locality" , KeyType .STRING , "Foo" )
63+ .addSubdirectory (new KeySpaceDirectory ("user" , KeyType .LONG ))));
6164
6265 final FDBDatabase database = dbExtension .getDatabase ();
6366
6467 // Store test data and create DataInKeySpacePath
6568 try (FDBRecordContext context = database .openContext ()) {
6669 Transaction tr = context .ensureActive ();
67-
68- KeySpacePath userPath = root .path ("app" ).add ("user" , 123L );
70+
71+ KeySpacePath appPath = root .path ("app" );
72+ KeySpacePath localityPath = appPath .add ("locality" );
73+ KeySpacePath userPath = localityPath .add ("user" , 123L );
6974 final Subspace pathSubspace = userPath .toSubspace (context );
7075
7176 // Add additional tuple elements after the KeySpacePath (this is how data is actually stored)
@@ -74,10 +79,10 @@ void testSimpleTwoLevelPath() {
7479
7580 tr .set (keyBytes , valueBytes );
7681 KeyValue keyValue = new KeyValue (keyBytes , valueBytes );
77-
78- // Create DataInKeySpacePath from the app-level path
79- KeySpacePath appPath = root . path ( "app" );
80- DataInKeySpacePath dataInPath = new DataInKeySpacePath ( appPath , keyValue , context );
82+
83+ final List < KeySpacePath > queryPaths = List . of ( appPath , localityPath , userPath );
84+ DataInKeySpacePath dataInPath = new DataInKeySpacePath (
85+ queryPaths . get ( depth ) , keyValue , context );
8186
8287 // Verify the resolved path
8388 CompletableFuture <ResolvedKeySpacePath > resolvedFuture = dataInPath .getResolvedPath ();
@@ -93,11 +98,14 @@ void testSimpleTwoLevelPath() {
9398 // Verify parent path
9499 ResolvedKeySpacePath parent = resolved .getParent ();
95100 assertNotNull (parent );
96- assertEquals ("app" , parent .getDirectoryName ());
97-
101+ assertEquals ("locality" , parent .getDirectoryName ());
102+ ResolvedKeySpacePath grandParent = parent .getParent ();
103+ assertNotNull (grandParent );
104+ assertEquals ("app" , grandParent .getDirectoryName ());
105+
98106 // Verify the resolved path recreates the KeySpacePath portion (not the full key)
99107 Tuple resolvedTuple = resolved .toTuple ();
100- assertEquals (TupleHelpers .subTuple (Tuple .fromBytes (keyBytes ), 0 , 2 ), resolvedTuple );
108+ assertEquals (TupleHelpers .subTuple (Tuple .fromBytes (keyBytes ), 0 , 3 ), resolvedTuple );
101109
102110 // Verify that the remainder contains the additional tuple elements
103111 Tuple remainder = resolved .getRemainder ();
@@ -546,4 +554,28 @@ void testNullKeyTypeDirectory() {
546554 context .commit ();
547555 }
548556 }
557+
558+ @ Test
559+ void testWithWrapper () {
560+ final FDBDatabase database = dbExtension .getDatabase ();
561+ final EnvironmentKeySpace keySpace = EnvironmentKeySpace .setupSampleData (database );
562+
563+ // Test export at different levels through wrapper methods
564+ try (FDBRecordContext context = database .openContext ()) {
565+ // Test 4: Export from specific data store level
566+ EnvironmentKeySpace .DataPath dataStore = keySpace .root ().userid (100L ).application ("app1" ).dataStore ();
567+
568+ final byte [] key = dataStore .toTuple (context ).add ("record2" ).add (0 ).pack ();
569+ final byte [] value = Tuple .from ("data" ).pack ();
570+ final DataInKeySpacePath dataInKeySpacePath = new DataInKeySpacePath (dataStore , new KeyValue (key , value ), context );
571+
572+ final ResolvedKeySpacePath resolvedPath = dataInKeySpacePath .getResolvedPath ().join ();
573+ assertEquals (dataStore .toResolvedPath (context ), withoutRemainder (resolvedPath ));
574+ assertEquals (Tuple .from ("record2" , 0 ), resolvedPath .getRemainder ());
575+ }
576+ }
577+
578+ private ResolvedKeySpacePath withoutRemainder (final ResolvedKeySpacePath path ) {
579+ return new ResolvedKeySpacePath (path .getParent (), path .toPath (), path .getResolvedPathValue (), null );
580+ }
549581}
0 commit comments