@@ -213,21 +213,37 @@ public void testQueryExplainPlan() throws Exception {
213213 }
214214 boolean queryPlanFound = false ;
215215 String queryPlan = pconn .getActivityLogger ().getExplainPlanInfo ();
216- if (queryPlan != null && queryPlan .contains ("FULL SCAN" ))
216+ if (queryPlan != null && queryPlan .contains ("FULL SCAN" ) &&
217+ queryPlan .contains ("regions=" ) && queryPlan .contains ("hostnames=" )) {
217218 queryPlanFound = true ;
218- assertTrue (queryPlanFound );
219+
220+ // Extract regions and hostnames efficiently
221+ String regions = extractBetweenBraces (queryPlan , "regions={" );
222+ String hostnames = extractBetweenBraces (queryPlan , "hostnames={" );
223+
224+ assertFalse ("Regions should not be empty" , regions .trim ().isEmpty ());
225+ assertFalse ("Hostnames should not be empty" , hostnames .trim ().isEmpty ());
226+
227+ }
228+ assertTrue ("Query plan should contain FULL SCAN, regions, and hostnames" , queryPlanFound );
219229 }
220230 try (PhoenixConnection pconn = getConnection ().unwrap (PhoenixConnection .class );) {
221231 loadData (pconn , "PhoenixTest" , "1" , 10 , 2 );
222232 String queryPlan = pconn .getActivityLogger ().getExplainPlanInfo ();
223- assertTrue (queryPlan .isEmpty ());
233+ assertTrue ("Query plan should be empty for non-query operations" , queryPlan .isEmpty ());
224234 }
225235 } else {
226236 // for HA case, ignoring as parallelPhoenixConnection object doesn't have activity Logger object defined.
227237 assertTrue (getConnection () instanceof ParallelPhoenixConnection );
228238 }
229239
230240 }
241+
242+ private String extractBetweenBraces (String text , String marker ) {
243+ int start = text .indexOf (marker ) + marker .length ();
244+ int end = text .indexOf ("}" , start );
245+ return text .substring (start , end );
246+ }
231247
232248 protected abstract ConnectionLimiter getConnectionLimiter () throws Exception ;
233249
0 commit comments