Search in sources :

Example 6 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class MonitoredCTSConnectionFactoryTest method shouldWrapHandlerWhenCalledAsync.

@Test
public void shouldWrapHandlerWhenCalledAsync() {
    //given
    PromiseImpl<Object, DataLayerException> promise = PromiseImpl.create();
    given(connectionFactory.createAsync()).willReturn(promise);
    //when
    monitoredConnectionFactory.createAsync();
    //then
    verify(connectionFactory).createAsync();
    verifyZeroInteractions(monitoringStore);
    promise.handleException(new DataLayerException("reason"));
    verify(monitoringStore).addConnection(false);
}
Also used : DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Test(org.testng.annotations.Test)

Example 7 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class SeriesTaskExecutorThread method run.

/**
     * Starts processing of the Queue Tasks.
     *
     * @throws java.lang.IllegalStateException If the queue has not been assigned.
     */
@Override
public void run() {
    if (queue == null)
        throw new IllegalStateException("Must assign a queue before starting.");
    try {
        taskExecutor.start();
    } catch (DataLayerException e) {
        throw new IllegalStateException("Cannot start task executor", e);
    }
    // Iterate until shutdown
    while (!Thread.currentThread().isInterrupted()) {
        try {
            Task task = queue.take();
            debug("process Task {0}", task);
            taskExecutor.execute(null, task);
        } catch (InterruptedException e) {
            error("interrupt detected", e);
            Thread.currentThread().interrupt();
        }
    }
    debug("Processor thread shutdown.");
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException)

Example 8 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class TokenDataStore method query.

/**
     * Query the store for instances.
     *
     * @param query The criteria of the query, using {@code T} bean property names as fields.
     * @return A set of all matching objects.
     * @throws ServerException When an error occurs when querying the store.
     */
public Set<T> query(QueryFilter<String> query) throws ServerException {
    SyncResultHandler<Collection<Token>> handler = new SyncResultHandler<Collection<Token>>();
    try {
        Task task = taskFactory.query(adapter.toTokenQuery(query), handler);
        taskExecutor.execute(null, task);
        return convertResults(handler.getResults());
    } catch (ServerException e) {
        throw e;
    } catch (DataLayerException e) {
        if (debug.warningEnabled()) {
            debug.warning("Unable to read objects corresponding to query: " + query, e);
        }
        throw new ServerException("Could not query tokens from data store: " + e.getMessage());
    }
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Collection(java.util.Collection) Token(org.forgerock.openam.cts.api.tokens.Token)

Example 9 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class TokenDataStore method read.

/**
     * Reads a {@code T} out of the store using its OpenAM Unique ID.
     *
     * @param id The OpenAM Unique ID assigned to the object.
     * @return The object, T.
     * @throws NotFoundException If the object is not found.
     * @throws ServerException When the object cannot be loaded.
     */
public T read(String id) throws NotFoundException, ServerException {
    try {
        if (id == null) {
            throw new NotFoundException("Object not found");
        }
        SyncResultHandler<Token> handler = new SyncResultHandler<Token>();
        taskExecutor.execute(id, taskFactory.read(id, handler));
        Token token = handler.getResults();
        if (token == null) {
            throw new NotFoundException("Object not found with id: " + id);
        }
        return adapter.fromToken(token);
    } catch (NotFoundException e) {
        throw e;
    } catch (ServerException e) {
        throw e;
    } catch (DataLayerException e) {
        if (debug.warningEnabled()) {
            debug.warning("Unable to read token corresponding to id: " + id, e);
        }
        throw new ServerException("Could not read token from token data store: " + e.getMessage());
    }
}
Also used : DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Token(org.forgerock.openam.cts.api.tokens.Token)

Example 10 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class CTSQueueConfigurationTest method shouldThrowExceptionIfConnectionsTooLow.

@Test
public void shouldThrowExceptionIfConnectionsTooLow() throws Exception {
    given(mockConfig.getMaxConnections()).willReturn(1);
    DataLayerException result = null;
    try {
        config.getProcessors();
    } catch (DataLayerException e) {
        result = e;
    }
    assertThat(result).isNotNull();
}
Also used : DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Test(org.testng.annotations.Test)

Aggregations

DataLayerException (org.forgerock.openam.sm.datalayer.api.DataLayerException)11 Token (org.forgerock.openam.cts.api.tokens.Token)4 Test (org.testng.annotations.Test)3 Task (org.forgerock.openam.sm.datalayer.api.Task)2 Collection (java.util.Collection)1 LdapInitializationFailedException (org.forgerock.openam.cts.exceptions.LdapInitializationFailedException)1 CreateTask (org.forgerock.openam.sm.datalayer.impl.tasks.CreateTask)1 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)1 Connection (org.forgerock.opendj.ldap.Connection)1 DN (org.forgerock.opendj.ldap.DN)1 LdapException (org.forgerock.opendj.ldap.LdapException)1 DeleteRequest (org.forgerock.opendj.ldap.requests.DeleteRequest)1