@Override public void start( final StartContext context ) { this.engine.start(); }
@Test public void shouldNotAutomaticallyStartDeployedRepositories() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); engine.startRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.RUNNING)); engine.shutdownRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); }
public synchronized ModeShapeEngine getEngine() { if (engine == null) { ModeShapeEngine engine = new ModeShapeEngine(); engine.start(); this.engine = engine; } return engine; } }
@Test public void shouldAllowUpdatingRepositoryConfigurationWhileRunning() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); engine.startRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.RUNNING)); long defaultLargeValueSize = Default.MINIMUM_BINARY_SIZE_IN_BYTES; assertThat(config.getBinaryStorage().getMinimumBinarySizeInBytes(), is(defaultLargeValueSize)); assertThat(repository.repositoryCache().largeValueSizeInBytes(), is(defaultLargeValueSize)); // Change the configuration. We'll do something simple, like changing the large value size ... long newLargeValueSizeInBytes = defaultLargeValueSize * 2L; Editor editor = repository.getConfiguration().edit(); EditableDocument binaryStorage = editor.getOrCreateDocument(FieldName.STORAGE) .getOrCreateDocument(FieldName.BINARY_STORAGE); binaryStorage.setNumber(FieldName.MINIMUM_BINARY_SIZE_IN_BYTES, newLargeValueSizeInBytes); Changes changes = editor.getChanges(); // Apply the changes to the deployed repository ... engine.update(name, changes).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.RUNNING)); // Verify the running repository and its configuraiton are using the new value ... RepositoryConfiguration newConfig = engine.getRepository(name).getConfiguration(); assertThat(newConfig.getBinaryStorage().getMinimumBinarySizeInBytes(), is(newLargeValueSizeInBytes)); assertThat(repository.repositoryCache().largeValueSizeInBytes(), is(newLargeValueSizeInBytes)); }
@Bean(destroyMethod="shutdown") public ModeShapeEngine modeShapeEngine(@Qualifier("springApplicationContext")SpringApplicationContext springApplicationContext) { ModeShapeEngine engine = new ModeShapeEngine(); log.info("Starting ModeShape engine..."); engine.start(); log.info("ModeShape engine started"); return engine; }
@Validate private void start() throws RepositoryException, InterruptedException { engine.start(); }
/** * This is called when a resource adapter instance is bootstrapped. * * @param ctx A bootstrap context containing references * @throws ResourceAdapterInternalException indicates bootstrap failure. */ @Override public synchronized void start( BootstrapContext ctx ) throws ResourceAdapterInternalException { if (engine == null) { engine = new ModeShapeEngine(); engine.start(); } }
protected ModeShapeEngine engine() { // Make sure the engine is started ... switch (ENGINE.getState()) { case NOT_RUNNING: ENGINE.start(); break; case STOPPING: // Wait until it's shutdown ... try { ENGINE.shutdown().get(10, TimeUnit.SECONDS); } catch (Exception e) { // ignore and let if fail ... } break; case RESTORING: case RUNNING: case STARTING: // do nothing ... } return ENGINE; }
protected ModeShapeEngine engine() { // Make sure the engine is started ... switch (ENGINE.getState()) { case NOT_RUNNING: ENGINE.start(); break; case STOPPING: // Wait until it's shutdown ... try { ENGINE.shutdown().get(10, TimeUnit.SECONDS); } catch (Exception e) { // ignore and let if fail ... } break; case RESTORING: case RUNNING: case STARTING: // do nothing ... } return ENGINE; }
@Test public void shouldAllowStartToBeCalledMultipleTimes() { for (int i = 0; i != 10; ++i) { engine.start(); assertThat(engine.getState(), is(State.RUNNING)); } }
@Test public void shouldStart() { engine.start(); assertThat(engine.getState(), is(State.RUNNING)); }
@Test public void shouldStartThenStopThenRestart() throws Exception { assertThat(engine.getState(), is(State.NOT_RUNNING)); engine.start(); assertThat(engine.getState(), is(State.RUNNING)); for (int i = 0; i != 5; ++i) { engine.shutdown().get(3L, TimeUnit.SECONDS); assertThat(engine.getState(), is(State.NOT_RUNNING)); } engine.start(); assertThat(engine.getState(), is(State.RUNNING)); }
@Test public void shouldDeployRepositoryConfiguration() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); assertThat(repository, is(notNullValue())); assertThat(repository, is(notNullValue())); }
protected void startEngineAndDeployRepositoryAndLogIn() throws Exception { print("starting engine"); engine.start(); assertThat(engine.getState(), is(State.RUNNING)); print("deploying repository"); repository = engine.deploy(config); session = repository.login(); assertThat(session.getRootNode(), is(notNullValue())); }
@Test( expected = ConfigurationException.class ) public void shouldFailToDeployRepositoryConfigurationWithoutName() throws Throwable { config = new RepositoryConfiguration(); // without a name! assertThat(config.validate().hasErrors(), is(true)); engine.start(); engine.deploy(config); }
@Test public void shouldAutomaticallyStartRepositoryUponLogin() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); assertThat(repository.getState(), is(State.NOT_RUNNING)); for (int i = 0; i != 4; ++i) { javax.jcr.Session session = repository.login(); assertThat(repository.getState(), is(State.RUNNING)); session.logout(); } assertThat(engine.getRepositoryState(name), is(State.RUNNING)); engine.shutdownRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); }
@Test public void shouldStartRepositoryUsingLocalEnvironmentWithDefaultPersistenceConfiguration() throws Exception { // Create the repository configuration ... String configFilePath = "config/repo-config-inmemory-no-persistence.json"; InputStream configFileStream = getClass().getClassLoader().getResourceAsStream(configFilePath); RepositoryConfiguration repositoryConfiguration = RepositoryConfiguration.read(configFileStream, "doesn't matter"); LocalEnvironment environment = new LocalEnvironment(); repositoryConfiguration = repositoryConfiguration.with(environment); // Start the engine and repository ... ModeShapeEngine engine = new ModeShapeEngine(); engine.start(); try { JcrRepository repository = engine.deploy(repositoryConfiguration); Session session = repository.login(); Node root = session.getRootNode(); root.addNode("Library", "nt:folder"); session.save(); session.logout(); session = repository.login(); Node library = session.getNode("/Library"); assertThat(library, is(notNullValue())); assertThat(library.getPrimaryNodeType().getName(), is("nt:folder")); session.logout(); } finally { engine.shutdown().get(); environment.shutdown(); } }
@Test public void shouldAllowUpdatingSequencerInformationWhenRunning() throws Exception { URL configUrl = getClass().getClassLoader().getResource("config/repo-config.json"); engine.start(); config = RepositoryConfiguration.read(configUrl).with(environment); JcrRepository repository = engine.deploy(config);
@Test public void shouldAllowConcurrentLoginWhileRequiringAutoStartOfRepository() throws Exception { engine.start(); final JcrRepository repository = engine.deploy(config); String name = repository.getName();
@Test public void shouldAllowUpdatingRepositoryConfigurationWhileNotRunning() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); assertThat(config.getBinaryStorage().getMinimumBinarySizeInBytes(), is(Default.MINIMUM_BINARY_SIZE_IN_BYTES)); // Change the configuration ... long newLargeValueSizeInBytes = Default.MINIMUM_BINARY_SIZE_IN_BYTES * 2; Editor editor = repository.getConfiguration().edit(); EditableDocument binaryStorage = editor.getOrCreateDocument(FieldName.STORAGE) .getOrCreateDocument(FieldName.BINARY_STORAGE); binaryStorage.setNumber(FieldName.MINIMUM_BINARY_SIZE_IN_BYTES, newLargeValueSizeInBytes); Changes changes = editor.getChanges(); // Apply the changes to the deployed repository ... engine.update(name, changes).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); RepositoryConfiguration newConfig = engine.getRepository(name).getConfiguration(); assertThat(newConfig.getBinaryStorage().getMinimumBinarySizeInBytes(), is(newLargeValueSizeInBytes)); }