use of org.exist.Database 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());
}
}
use of org.exist.Database in project exist by eXist-db.
the class DocumentImplTest method isSameNode_differentDoc.
@Test
public void isSameNode_differentDoc() {
final BrokerPool mockBrokerPool = EasyMock.createMock(BrokerPool.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
final Group mockCurrentSubjectGroup = EasyMock.createMock(Group.class);
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
// expectations
expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager).times(2);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase).times(2);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker).times(2);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject).times(2);
expect(mockCurrentSubject.getUserMask()).andReturn(Permission.DEFAULT_UMASK).times(2);
expect(mockCurrentSubject.getId()).andReturn(RealmImpl.SYSTEM_ACCOUNT_ID).times(2);
expect(mockCurrentSubject.getDefaultGroup()).andReturn(mockCurrentSubjectGroup).times(2);
expect(mockCurrentSubjectGroup.getId()).andReturn(RealmImpl.DBA_GROUP_ID).times(2);
replay(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
// test setup
final DocumentImpl doc = new DocumentImpl(mockBrokerPool, 99);
final DocumentImpl doc2 = new DocumentImpl(mockBrokerPool, 765);
assertFalse(doc.isSameNode(doc2));
verify(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
}
use of org.exist.Database in project exist by eXist-db.
the class DocumentImplTest method isSameNode_nonDoc.
@Test
public void isSameNode_nonDoc() {
final BrokerPool mockBrokerPool = EasyMock.createMock(BrokerPool.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
final Group mockCurrentSubjectGroup = EasyMock.createMock(Group.class);
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
// expectations
expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject);
expect(mockCurrentSubject.getUserMask()).andReturn(Permission.DEFAULT_UMASK);
expect(mockCurrentSubject.getId()).andReturn(RealmImpl.SYSTEM_ACCOUNT_ID);
expect(mockCurrentSubject.getDefaultGroup()).andReturn(mockCurrentSubjectGroup);
expect(mockCurrentSubjectGroup.getId()).andReturn(RealmImpl.DBA_GROUP_ID);
replay(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
// test setup
final DocumentImpl doc = new DocumentImpl(mockBrokerPool, 99);
final TextImpl text = new TextImpl("hello");
assertFalse(doc.isSameNode(text));
verify(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
}
use of org.exist.Database in project exist by eXist-db.
the class DebuggeeImpl method start.
@Override
public String start(String uri) throws Exception {
Database db = null;
ScriptRunner runner = null;
try {
db = BrokerPool.getInstance();
try (final DBBroker broker = db.getBroker()) {
// Try to find the XQuery
Source source = SourceFactory.getSource(broker, "", uri, true);
if (source == null)
return null;
XQuery xquery = broker.getBrokerPool().getXQueryService();
XQueryContext queryContext = new XQueryContext(broker.getBrokerPool());
// Find correct script load path
queryContext.setModuleLoadPath(XmldbURI.create(uri).removeLastSegment().toString());
CompiledXQuery compiled;
try {
compiled = xquery.compile(broker, queryContext, source);
} catch (IOException e) {
e.printStackTrace();
return null;
}
String sessionId = String.valueOf(queryContext.hashCode());
// link debugger session & script
DebuggeeJointImpl joint = new DebuggeeJointImpl();
SessionImpl session = new SessionImpl();
joint.setCompiledScript(compiled);
queryContext.setDebuggeeJoint(joint);
joint.continuation(new Init(session, sessionId, "eXist"));
runner = new ScriptRunner(session, compiled);
runner.start();
int count = 0;
while (joint.firstExpression == null && runner.exception == null && count < 10) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
count++;
}
if (runner.exception != null) {
throw runner.exception;
}
if (joint.firstExpression == null) {
throw new XPathException("Can't run debug session.");
}
// queryContext.declareVariable(Debuggee.SESSION, sessionId);
// XXX: make sure that it started up
sessions.put(sessionId, session);
return sessionId;
}
} catch (Exception e) {
if (runner != null)
runner.stop();
throw e;
}
}
use of org.exist.Database in project exist by eXist-db.
the class Source method exec.
@Override
public void exec() {
if (fileURI == null) {
return;
}
InputStream is = null;
try {
if (fileURI.toLowerCase().startsWith("dbgp://")) {
String uri = fileURI.substring(7);
if (uri.toLowerCase().startsWith("file:/")) {
uri = fileURI.substring(5);
is = Files.newInputStream(Paths.get(uri));
} else {
XmldbURI pathUri = XmldbURI.create(URLDecoder.decode(fileURI.substring(15), "UTF-8"));
Database db = getJoint().getContext().getDatabase();
try (final DBBroker broker = db.getBroker();
final LockedDocument resource = broker.getXMLResource(pathUri, LockMode.READ_LOCK)) {
if (resource.getDocument().getResourceType() == DocumentImpl.BINARY_FILE) {
is = broker.getBinaryResource((BinaryDocument) resource.getDocument());
} else {
// TODO: xml source???
return;
}
} catch (EXistException e) {
exception = e;
}
}
} else {
URL url = new URL(fileURI);
URLConnection conn = url.openConnection();
is = conn.getInputStream();
}
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
byte[] buf = new byte[256];
int c;
while ((c = is.read(buf)) > -1) {
// TODO: begin & end line should affect
baos.write(buf, 0, c);
}
source = baos.toByteArray();
success = true;
} catch (PermissionDeniedException | IOException e) {
exception = e;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
if (exception == null) {
exception = e;
}
}
}
}
}
Aggregations