@@ -83,62 +83,62 @@ public class QBFailover extends BasicJavaClientREST {
8383 private static String stringTriple ;
8484 private static final String query1 = "fn:count(fn:doc())" ;
8585 private static String [] hostNames ;
86- private static String dataDir ;
86+ private static String dataDir ;
8787 private static JobTicket ticket ;
8888 private static final String TEST_DIR_PREFIX = "/WriteHostBatcher-testdata/" ;
89-
90-
89+
9190 @ BeforeClass
9291 public static void setUpBeforeClass () throws Exception {
9392 loadGradleProperties ();
9493 host = getRestAppServerHostName ();
9594 hostNames = getHosts ();
96- // Add all possible hostnames and pick a random one to create a client
95+ // Add all possible hostnames and pick a random one to create a client
9796 List <String > hostLists = new ArrayList <String >();
9897 String localhost = InetAddress .getLocalHost ().getHostName ().toLowerCase ();
99- Pattern pattern = Pattern .compile (localhost + "(.*)" );
98+ Pattern pattern = Pattern .compile (localhost + "(.*)" );
10099 Matcher matcher = pattern .matcher (hostNames [0 ]);
101100 String domain = null ;
102- if (matcher .find ())
103- {
104- domain = matcher .group (1 );
105- System .out .println (domain );
101+ if (matcher .find ()) {
102+ domain = matcher .group (1 );
103+ System .out .println (domain );
106104 }
107- for (String host : hostNames ){
105+ for (String host : hostNames ) {
108106 hostLists .add (host );
109- pattern = Pattern .compile ("(.*)" + domain );
107+ pattern = Pattern .compile ("(.*)" + domain );
110108 matcher = pattern .matcher (host );
111- if (matcher .find ())
112- {
109+ if (matcher .find ()) {
113110 hostLists .add (matcher .group (1 ));
114111 }
115112 }
116113 hostLists .add ("localhost" );
117114 int index = new Random ().nextInt (hostLists .size ());
118115 dbClient = DatabaseClientFactory .newClient (hostLists .get (index ), port , user , password , Authentication .DIGEST );
119116 evalClient = DatabaseClientFactory .newClient (host , port , user , password , Authentication .DIGEST );
120- System .out .println ("Connected to: " + dbClient .getHost ());
117+ System .out .println ("Connected to: " + dbClient .getHost ());
121118 dmManager = dbClient .newDataMovementManager ();
122119 tempMgr = evalClient .newDataMovementManager ();
123-
120+
124121 Map <String , String > props = new HashMap <>();
125- String version = String .valueOf (evalClient .newServerEval ().xquery ("xquery version \" 1.0-ml\" ; xdmp:version()" ).eval ().next ().getString ().charAt (0 ));
126- /* if (OS.indexOf("win") >= 0) {
127- dataDir = "//netapp1-10g.colo.marklogic.com/lab1/space/dmsdk-failover/win/"+version+"/temp-";
128- }else*/
129- if (OS .indexOf ("nux" ) >= 0 ){
130- dataDir = "/project/qa-netapp/space/dmsdk-failover/linux/" +version +"/temp-" ;
131- }else if (OS .indexOf ("mac" ) >= 0 ){
132- dataDir = "/project/qa-netapp/space/dmsdk-failover/mac/" +version +"/temp-" ;
133- }else {
122+ String version = String .valueOf (evalClient .newServerEval ().xquery ("xquery version \" 1.0-ml\" ; xdmp:version()" )
123+ .eval ().next ().getString ().charAt (0 ));
124+ /*
125+ * if (OS.indexOf("win") >= 0) { dataDir =
126+ * "//netapp1-10g.colo.marklogic.com/lab1/space/dmsdk-failover/win/"+
127+ * version+"/temp-"; }else
128+ */
129+ if (OS .indexOf ("nux" ) >= 0 ) {
130+ dataDir = "/project/qa-netapp/space/dmsdk-failover/linux/" + version + "/temp-" ;
131+ } else if (OS .indexOf ("mac" ) >= 0 ) {
132+ dataDir = "/project/qa-netapp/space/dmsdk-failover/mac/" + version + "/temp-" ;
133+ } else {
134134 Assert .fail ("Unsupported platform" );
135135 }
136-
136+
137137 createDB (dbName );
138138 Thread .currentThread ().sleep (500L );
139139 for (int i = 0 ; i < hostNames .length ; i ++) {
140140 if (i != 0 ) {
141- createForest (dbName + "-" + (i + 1 ), hostNames [i ], dataDir + (i + 1 ),hostNames [0 ]);
141+ createForest (dbName + "-" + (i + 1 ), hostNames [i ], dataDir + (i + 1 ), hostNames [0 ]);
142142 } else {
143143 createForest (dbName + "-" + (i + 1 ), hostNames [i ], dataDir + (i + 1 ), null );
144144
@@ -206,8 +206,14 @@ public static void tearDownAfterClass() throws Exception {
206206 @ Before
207207 public void setUp () throws Exception {
208208 for (int i = 0 ; i < hostNames .length ; i ++) {
209+ if (!isRunning (hostNames [i ])) {
210+ serverStartStop (hostNames [i ], "start" );
211+ }
209212 Assert .assertTrue (isRunning (hostNames [i ]));
210213 }
214+ if (!(dbClient .newServerEval ().xquery (query1 ).eval ().next ().getNumber ().intValue () == 0 )) {
215+ clearDB (port );
216+ }
211217 Assert .assertTrue (dbClient .newServerEval ().xquery (query1 ).eval ().next ().getNumber ().intValue () == 0 );
212218 ForestConfiguration fc = dmManager .readForestConfig ();
213219 Forest [] f = fc .listForests ();
@@ -230,7 +236,7 @@ public void tearDown() throws Exception {
230236 System .out .println ("Disabling " + dbName + "-" + (i + 1 ));
231237 changeProperty (props , "/manage/v2/forests/" + dbName + "-" + (i + 1 ) + "/properties" );
232238 Thread .currentThread ().sleep (1000L );
233- System .out .println ("Restarting server: " + hostNames [i ]);
239+ System .out .println ("Restarting server: " + hostNames [i ]);
234240 serverStartStop (hostNames [i ], "start" );
235241 Thread .currentThread ().sleep (1000L );
236242 System .out .println (new SimpleDateFormat ("yyyy.MM.dd.HH.mm:ss" ).format (new Date ()));
@@ -278,7 +284,7 @@ public void testStopOneNode() throws Exception {
278284 assertEquals ("document count" , 15000 , success .intValue ());
279285 assertEquals ("document count" , 0 , failure .intValue ());
280286 }
281-
287+
282288 @ Test
283289 public void testRestart () throws Exception {
284290 System .out .println (Thread .currentThread ().getStackTrace ()[1 ].getMethodName ());
@@ -503,18 +509,18 @@ public void xQueryMasstransformReplace() throws Exception {
503509 modified .incrementAndGet ();
504510 }
505511 } else {
506- passed .set (false );
512+ passed .set (false );
507513 }
508514 }
509515 });
510516 tempMgr .startJob (readBatcher );
511517 readBatcher .awaitCompletion ();
512- System .out .println ("Modified docs: " + modified .intValue ());
518+ System .out .println ("Modified docs: " + modified .intValue ());
513519 Assert .assertTrue (passed .get ());
514520 assertEquals ("document count" , 15000 , modified .intValue ());
515521 assertEquals ("document count" , 15000 , success .intValue ());
516522 assertEquals ("document count" , 0 , skipped .intValue ());
517-
523+
518524 }
519525
520526 @ Test
@@ -576,13 +582,13 @@ public void xQueryMasstransformReplaceTwoNodes() throws Exception {
576582 modified .incrementAndGet ();
577583 }
578584 } else {
579- passed .set (false );
585+ passed .set (false );
580586 }
581587 }
582588 });
583589 tempMgr .startJob (readBatcher );
584590 readBatcher .awaitCompletion ();
585- System .out .println ("Modified docs: " + modified .intValue ());
591+ System .out .println ("Modified docs: " + modified .intValue ());
586592 Assert .assertTrue (passed .get ());
587593 assertEquals ("document count" , 15000 , modified .intValue ());
588594 assertEquals ("document count" , 15000 , success .intValue ());
@@ -654,13 +660,13 @@ public void xQueryMasstransformReplaceRepeated() throws Exception {
654660 modified .incrementAndGet ();
655661 }
656662 } else {
657- passed .set (false );
663+ passed .set (false );
658664 }
659665 }
660666 });
661667 tempMgr .startJob (readBatcher );
662668 readBatcher .awaitCompletion ();
663- System .out .println ("Modified docs: " + modified .intValue ());
669+ System .out .println ("Modified docs: " + modified .intValue ());
664670 Assert .assertTrue (passed .get ());
665671 assertEquals ("document count" , 15000 , modified .intValue ());
666672 assertEquals ("document count" , 15000 , success .intValue ());
@@ -754,6 +760,7 @@ private void addDocs() {
754760 }
755761 ihb2 .flushAndWait ();
756762 }
763+
757764 private boolean isRunning (String host ) {
758765 try {
759766
@@ -765,7 +772,7 @@ private boolean isRunning(String host) {
765772 HttpResponse response = client .execute (get );
766773 ResponseHandler <String > handler = new BasicResponseHandler ();
767774 String body = handler .handleResponse (response );
768- if (body .contains ("Healthy" )){
775+ if (body .contains ("Healthy" )) {
769776 return true ;
770777 }
771778
0 commit comments