use of org.exist.test.ExistEmbeddedServer in project exist by eXist-db.
the class ConcurrentBrokerPoolTest method validateStoredDoc.
private void validateStoredDoc(final Tuple2<Path, UUID> pathUuid) throws EXistException, IOException, DatabaseConfigurationException, PermissionDeniedException, URISyntaxException {
final Path dataDir = pathUuid._1;
assertTrue(Files.exists(dataDir));
final UUID uuid = pathUuid._2;
final Properties config = new Properties();
config.put(BrokerPool.PROPERTY_DATA_DIR, dataDir);
config.put(Journal.PROPERTY_RECOVERY_JOURNAL_DIR, dataDir);
final ExistEmbeddedServer server = new ExistEmbeddedServer("validate-" + uuid.toString(), getConfigFile(getClass()), config, true, false);
server.startDb();
try {
try (final DBBroker broker = server.getBrokerPool().getBroker()) {
try (final LockedDocument doc = broker.getXMLResource(XmldbURI.DB.append(docName(uuid)), Lock.LockMode.READ_LOCK)) {
assertNotNull(doc);
final Source expected = Input.fromString(docContent(uuid)).build();
final Source actual = Input.fromNode(doc.getDocument()).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
// ASSERT
assertFalse(diff.toString(), diff.hasDifferences());
}
}
} finally {
server.stopDb();
// clear temp files
FileUtils.deleteQuietly(dataDir);
}
}
use of org.exist.test.ExistEmbeddedServer in project exist by eXist-db.
the class BrokerPoolServiceTest method backgroundJobsShutdownCleanly.
/**
* This test registers a custom BrokerPoolService
* and then runs the database.
*
* The custom BrokerPoolService launches a bunch of
* background jobs when the database starts, and then
* attempts to stop them cleanly when the database
* stops.
*/
@Test
public void backgroundJobsShutdownCleanly() throws EXistException, IOException, DatabaseConfigurationException, InterruptedException, ExecutionException {
// Create and add our BackgroundJobsBrokerPoolService to the BrokerPool
final BrokerPoolService testBrokerPoolService = new BackgroundJobsBrokerPoolService(futures);
final Properties configProps = new Properties();
configProps.put("exist.testBrokerPoolService", testBrokerPoolService);
// run the database
final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer(configProps, true, true);
existEmbeddedServer.startDb();
try {
// do nothing for a while (background jobs will be running)
Thread.sleep(3000);
} finally {
existEmbeddedServer.stopDb();
}
// check results
int totalBackgroundJobResults = 0;
for (final Future<List<BackgroundJobsBrokerPoolService.TimestampAndId>> future : futures) {
try {
final List<BackgroundJobsBrokerPoolService.TimestampAndId> backgroundJobResult = future.get();
// should contain at least 1 result
assertTrue(backgroundJobResult.size() >= 1);
totalBackgroundJobResults += backgroundJobResult.size();
} catch (final CancellationException e) {
// ignore as the background job was cancelled OK
} catch (final ExecutionException e) {
// a background task threw an exception... shouldn't happen, so throw it!
throw e;
} catch (final InterruptedException e) {
// interrupted while waiting on the future, can't recover...
// restore interrupt flag status
Thread.currentThread().interrupt();
throw e;
}
}
assertTrue(totalBackgroundJobResults > 0);
}
Aggregations