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");
}
}
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);
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations