Revision 6789
Added by ben leinfelder about 13 years ago
test/edu/ucsb/nceas/metacat/replication/ReplicationTest.java | ||
---|---|---|
99 | 99 |
suite.addTest(new ReplicationTest("testCertificate")); |
100 | 100 |
suite.addTest(new ReplicationTest("testReplicateData_AtoB")); |
101 | 101 |
suite.addTest(new ReplicationTest("testReplicateEML_AtoB")); |
102 |
suite.addTest(new ReplicationTest("testReplicateDataLocking")); |
|
102 | 103 |
|
103 | 104 |
return suite; |
104 | 105 |
} |
... | ... | |
309 | 310 |
} |
310 | 311 |
} |
311 | 312 |
|
313 |
public void testReplicateDataLocking() { |
|
314 |
try { |
|
315 |
// the id |
|
316 |
String baseDocid = DocumentUtil.generateDocumentId("replicationTest", 0); |
|
317 |
String docid = baseDocid + "." + 1; |
|
318 |
|
|
319 |
// the test data |
|
320 |
String object = "test"; |
|
321 |
|
|
322 |
// insert data locally |
|
323 |
m.login(username, password); |
|
324 |
m.upload(docid, "testObject", IOUtils.toInputStream(object, MetaCatServlet.DEFAULT_ENCODING), object.getBytes(MetaCatServlet.DEFAULT_ENCODING).length); |
|
325 |
|
|
326 |
// wait for replication (forced) |
|
327 |
Thread.sleep(forceReplicationSleep); |
|
328 |
|
|
329 |
// check the target for the same data |
|
330 |
targetMetacat.login(username, password); |
|
331 |
InputStream is = targetMetacat.read(docid); |
|
332 |
String replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING); |
|
333 |
|
|
334 |
assertEquals(object, replicatedObject); |
|
335 |
|
|
336 |
// update the object on the target |
|
337 |
docid = baseDocid + "." + 2; |
|
338 |
object = "test2"; |
|
339 |
targetMetacat.upload(docid, "testObject", IOUtils.toInputStream(object, MetaCatServlet.DEFAULT_ENCODING), object.getBytes(MetaCatServlet.DEFAULT_ENCODING).length); |
|
340 |
|
|
341 |
// wait for replication (forced) |
|
342 |
Thread.sleep(forceReplicationSleep); |
|
343 |
|
|
344 |
// check the original has the result |
|
345 |
is = m.read(docid); |
|
346 |
replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING); |
|
347 |
|
|
348 |
assertEquals(object, replicatedObject); |
|
349 |
|
|
350 |
// delete the object |
|
351 |
targetMetacat.delete(docid); |
|
352 |
|
|
353 |
// wait for replication (forced) |
|
354 |
Thread.sleep(forceReplicationSleep); |
|
355 |
|
|
356 |
// check that it is missing |
|
357 |
replicatedObject = null; |
|
358 |
try { |
|
359 |
is = m.read(docid); |
|
360 |
replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING); |
|
361 |
} catch (DocumentNotFoundException dnfe) { |
|
362 |
// expect this |
|
363 |
assertTrue(true); |
|
364 |
} |
|
365 |
assertNull(replicatedObject); |
|
366 |
|
|
367 |
|
|
368 |
} catch (Exception e) { |
|
369 |
e.printStackTrace(); |
|
370 |
fail(e.getMessage()); |
|
371 |
} |
|
372 |
} |
|
373 |
|
|
312 | 374 |
|
313 | 375 |
} |
314 | 376 |
|
Also available in: Unified diff
add test for data locking