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);
}
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.");
}
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());
}
}
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());
}
}
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();
}
Aggregations