Skip to content

Commit 9968afe

Browse files
georgeajitgeorgeajit
authored andcommitted
No Task - Run no setups for one node environments.
1 parent 4318252 commit 9968afe

File tree

2 files changed

+292
-261
lines changed

2 files changed

+292
-261
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/QBFailover.java

Lines changed: 156 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -101,110 +101,111 @@ public static void setUpBeforeClass() throws Exception {
101101
port = getRestAppServerPort();
102102

103103
hostNames = getHosts();
104-
// Add all possible hostnames and pick a random one to create a client
105-
List<String> hostLists = new ArrayList<String>();
106-
String localhost = InetAddress.getLocalHost().getHostName().toLowerCase();
107-
Pattern pattern = Pattern.compile(localhost + "(.*)");
108-
Matcher matcher = pattern.matcher(hostNames[0]);
109-
String domain = null;
110-
if (matcher.find()) {
111-
domain = matcher.group(1);
112-
}
113-
for (String host : hostNames) {
114-
hostLists.add(host);
115-
pattern = Pattern.compile("(.*)" + domain);
116-
matcher = pattern.matcher(host);
104+
// Perform the setup on multiple nodes only.
105+
if (hostNames.length > 1) {
106+
// Add all possible hostnames and pick a random one to create a client
107+
List<String> hostLists = new ArrayList<String>();
108+
String localhost = InetAddress.getLocalHost().getHostName().toLowerCase();
109+
Pattern pattern = Pattern.compile(localhost + "(.*)");
110+
Matcher matcher = pattern.matcher(hostNames[0]);
111+
String domain = null;
117112
if (matcher.find()) {
118-
hostLists.add(matcher.group(1));
113+
domain = matcher.group(1);
119114
}
120-
}
121-
hostLists.add("localhost");
122-
int index = new Random().nextInt(hostLists.size());
123-
dbClient = DatabaseClientFactory.newClient(hostLists.get(index), port, user, password, Authentication.DIGEST);
124-
evalClient = DatabaseClientFactory.newClient(host, port, user, password, Authentication.DIGEST);
125-
System.out.println("Connected to: " + dbClient.getHost());
126-
dmManager = dbClient.newDataMovementManager();
127-
tempMgr = evalClient.newDataMovementManager();
128-
129-
Map<String, String> props = new HashMap<>();
130-
String version = String.valueOf(evalClient.newServerEval().xquery("xquery version \"1.0-ml\"; xdmp:version()")
131-
.eval().next().getString().charAt(0));
132-
if (OS.indexOf("win") >= 0) {
133-
Properties prop = new Properties();
134-
InputStream input = null;
135-
String location = null;
136-
String seperator = File.separator;
137-
try {
138-
input = new FileInputStream(System.getProperty("user.dir") + seperator + ".." + seperator + ".."
139-
+ seperator + "qa" + seperator + "failover-location.properties");
140-
prop.load(input);
141-
location = prop.getProperty("location");
142-
System.out.println(prop.getProperty("location"));
143-
} catch (IOException ex) {
144-
ex.printStackTrace();
145-
Assert.fail("Forest location file not found");
146-
} finally {
147-
if (input != null) {
148-
try {
149-
input.close();
150-
} catch (IOException e) {
151-
e.printStackTrace();
152-
Assert.fail("Forest location file not found");
115+
for (String host : hostNames) {
116+
hostLists.add(host);
117+
pattern = Pattern.compile("(.*)" + domain);
118+
matcher = pattern.matcher(host);
119+
if (matcher.find()) {
120+
hostLists.add(matcher.group(1));
121+
}
122+
}
123+
hostLists.add("localhost");
124+
int index = new Random().nextInt(hostLists.size());
125+
dbClient = DatabaseClientFactory.newClient(hostLists.get(index), port, user, password,
126+
Authentication.DIGEST);
127+
evalClient = DatabaseClientFactory.newClient(host, port, user, password, Authentication.DIGEST);
128+
System.out.println("Connected to: " + dbClient.getHost());
129+
dmManager = dbClient.newDataMovementManager();
130+
tempMgr = evalClient.newDataMovementManager();
131+
Map<String, String> props = new HashMap<>();
132+
String version = String.valueOf(evalClient.newServerEval()
133+
.xquery("xquery version \"1.0-ml\"; xdmp:version()").eval().next().getString().charAt(0));
134+
if (OS.indexOf("win") >= 0) {
135+
Properties prop = new Properties();
136+
InputStream input = null;
137+
String location = null;
138+
String seperator = File.separator;
139+
try {
140+
input = new FileInputStream(System.getProperty("user.dir") + seperator + ".." + seperator + ".."
141+
+ seperator + "qa" + seperator + "failover-location.properties");
142+
prop.load(input);
143+
location = prop.getProperty("location");
144+
System.out.println(prop.getProperty("location"));
145+
} catch (IOException ex) {
146+
ex.printStackTrace();
147+
Assert.fail("Forest location file not found");
148+
} finally {
149+
if (input != null) {
150+
try {
151+
input.close();
152+
} catch (IOException e) {
153+
e.printStackTrace();
154+
Assert.fail("Forest location file not found");
155+
}
153156
}
154157
}
158+
dataDir = location + "/space/dmsdk-failover/win/" + version + "/temp-";
159+
} else if (OS.indexOf("nux") >= 0) {
160+
dataDir = "/project/qa-netapp/space/dmsdk-failover/linux/" + version + "/temp-";
161+
} else if (OS.indexOf("mac") >= 0) {
162+
dataDir = "/project/qa-netapp/space/dmsdk-failover/mac/" + version + "/temp-";
163+
} else {
164+
Assert.fail("Unsupported platform");
155165
}
156-
dataDir = location + "/space/dmsdk-failover/win/" + version + "/temp-";
157-
} else if (OS.indexOf("nux") >= 0) {
158-
dataDir = "/project/qa-netapp/space/dmsdk-failover/linux/" + version + "/temp-";
159-
} else if (OS.indexOf("mac") >= 0) {
160-
dataDir = "/project/qa-netapp/space/dmsdk-failover/mac/" + version + "/temp-";
161-
} else {
162-
Assert.fail("Unsupported platform");
163-
}
166+
createDB(dbName);
167+
Thread.currentThread().sleep(500L);
168+
for (int i = 0; i < hostNames.length; i++) {
169+
if (i != 0) {
170+
createForest(dbName + "-" + (i + 1), hostNames[i], dataDir + (i + 1), hostNames[0]);
171+
} else {
172+
createForest(dbName + "-" + (i + 1), hostNames[i], dataDir + (i + 1), null);
164173

165-
createDB(dbName);
166-
Thread.currentThread().sleep(500L);
167-
for (int i = 0; i < hostNames.length; i++) {
168-
if (i != 0) {
169-
createForest(dbName + "-" + (i + 1), hostNames[i], dataDir + (i + 1), hostNames[0]);
170-
} else {
171-
createForest(dbName + "-" + (i + 1), hostNames[i], dataDir + (i + 1), null);
174+
}
175+
props.put("database", dbName);
176+
props.put("state", "attach");
177+
postRequest(null, props, "/manage/v2/forests/" + dbName + "-" + (i + 1));
172178

179+
Thread.currentThread().sleep(500L);
173180
}
174-
props.put("database", dbName);
175-
props.put("state", "attach");
176-
postRequest(null, props, "/manage/v2/forests/" + dbName + "-" + (i + 1));
177-
181+
props = new HashMap<>();
182+
props.put("journaling", "strict");
183+
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
178184
Thread.currentThread().sleep(500L);
185+
// Create App Server if needed.
186+
createRESTServerWithDB(server, port);
187+
associateRESTServerWithDB(server, dbName);
188+
// StringHandle
189+
stringTriple = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>This is so foo</foo>";
190+
stringHandle = new StringHandle(stringTriple);
191+
stringHandle.setFormat(Format.XML);
192+
meta2 = new DocumentMetadataHandle().withCollections("XmlTransform");
193+
meta2.setFormat(Format.XML);
194+
// Xquery transformation
195+
TransformExtensionsManager transMgr = dbClient.newServerConfigManager().newTransformExtensionsManager();
196+
ExtensionMetadata metadata = new ExtensionMetadata();
197+
metadata.setTitle("Adding attribute xquery Transform");
198+
metadata.setDescription("This plugin transforms an XML document by adding attribute to root node");
199+
metadata.setProvider("MarkLogic");
200+
metadata.setVersion("0.1");
201+
// get the transform file
202+
File transformFile = FileUtils
203+
.toFile(WriteHostBatcherTest.class.getResource(TEST_DIR_PREFIX + "add-attr-xquery-transform.xqy"));
204+
FileHandle transformHandle = new FileHandle(transformFile);
205+
transMgr.writeXQueryTransform("add-attr-xquery-transform", transformHandle, metadata);
206+
} else {
207+
System.out.println("Test skipped - setUpBeforeClass");
179208
}
180-
props = new HashMap<>();
181-
props.put("journaling", "strict");
182-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
183-
Thread.currentThread().sleep(500L);
184-
// Create App Server if needed.
185-
createRESTServerWithDB(server, port);
186-
associateRESTServerWithDB(server, dbName);
187-
188-
// StringHandle
189-
stringTriple = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>This is so foo</foo>";
190-
stringHandle = new StringHandle(stringTriple);
191-
stringHandle.setFormat(Format.XML);
192-
meta2 = new DocumentMetadataHandle().withCollections("XmlTransform");
193-
meta2.setFormat(Format.XML);
194-
195-
// Xquery transformation
196-
TransformExtensionsManager transMgr = dbClient.newServerConfigManager().newTransformExtensionsManager();
197-
ExtensionMetadata metadata = new ExtensionMetadata();
198-
metadata.setTitle("Adding attribute xquery Transform");
199-
metadata.setDescription("This plugin transforms an XML document by adding attribute to root node");
200-
metadata.setProvider("MarkLogic");
201-
metadata.setVersion("0.1");
202-
// get the transform file
203-
File transformFile = FileUtils
204-
.toFile(WriteHostBatcherTest.class.getResource(TEST_DIR_PREFIX + "add-attr-xquery-transform.xqy"));
205-
FileHandle transformHandle = new FileHandle(transformFile);
206-
transMgr.writeXQueryTransform("add-attr-xquery-transform", transformHandle, metadata);
207-
208209
}
209210

210211
private static void createForest(String forestName, String hostname, String dataDir, String failoverHost) {
@@ -224,64 +225,80 @@ private static void createForest(String forestName, String hostname, String data
224225

225226
@AfterClass
226227
public static void tearDownAfterClass() throws Exception {
227-
associateRESTServerWithDB(server, "Documents");
228-
for (int i = 0; i < hostNames.length; i++) {
229-
System.out.println(dbName + "-" + (i + 1));
230-
detachForest(dbName, dbName + "-" + (i + 1));
231-
deleteForest(dbName + "-" + (i + 1));
228+
// Perform the setup on multiple nodes only.
229+
if (hostNames.length > 1) {
230+
associateRESTServerWithDB(server, "Documents");
231+
for (int i = 0; i < hostNames.length; i++) {
232+
System.out.println(dbName + "-" + (i + 1));
233+
detachForest(dbName, dbName + "-" + (i + 1));
234+
deleteForest(dbName + "-" + (i + 1));
235+
}
236+
deleteDB(dbName);
237+
} else {
238+
System.out.println("Test skipped - tearDownAfterClass");
232239
}
233-
deleteDB(dbName);
234240
}
235241

236242
@Before
237243
public void setUp() throws Exception {
238-
for (int i = 0; i < hostNames.length; i++) {
239-
if (!isRunning(hostNames[i])) {
240-
serverStartStop(hostNames[i], "start");
244+
// Perform the setup on multiple nodes only.
245+
if (hostNames.length > 1) {
246+
for (int i = 0; i < hostNames.length; i++) {
247+
if (!isRunning(hostNames[i])) {
248+
serverStartStop(hostNames[i], "start");
249+
}
250+
Assert.assertTrue(isRunning(hostNames[i]));
241251
}
242-
Assert.assertTrue(isRunning(hostNames[i]));
243-
}
244-
if (!(evalClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0)) {
245-
clearDB(port);
252+
if (!(evalClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0)) {
253+
clearDB(port);
254+
}
255+
Assert.assertTrue(evalClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0);
256+
ForestConfiguration fc = dmManager.readForestConfig();
257+
Forest[] f = fc.listForests();
258+
f = (Forest[]) Arrays.stream(f).filter(x -> x.getDatabaseName().equals(dbName)).collect(Collectors.toList())
259+
.toArray(new Forest[hostNames.length]);
260+
Assert.assertEquals(f.length, hostNames.length);
261+
Assert.assertEquals(f.length, 3L);
262+
addDocs();
263+
Assert.assertTrue(
264+
evalClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 20000);
265+
} else {
266+
System.out.println("Test skipped - setUp");
246267
}
247-
Assert.assertTrue(evalClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0);
248-
ForestConfiguration fc = dmManager.readForestConfig();
249-
Forest[] f = fc.listForests();
250-
f = (Forest[]) Arrays.stream(f).filter(x -> x.getDatabaseName().equals(dbName)).collect(Collectors.toList())
251-
.toArray(new Forest[hostNames.length]);
252-
Assert.assertEquals(f.length, hostNames.length);
253-
Assert.assertEquals(f.length, 3L);
254-
addDocs();
255-
Assert.assertTrue(evalClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 20000);
256268
}
257269

258270
@After
259271
public void tearDown() throws Exception {
260-
Map<String, String> props = new HashMap<>();
261-
props.put("database", dbName);
262-
System.out.println("Restarting servers");
263-
for (int i = hostNames.length - 1; i >= 1; i--) {
264-
props.put("enabled", "false");
265-
System.out.println(new SimpleDateFormat("yyyy.MM.dd.HH.mm:ss").format(new Date()));
266-
System.out.println("Disabling " + dbName + "-" + (i + 1));
267-
changeProperty(props, "/manage/v2/forests/" + dbName + "-" + (i + 1) + "/properties");
268-
Thread.currentThread().sleep(1000L);
269-
System.out.println("Restarting server: " + hostNames[i]);
270-
try {
271-
serverStartStop(hostNames[i], "start");
272-
} catch (Exception e) {
273-
e.printStackTrace();
272+
// Perform the setup on multiple nodes only.
273+
if (hostNames.length > 1) {
274+
Map<String, String> props = new HashMap<>();
275+
props.put("database", dbName);
276+
System.out.println("Restarting servers");
277+
for (int i = hostNames.length - 1; i >= 1; i--) {
278+
props.put("enabled", "false");
279+
System.out.println(new SimpleDateFormat("yyyy.MM.dd.HH.mm:ss").format(new Date()));
280+
System.out.println("Disabling " + dbName + "-" + (i + 1));
281+
changeProperty(props, "/manage/v2/forests/" + dbName + "-" + (i + 1) + "/properties");
282+
Thread.currentThread().sleep(1000L);
283+
System.out.println("Restarting server: " + hostNames[i]);
284+
try {
285+
serverStartStop(hostNames[i], "start");
286+
} catch (Exception e) {
287+
e.printStackTrace();
288+
}
289+
Thread.currentThread().sleep(1000L);
290+
System.out.println(new SimpleDateFormat("yyyy.MM.dd.HH.mm:ss").format(new Date()));
291+
System.out.println("Enabling " + dbName + "-" + (i + 1));
292+
props.put("enabled", "true");
293+
changeProperty(props, "/manage/v2/forests/" + dbName + "-" + (i + 1) + "/properties");
294+
Thread.currentThread().sleep(1000L);
274295
}
275-
Thread.currentThread().sleep(1000L);
276-
System.out.println(new SimpleDateFormat("yyyy.MM.dd.HH.mm:ss").format(new Date()));
277-
System.out.println("Enabling " + dbName + "-" + (i + 1));
278-
props.put("enabled", "true");
279-
changeProperty(props, "/manage/v2/forests/" + dbName + "-" + (i + 1) + "/properties");
280-
Thread.currentThread().sleep(1000L);
296+
Thread.currentThread().sleep(3000L);
297+
System.out.println("Clearin DB");
298+
clearDB(port);
299+
} else {
300+
System.out.println("Test skipped - tearDown");
281301
}
282-
Thread.currentThread().sleep(3000L);
283-
System.out.println("Clearin DB");
284-
clearDB(port);
285302
}
286303

287304
@Test(timeout = 450000)

0 commit comments

Comments
 (0)