protected void checkLeaks() {
   int finalOpenSessions = CoreInstance.getInstance().getNumberOfSessions();
   int leakedOpenSessions = finalOpenSessions - initialOpenSessions;
   if (leakedOpenSessions != 0) {
     log.error(
         String.format(
             "There are %s open session(s) at tear down; it seems "
                 + "the test leaked %s session(s).",
             Integer.valueOf(finalOpenSessions), Integer.valueOf(leakedOpenSessions)));
     for (CoreInstance.RegistrationInfo info : CoreInstance.getInstance().getRegistrationInfos()) {
       log.warn("Leaking session", info);
     }
   }
   int finalSingleConnections = ConnectionHelper.countConnectionReferences();
   int leakedSingleConnections = finalSingleConnections - initialSingleConnections;
   if (leakedSingleConnections > 0) {
     log.error(
         String.format(
             "There are %s single datasource connection(s) open at tear down; "
                 + "the test leaked %s connection(s).",
             Integer.valueOf(finalSingleConnections), Integer.valueOf(leakedSingleConnections)));
   }
   ConnectionHelper.clearConnectionReferences();
 }
Ejemplo n.º 2
0
  /**
   * Check that for two different repositories we get the connections from two different pools. If
   * not, TransactionCachingInterceptor will return a session from the first repository when asked
   * for a new session for the second repository.
   */
  @Test
  public void testMultipleRepositoriesPerTransaction() throws Exception {
    // config for second repo available only for H2
    assumeTrue("Test only works with H2", database.isVCSH2());

    DatabaseH2 db = (DatabaseH2) DatabaseHelper.DATABASE;
    db.setUp2();
    deployContrib(
        "org.nuxeo.ecm.core.storage.sql.test", "OSGI-INF/test-pooling-h2-repo2-contrib.xml");
    // open a second repository
    try (CoreSession session2 =
        CoreInstance.openCoreSession(
            database.getRepositoryName() + "2", SecurityConstants.ADMINISTRATOR)) {
      doTestMultipleRepositoriesPerTransaction(session2);
    }
  }
 public synchronized void run() {
   TransactionHelper.startTransaction(transactionTimeout);
   synchronized (this) {
     if (isRunning) {
       throw new IllegalStateException("Task already running");
     }
     isRunning = true;
     // versions have no path, target document can be null
     if (rootSource == null) {
       isRunning = false;
       throw new IllegalArgumentException("source node must be specified");
     }
   }
   try {
     session = CoreInstance.openCoreSessionSystem(repositoryName);
     log.info("Starting new import task");
     if (rootDoc != null) {
       // reopen the root to be sure the session is valid
       rootDoc = session.getDocument(rootDoc.getRef());
     }
     recursiveCreateDocumentFromNode(rootDoc, rootSource);
     session.save();
     GenericMultiThreadedImporter.addCreatedDoc(taskId, uploadedFiles);
     TransactionHelper.commitOrRollbackTransaction();
   } catch (Exception e) { // deals with interrupt below
     log.error("Error during import", e);
     ExceptionUtils.checkInterrupt(e);
     notifyImportError();
   } finally {
     log.info("End of task");
     if (session != null) {
       session.close();
       session = null;
     }
     synchronized (this) {
       isRunning = false;
     }
   }
 }
 protected static CoreSession getSessionFromDoc(DocumentModel doc) {
   return CoreInstance.getInstance().getSession(doc.getSessionId());
 }
Ejemplo n.º 5
0
 protected CoreSession getRestrictedSession(String userName) {
   RepositoryManager rm = Framework.getLocalService(RepositoryManager.class);
   Map<String, Serializable> ctx = new HashMap<>();
   ctx.put("principal", new UserPrincipal(userName, null, false, false));
   return CoreInstance.openCoreSession(rm.getDefaultRepositoryName(), ctx);
 }
 public CoreSession openSessionAs(NuxeoPrincipal principal) throws ClientException {
   return CoreInstance.openCoreSession(repositoryName, principal);
 }
 public CoreSession openSessionAs(String username) throws ClientException {
   return CoreInstance.openCoreSession(repositoryName, username);
 }
 protected void initCheckLeaks() {
   initialOpenSessions = CoreInstance.getInstance().getNumberOfSessions();
   initialSingleConnections = ConnectionHelper.countConnectionReferences();
 }
Ejemplo n.º 9
0
 protected CoreSession openSessionAs(String username) {
   return CoreInstance.openCoreSession(session.getRepositoryName(), username);
 }
Ejemplo n.º 10
0
 @Override
 public void close() {
   CoreInstance.closeCoreSession(this); // calls back destroy()
 }
Ejemplo n.º 11
0
 protected CoreSession getCoreSession() {
   String coreSessionId = treeRoot == null ? sessionId : treeRoot.getSessionId();
   return CoreInstance.getInstance().getSession(coreSessionId);
 }