* @param forceCorruption Should the database be forcefully corrupted
*/
private void constructedNodeQuery(boolean forceCorruption)
{
BrokerPool.FORCE_CORRUPTION = forceCorruption;
BrokerPool pool = null;
DBBroker broker = null;
try
{
pool = startDB();
assertNotNull(pool);
broker = pool.get(pool.getSecurityManager().getSystemSubject());
TransactionManager transact = pool.getTransactionManager();
assertNotNull(transact);
//only store the documents the first time
if(forceCorruption)
{
//store a first test document
storeTestDocument(broker, transact, "testcr1.xml");
//store a second test document
storeTestDocument(broker, transact, "testcr2.xml");
}
//create some child collections in TEMP collection
createTempChildCollection(broker, transact, "testchild1");
createTempChildCollection(broker, transact, "testchild2");
//execute an xquery
XQuery service = broker.getXQueryService();
assertNotNull(service);
CompiledXQuery compiled = service.compile(service.newContext(AccessContext.TEST), new StringSource(xquery));
assertNotNull(compiled);
Sequence result = service.execute(compiled, null);
assertNotNull(result);
assertEquals(expectedResults.length, result.getItemCount());
for(int i = 0; i < result.getItemCount(); i++)
{
assertEquals(expectedResults[i], (String)result.itemAt(i).getStringValue());
}
//read the first test document
testDocumentIsValid(broker, transact, "testcr1.xml");
//read the second test document
testDocumentIsValid(broker, transact, "testcr1.xml");
//test the child collections exist
testTempChildCollectionExists(broker, transact, "testchild1");
testTempChildCollectionExists(broker, transact, "testchild2");
transact.getJournal().flushToLog(true);
}
catch(Exception e)
{
fail(e.getMessage());
e.printStackTrace();
}
finally
{
if (pool != null) pool.release(broker);
}
}