@@ -76,39 +76,104 @@ void setup() {
76
76
77
77
@ Test
78
78
void getTableRelationshipsTest () {
79
+ when (this .mockDatabasePage .getValues ())
80
+ .thenReturn (
81
+ List .of (new Database (this .databaseId , State .READY , this .databaseAdminClient )));
79
82
ReadContext readContext = mock (ReadContext .class );
80
83
81
84
Struct s1 =
82
85
Struct .newBuilder ()
86
+ .set ("table_schema" )
87
+ .to ("" )
83
88
.set ("table_name" )
84
89
.to (Value .string ("grandpa" ))
85
90
.set ("parent_table_name" )
86
91
.to (Value .string (null ))
87
92
.build ();
88
93
Struct s2 =
89
94
Struct .newBuilder ()
95
+ .set ("table_schema" )
96
+ .to ("" )
90
97
.set ("table_name" )
91
98
.to (Value .string ("parent_a" ))
92
99
.set ("parent_table_name" )
93
100
.to (Value .string ("grandpa" ))
94
101
.build ();
95
102
Struct s3 =
96
103
Struct .newBuilder ()
104
+ .set ("table_schema" )
105
+ .to ("" )
97
106
.set ("table_name" )
98
107
.to (Value .string ("parent_b" ))
99
108
.set ("parent_table_name" )
100
109
.to (Value .string ("grandpa" ))
101
110
.build ();
102
111
Struct s4 =
103
112
Struct .newBuilder ()
113
+ .set ("table_schema" )
114
+ .to ("" )
104
115
.set ("table_name" )
105
116
.to (Value .string ("child" ))
106
117
.set ("parent_table_name" )
107
118
.to (Value .string ("parent_a" ))
108
119
.build ();
120
+ Struct s5 =
121
+ Struct .newBuilder ()
122
+ .set ("table_schema" )
123
+ .to ("INFORMATION_SCHEMA" )
124
+ .set ("table_name" )
125
+ .to (Value .string ("TABLES" ))
126
+ .set ("parent_table_name" )
127
+ .to (Value .string (null ))
128
+ .build ();
129
+ Struct s6 =
130
+ Struct .newBuilder ()
131
+ .set ("table_schema" )
132
+ .to ("" )
133
+ .set ("table_name" )
134
+ .to (Value .string ("TABLES" ))
135
+ .set ("parent_table_name" )
136
+ .to (Value .string (null ))
137
+ .build ();
138
+ Struct s7 =
139
+ Struct .newBuilder ()
140
+ .set ("table_schema" )
141
+ .to ("" )
142
+ .set ("table_name" )
143
+ .to (Value .string ("CHILD_TABLES" ))
144
+ .set ("parent_table_name" )
145
+ .to (Value .string ("TABLES" ))
146
+ .build ();
147
+ Struct s8 =
148
+ Struct .newBuilder ()
149
+ .set ("table_schema" )
150
+ .to ("my_schema" )
151
+ .set ("table_name" )
152
+ .to (Value .string ("grandpa" ))
153
+ .set ("parent_table_name" )
154
+ .to (Value .string (null ))
155
+ .build ();
156
+ Struct s9 =
157
+ Struct .newBuilder ()
158
+ .set ("table_schema" )
159
+ .to ("my_schema" )
160
+ .set ("table_name" )
161
+ .to (Value .string ("dad" ))
162
+ .set ("parent_table_name" )
163
+ .to (Value .string ("grandpa" ))
164
+ .build ();
165
+ Struct s10 =
166
+ Struct .newBuilder ()
167
+ .set ("table_schema" )
168
+ .to ("my_schema" )
169
+ .set ("table_name" )
170
+ .to (Value .string ("child" ))
171
+ .set ("parent_table_name" )
172
+ .to (Value .string ("dad" ))
173
+ .build ();
109
174
110
175
MockResults mockResults = new MockResults ();
111
- mockResults .structs = Arrays .asList (s1 , s2 , s3 , s4 );
176
+ mockResults .structs = Arrays .asList (s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 );
112
177
ResultSet results = mock (ResultSet .class );
113
178
when (results .next ()).thenAnswer (invocation -> mockResults .next ());
114
179
when (results .getCurrentRowAsStruct ()).thenAnswer (invocation -> mockResults .getCurrent ());
@@ -118,9 +183,27 @@ void getTableRelationshipsTest() {
118
183
Map <String , Set <String >> relationships =
119
184
this .spannerDatabaseAdminTemplate .getParentChildTablesMap ();
120
185
121
- assertThat (relationships ).hasSize (2 );
186
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("some-random-table" )).isFalse ();
187
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("grandpa" )).isTrue ();
188
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("parent_a" )).isTrue ();
189
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("parent_b" )).isTrue ();
190
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("child" )).isTrue ();
191
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("child" )).isTrue ();
192
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("INFORMATION_SCHEMA.TABLES" )).isTrue ();
193
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("TABLES" )).isTrue ();
194
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("CHILD_TABLES" )).isTrue ();
195
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("my_schema.grandpa" )).isTrue ();
196
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("my_schema.dad" )).isTrue ();
197
+ assertThat (this .spannerDatabaseAdminTemplate .tableExists ("my_schema.child" )).isTrue ();
198
+
199
+ assertThat (relationships ).hasSize (5 );
122
200
assertThat (relationships .get ("grandpa" )).containsExactlyInAnyOrder ("parent_a" , "parent_b" );
123
201
assertThat (relationships .get ("parent_a" )).containsExactlyInAnyOrder ("child" );
202
+ assertThat (relationships .get ("child" )).isNull ();
203
+ assertThat (relationships .get ("TABLES" )).containsExactlyInAnyOrder ("CHILD_TABLES" );
204
+ assertThat (relationships .get ("INFORMATION_SCHEMA.TABLES" )).isNull ();
205
+ assertThat (relationships .get ("my_schema.grandpa" )).containsExactlyInAnyOrder ("my_schema.dad" );
206
+ assertThat (relationships .get ("my_schema.dad" )).containsExactlyInAnyOrder ("my_schema.child" );
124
207
125
208
assertThat (this .spannerDatabaseAdminTemplate .isInterleaved ("grandpa" , "child" ))
126
209
.as ("verify grand-child relationship" )
@@ -140,6 +223,19 @@ void getTableRelationshipsTest() {
140
223
assertThat (this .spannerDatabaseAdminTemplate .isInterleaved ("parent_b" , "child" ))
141
224
.as ("verify not parent-child relationship" )
142
225
.isFalse ();
226
+
227
+ assertThat (this .spannerDatabaseAdminTemplate
228
+ .isInterleaved ("my_schema.grandpa" , "my_schema.dad" ))
229
+ .as ("verify my-schema grand-child relationship" )
230
+ .isTrue ();
231
+ assertThat (this .spannerDatabaseAdminTemplate
232
+ .isInterleaved ("my_schema.grandpa" , "my_schema.child" ))
233
+ .as ("verify my-schema grand-child relationship" )
234
+ .isTrue ();
235
+ assertThat (this .spannerDatabaseAdminTemplate
236
+ .isInterleaved ("my_schema.grandpa" , "child" ))
237
+ .as ("verify not my-schema grand-child relationship" )
238
+ .isFalse ();
143
239
}
144
240
145
241
@ Test
0 commit comments