Search in sources :

Example 11 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class ExistEmbeddedServer method startDb.

public void startDb() throws DatabaseConfigurationException, EXistException, IOException {
    if (pool == null) {
        if (disableAutoDeploy) {
            this.prevAutoDeploy = System.getProperty(AUTODEPLOY_PROPERTY, "off");
            System.setProperty(AUTODEPLOY_PROPERTY, "off");
        }
        final String name = instanceName.orElse(BrokerPool.DEFAULT_INSTANCE_NAME);
        final Optional<Path> home = Optional.ofNullable(System.getProperty("exist.home", System.getProperty("user.dir"))).map(Paths::get);
        final Path confFile = configFile.orElseGet(() -> ConfigurationHelper.lookup("conf.xml", home));
        final Configuration config;
        if (confFile.isAbsolute() && Files.exists(confFile)) {
            // TODO(AR) is this correct?
            config = new Configuration(confFile.toAbsolutePath().toString());
        } else {
            config = new Configuration(FileUtils.fileName(confFile), home);
        }
        // override any specified config properties
        configProperties.ifPresent(properties -> {
            for (final Map.Entry<Object, Object> configProperty : properties.entrySet()) {
                config.setProperty(configProperty.getKey().toString(), configProperty.getValue());
            }
        });
        if (useTemporaryStorage) {
            if (!temporaryStorage.isPresent()) {
                this.temporaryStorage = Optional.of(Files.createTempDirectory("org.exist.test.ExistEmbeddedServer"));
            }
            config.setProperty(BrokerPool.PROPERTY_DATA_DIR, temporaryStorage.get());
            config.setProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR, temporaryStorage.get());
            LOG.info("Using temporary storage location: {}", temporaryStorage.get().toAbsolutePath().toString());
        }
        BrokerPool.configure(name, 1, 5, config, Optional.empty());
        this.pool = BrokerPool.getInstance(name);
    } else {
        throw new IllegalStateException("ExistEmbeddedServer already running");
    }
}
Also used : Path(java.nio.file.Path) Configuration(org.exist.util.Configuration) Paths(java.nio.file.Paths) Map(java.util.Map)

Example 12 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class XQueryTestRunner method getConfiguration.

private static Configuration getConfiguration() throws DatabaseConfigurationException {
    final Optional<Path> home = Optional.ofNullable(System.getProperty("exist.home", System.getProperty("user.dir"))).map(Paths::get);
    final Path confFile = ConfigurationHelper.lookup("conf.xml", home);
    if (confFile.isAbsolute() && Files.exists(confFile)) {
        return new Configuration(confFile.toAbsolutePath().toString());
    } else {
        return new Configuration(FileUtils.fileName(confFile), home);
    }
}
Also used : Path(java.nio.file.Path) Configuration(org.exist.util.Configuration) Paths(java.nio.file.Paths)

Example 13 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class BrokerPoolsTest method shutdownConcurrent.

@Test
public void shutdownConcurrent() throws InterruptedException, ExecutionException, EXistException, DatabaseConfigurationException, IOException {
    final int testThreads = 5;
    final CountDownLatch shutdownLatch = new CountDownLatch(1);
    final CountDownLatch acquiredLatch = new CountDownLatch(testThreads);
    final List<Future<Exception>> shutdownTasks = new ArrayList<>();
    final ExecutorService executorService = Executors.newFixedThreadPool(testThreads);
    for (int i = 0; i < testThreads; i++) {
        final Path dataDir = temporaryFolder.newFolder("exist" + i).toPath().normalize().toAbsolutePath();
        // load config from classpath and override data and journal dir
        final Configuration configuration = new Configuration("conf.xml");
        configuration.setProperty(BrokerPool.PROPERTY_DATA_DIR, dataDir);
        configuration.setProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR, dataDir);
        BrokerPool.configure("instance" + i, 0, 1, configuration);
        shutdownTasks.add(executorService.submit(new BrokerPoolShutdownTask(acquiredLatch, shutdownLatch)));
    }
    // wait for all shutdown threads to be acquired
    acquiredLatch.await();
    shutdownLatch.countDown();
    executorService.shutdown();
    assertTrue(executorService.awaitTermination(8, TimeUnit.SECONDS));
    for (final Future<Exception> shutdownTask : shutdownTasks) {
        assertNull(shutdownTask.get());
    }
}
Also used : Path(java.nio.file.Path) Configuration(org.exist.util.Configuration) IOException(java.io.IOException) EXistException(org.exist.EXistException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) Test(org.junit.Test)

Example 14 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class GetReleaseBrokerDeadlocks method exterServiceMode.

@Test
@Ignore
public void exterServiceMode() {
    try {
        Configuration config = new Configuration();
        config.setProperty(FunctionFactory.PROPERTY_DISABLE_DEPRECATED_FUNCTIONS, Boolean.FALSE);
        BrokerPool.configure(1, 5, config);
        Database db = BrokerPool.getInstance();
        Thread thread = new Thread(db.getThreadGroup(), new EnterServiceMode());
        try (final DBBroker broker = db.getBroker()) {
            thread.start();
            Thread.sleep(1000);
        }
        Thread.sleep(1000);
        assertFalse(thread.isAlive());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Configuration(org.exist.util.Configuration) Database(org.exist.Database) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class GetReleaseBrokerDeadlocks method testingGetReleaseCycle.

@Test
@Ignore
public void testingGetReleaseCycle() {
    boolean debug = false;
    try {
        Configuration config = new Configuration();
        config.setProperty(FunctionFactory.PROPERTY_DISABLE_DEPRECATED_FUNCTIONS, new Boolean(false));
        BrokerPool.configure(1, 5, config);
        Database db = BrokerPool.getInstance();
        Thread thread;
        for (int i = 0; i < 1000; i++) {
            thread = new Thread(db.getThreadGroup(), new GetRelease());
            thread.start();
            Thread.sleep(rd.nextInt(250));
            if (ex != null) {
                LOG.error(ex.getMessage(), ex);
                fail(ex.getMessage());
            }
            if (debug && db.countActiveBrokers() == 20) {
                Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
                StringBuilder sb = new StringBuilder();
                sb.append("************************************************\n");
                sb.append("************************************************\n");
                for (Map.Entry<Thread, StackTraceElement[]> entry : stackTraces.entrySet()) {
                    StackTraceElement[] stacks = entry.getValue();
                    sb.append("THREAD: ");
                    sb.append(entry.getKey().getName());
                    sb.append("\n");
                    for (int n = 0; n < stacks.length; n++) {
                        sb.append(" ");
                        sb.append(stacks[n]);
                        sb.append("\n");
                    }
                }
                if (stackTraces.isEmpty())
                    sb.append("No threads.");
            // System.out.println(sb.toString());
            }
        }
        while (db.countActiveBrokers() > 0) {
            Thread.sleep(100);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : Configuration(org.exist.util.Configuration) Database(org.exist.Database) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Configuration (org.exist.util.Configuration)30 Test (org.junit.Test)10 Path (java.nio.file.Path)9 EXistException (org.exist.EXistException)8 IOException (java.io.IOException)7 BrokerPool (org.exist.storage.BrokerPool)6 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)6 InputStream (java.io.InputStream)4 Scheduler (org.exist.scheduler.Scheduler)4 DBBroker (org.exist.storage.DBBroker)4 Paths (java.nio.file.Paths)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 Subject (org.exist.security.Subject)3 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 Database (org.exist.Database)2 AuthenticationException (org.exist.security.AuthenticationException)2 SecurityManager (org.exist.security.SecurityManager)2 Ignore (org.junit.Ignore)2