@@ -1220,7 +1220,7 @@ public void testQueryBatcherFailures() throws IOException, InterruptedException
12201220 }
12211221
12221222 @ Test
1223- public void testServerXQueryTransform () throws IOException , ParserConfigurationException , SAXException , TransformerException , InterruptedException , XPathExpressionException
1223+ public void testServerXQueryTransform () throws InterruptedException , XPathExpressionException
12241224 {
12251225 System .out .println ("Running testServerXQueryTransform" );
12261226 try {
@@ -1272,8 +1272,7 @@ public void testServerXQueryTransform() throws IOException, ParserConfigurationE
12721272 batcher .flushAndWait ();
12731273 dmManager .stopJob (batcher );
12741274
1275- StringBuffer batchResults = new StringBuffer ();
1276- StringBuffer batchFailResults = new StringBuffer ();
1275+ List <String > uris = new ArrayList <>();
12771276
12781277 // create query def
12791278 QueryManager queryMgr = client .newQueryManager ();
@@ -1285,56 +1284,34 @@ public void testServerXQueryTransform() throws IOException, ParserConfigurationE
12851284 queryBatcher1 .withBatchSize (5 );
12861285
12871286 queryBatcher1 .onUrisReady (batch -> {
1288- for (String str : batch .getItems ()) {
1289- batchResults .append (str );
1290- batchResults .append ("|" );
1287+ for (String item : batch .getItems ()) {
1288+ uris .add (item );
12911289 }
12921290 });
1293- queryBatcher1 .onQueryFailure (throwable -> {
1294- System .out .println ("Exceptions thrown from callback onQueryFailure" );
1295- throwable .printStackTrace ();
1296- batchFailResults .append ("Test has Exceptions" );
1297- });
12981291 dmManager .startJob (queryBatcher1 );
1299- queryBatcher1 .awaitCompletion (3 , TimeUnit .MINUTES );
1300- while (!queryBatcher1 .isStopped ()) {
1301- // Do nothing. Wait for batcher to complete.
1302- }
1303-
1304- if (queryBatcher1 .isStopped ()) {
1305- // Verify the batch results now.
1306- String [] res = batchResults .toString ().split ("\\ |" );
1307- assertEquals (res .length , 20 );
1308-
1309- // Get a random URI, since the URIs returned are not ordered. Get the 3rd
1310- // URI.
1311- assertTrue ( res [2 ].contains ("foo" ) || res [2 ].contains ("bar" ));
1312-
1313- // do a lookup with the first URI using the client to verify transforms
1314- // are done.
1315- DOMHandle readHandle = readDocumentUsingDOMHandle (client , res [0 ], "XML" );
1316- String contents = readHandle .evaluateXPath ("/foo/text()" , String .class );
1317- String attribute = readHandle .evaluateXPath ("/foo/@Lang" , String .class );
1318- // Verify that the contents are of xmlStr1 or xmlStr2.
1319-
1320- System .out .println ("Contents are : " + contents );
1321- System .out .println ("Contents are : " + attribute );
1322- assertTrue ( xmlStr1 .contains (contents ) || xmlStr2 .contains (contents ));
1323- assertTrue ( attribute .equalsIgnoreCase ("English" ));
1324- }
1325- else {
1326- fail ("testServerXQueryTransform method failed" );
1327- }
1328- } catch (Exception e ) {
1329- e .printStackTrace ();
1330- fail ("testServerXQueryTransform method failed" );
1292+ queryBatcher1 .awaitCompletion ();
1293+
1294+ // Verify the batch results now.
1295+ assertEquals (20 , uris .size ());
1296+
1297+ // Get a random URI, since the URIs returned are not ordered. Get the 3rd
1298+ // URI.
1299+ String thirdUri = uris .get (2 );
1300+ assertTrue ( thirdUri .contains ("foo" ) || thirdUri .contains ("bar" ), "Unexpected URI: " + thirdUri );
1301+
1302+ // do a lookup with the first URI using the client to verify transforms
1303+ // are done.
1304+ DOMHandle readHandle = readDocumentUsingDOMHandle (client , uris .get (0 ), "XML" );
1305+ String contents = readHandle .evaluateXPath ("/foo/text()" , String .class );
1306+ String attribute = readHandle .evaluateXPath ("/foo/@Lang" , String .class );
1307+ // Verify that the contents are of xmlStr1 or xmlStr2.
1308+ System .out .println ("Contents are : " + contents );
1309+ System .out .println ("Contents are : " + attribute );
1310+ assertTrue ( xmlStr1 .contains (contents ) || xmlStr2 .contains (contents ));
1311+ assertTrue ( attribute .equalsIgnoreCase ("English" ));
13311312 }
13321313 finally {
1333- try {
1334- clearDB ();
1335- } catch (Exception e ) {
1336- e .printStackTrace ();
1337- }
1314+ clearDB ();
13381315 }
13391316 }
13401317
0 commit comments