JcrRepository implements org.modeshape.jcr.api.Repository { void start() throws Exception { doStart(); } protected  JcrRepository( RepositoryConfiguration configuration ); State getState(); @Override String getName(); @Override int getActiveSessionsCount(); RepositoryStatistics getRepositoryStatistics(); Problems getStartupProblems(); Transactions transactions(); RepositoryConfiguration getConfiguration(); @Override String getDescriptor( String key ); @Override JcrValue getDescriptorValue( String key ); @Override JcrValue[] getDescriptorValues( String key ); @Override boolean isSingleValueDescriptor( String key ); @Override boolean isStandardDescriptor( String key ); @Override String[] getDescriptorKeys(); @Override synchronized JcrSession login(); @Override synchronized JcrSession login( Credentials credentials ); @Override synchronized JcrSession login( String workspaceName ); @Override synchronized JcrSession login( final Credentials credentials,
                                          String workspaceName );  }
@Test public void shouldAllowCreatingWorkspaces() throws Exception { shutdownDefaultRepository(); RepositoryConfiguration config = null; config = RepositoryConfiguration.read("{ \"name\" : \"repoName\", \"workspaces\" : { \"allowCreation\" : true } }"); config = new RepositoryConfiguration(config.getDocument(), "repoName", new TestingEnvironment()); repository = new JcrRepository(config); repository.start(); Session session2 = null; Session session3 = null; try { session = createSession(); session2 = createSession(); String newWorkspaceName = "MyCarWorkspace"; session.getWorkspace().createWorkspace(newWorkspaceName); assertAccessibleWorkspace(session, newWorkspaceName); assertAccessibleWorkspace(session2, newWorkspaceName); session.logout(); session3 = createSession(); assertAccessibleWorkspace(session2, newWorkspaceName); assertAccessibleWorkspace(session3, newWorkspaceName); session = createSession(newWorkspaceName); } finally { try { if (session2 != null) session2.logout(); } finally { if (session3 != null) session3.logout(); } } }
@FixFor( {"MODE-1498", "MODE-2202"} ) @Test public void shouldWorkWithUserDefinedTransactionsInSeparateThreads() throws Exception { CyclicBarrier barrier = new CyclicBarrier(2); CyclicBarrier completionBarrier = new CyclicBarrier(3); session = createSession(); SessionWorker worker1 = new SessionWorker(session, barrier, completionBarrier, "thread 1") { @Override protected void execute( Session session ) throws Exception { SimpleListener listener = addListener(3); assertThat(listener.getActualEventCount(), is(0)); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); final TransactionManager txnMgr = getTransactionManager(); txnMgr.begin(); assertThat(listener.getActualEventCount(), is(0)); Node txnNode1 = session.getRootNode().addNode("txnNode1"); Node txnNode1a = txnNode1.addNode("txnNodeA"); assertThat(txnNode1a, is(notNullValue())); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(false)); session.save(); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(false)); assertThat(listener.getActualEventCount(), is(0)); barrier.await(); Thread.sleep(100L); assertThat(listener.getActualEventCount(), is(0)); barrier.await(); Node txnNode2 = session.getRootNode().addNode("txnNode2"); assertThat(txnNode2, is(notNullValue())); session.save(); assertThat(listener.getActualEventCount(), is(0)); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(true)); barrier.await(); Thread.sleep(100L); assertThat(listener.getActualEventCount(), is(0)); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(true)); barrier.await(); txnMgr.commit(); barrier.await(); listener.waitForEvents(); nodeExists(session, "/", "txnNode1"); nodeExists(session, "/", "txnNode2"); } }; SessionWorker worker2 = new SessionWorker(createSession(), barrier, completionBarrier, "thread 2") { @Override protected void execute( Session session ) throws Exception { nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); Thread.sleep(50L); barrier.await(); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); session.refresh(false); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); Thread.sleep(50L); barrier.await(); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); session.refresh(false); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); Thread.sleep(50L); barrier.await(); nodeExists(session, "/", "txnNode1"); nodeExists(session, "/", "txnNode2"); session.refresh(false); nodeExists(session, "/", "txnNode1"); nodeExists(session, "/", "txnNode2"); } }; new Thread(worker1).start(); new Thread(worker2).start(); completionBarrier.await(); }
@FixFor( {"MODE-1498", "MODE-2202"} ) @Test public void shouldWorkWithUserDefinedTransactionsThatUseRollbackInSeparateThreads() throws Exception { CyclicBarrier barrier = new CyclicBarrier(2); CyclicBarrier completionBarrier = new CyclicBarrier(3); session = createSession(); SessionWorker worker1 = new SessionWorker(session, barrier, completionBarrier, "thread 1") { @Override protected void execute( Session session ) throws Exception { SimpleListener listener = addListener(3); assertThat(listener.getActualEventCount(), is(0)); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); final TransactionManager txnMgr = getTransactionManager(); txnMgr.begin(); assertThat(listener.getActualEventCount(), is(0)); Node txnNode1 = session.getRootNode().addNode("txnNode1"); Node txnNode1a = txnNode1.addNode("txnNodeA"); assertThat(txnNode1a, is(notNullValue())); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(false)); session.save(); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(false)); assertThat(listener.getActualEventCount(), is(0)); barrier.await(); Thread.sleep(100L); assertThat(listener.getActualEventCount(), is(0)); barrier.await(); Node txnNode2 = session.getRootNode().addNode("txnNode2"); assertThat(txnNode2, is(notNullValue())); session.save(); assertThat(listener.getActualEventCount(), is(0)); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(true)); barrier.await(); Thread.sleep(100L); assertThat(listener.getActualEventCount(), is(0)); assertThat(session.getRootNode().hasNode("txnNode1"), is(true)); assertThat(session.getRootNode().hasNode("txnNode2"), is(true)); barrier.await(); txnMgr.rollback(); barrier.await(); Thread.sleep(100L); assertThat(listener.getActualEventCount(), is(0)); assertThat(session.getRootNode().hasNode("txnNode1"), is(false)); assertThat(session.getRootNode().hasNode("txnNode2"), is(false)); session.refresh(false); assertThat(session.getRootNode().hasNode("txnNode1"), is(false)); assertThat(session.getRootNode().hasNode("txnNode2"), is(false)); } }; SessionWorker worker2 = new SessionWorker(createSession(), barrier, completionBarrier, "thread 2") { @Override protected void execute( Session session ) throws Exception { nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); Thread.sleep(50L); barrier.await(); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); session.refresh(false); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); Thread.sleep(50L); barrier.await(); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); session.refresh(false); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); barrier.await(); Thread.sleep(50L); barrier.await(); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); session.refresh(false); nodeDoesNotExist(session, "/", "txnNode1"); nodeDoesNotExist(session, "/", "txnNode2"); } }; new Thread(worker1).start(); new Thread(worker2).start(); completionBarrier.await(10, TimeUnit.SECONDS); }
@Test @FixFor( "MODE-2387" ) public void shouldStartRepositoryWithCustomSettingsForLocalIndexProvider() throws Exception { shutdownDefaultRepository(); FileUtil.delete("target/local_index_custom_settings_test_repository"); repository = TestingUtil.startRepositoryWithConfig("config/local-index-provider-with-custom-settings.json"); repository.start(); }
@Test(expected = RuntimeException.class) @FixFor( "MODE-2528" ) public void shouldNotStartRepositoryWithInvalidPersistence() throws Exception { shutdownDefaultRepository(); repository = TestingUtil.startRepositoryWithConfig("config/repo-config-invalid-persistence.json"); repository.start(); }