Search in sources :

Example 1 with ExistEmbeddedServer

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);
    }
}
Also used : Path(java.nio.file.Path) Diff(org.xmlunit.diff.Diff) ExistEmbeddedServer(org.exist.test.ExistEmbeddedServer) LockedDocument(org.exist.dom.persistent.LockedDocument) UUID(java.util.UUID) Properties(java.util.Properties) Source(javax.xml.transform.Source)

Example 2 with ExistEmbeddedServer

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);
}
Also used : ExistEmbeddedServer(org.exist.test.ExistEmbeddedServer) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)2 ExistEmbeddedServer (org.exist.test.ExistEmbeddedServer)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Source (javax.xml.transform.Source)1 LockedDocument (org.exist.dom.persistent.LockedDocument)1 Test (org.junit.Test)1 Diff (org.xmlunit.diff.Diff)1