@Before public void setUp() throws Exception { dialect = (Dialect) applicationContext.getBean("dialect"); if (dialect instanceof PostgreSQLDialect) { // Note: PostgreSQL does not support \u0000 char embedded in a string // http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00115.php COMPLEX_LOCAL_NAME = COMPLEX_LOCAL_NAME_NO_U0000; } serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); transactionService = serviceRegistry.getTransactionService(); dictionaryService = BaseNodeServiceTest.loadModel(applicationContext); nodeService = serviceRegistry.getNodeService(); this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); this.authenticationComponent.setSystemUserAsCurrentUser(); // get the indexer and searcher factory IndexerAndSearcher indexerAndSearcher = (IndexerAndSearcher) applicationContext.getBean("indexerAndSearcherFactory"); searcher = new SearcherComponent(); searcher.setIndexerAndSearcherFactory(indexerAndSearcher); // create a test workspace StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + "_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); // begin a transaction txn = transactionService.getUserTransaction(); txn.begin(); }
@Test @Category(RedundantTests.class) public void testEphemeralLockIndexing() { TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, authenticationService); IndexerAndSearcher indexerAndSearcher = (IndexerAndSearcher) applicationContext.getBean("indexerAndSearcherFactory"); SearcherComponent searcher = new SearcherComponent(); searcher.setIndexerAndSearcherFactory(indexerAndSearcher); // Create a lock (owned by the current user) lockService.lock(noAspectNode, LockType.WRITE_LOCK, 86400, Lifetime.EPHEMERAL); // Query for the user's locks final String query = String.format("+@cm\\:lockOwner:\"%s\" +@cm\\:lockType:\"WRITE_LOCK\"", GOOD_USER_NAME); ResultSet rs = searcher.query(storeRef, "lucene", query); assertTrue(rs.getNodeRefs().contains(noAspectNode)); // Unlock the node lockService.unlock(noAspectNode); // Perform a new search, the index should reflect that it is not locked. rs = searcher.query(storeRef, "lucene", query); assertFalse(rs.getNodeRefs().contains(noAspectNode)); }