AsyncOperationCollection implements IAsyncOperationCollection { @Override public IObject getAsyncOperation(final String token) throws GetAsyncOperationException { try (IPoolGuard guard = new PoolGuard(connectionPool)) { IObject result = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject")); IDatabaseTask getItemTask = IOC.resolve( Keys.getOrAdd("db.async_ops_collection.get"), guard.getObject(), collectionName, token, (IAction<IObject[]>) docs -> { try { result.setValue(new FieldName("result"), docs[0]); } catch (ChangeValueException e) { throw new ActionExecuteException(e); } } ); getItemTask.execute(); IObject searchResult = (IObject) result.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "result")); if (searchResult == null) { throw new GetAsyncOperationException("Can't find operation."); } return searchResult; } catch (ResolutionException e) { throw new GetAsyncOperationException("Can't resolve object during get operation.", e); } catch (InvalidArgumentException e) { throw new GetAsyncOperationException("Can't register strategy for getItem task.", e); } catch (PoolGuardException e) { throw new GetAsyncOperationException("Can't get connection from pool.", e); } catch (ReadValueException e) { throw new GetAsyncOperationException("Error during preparing read task.", e); } catch (TaskExecutionException e) { throw new GetAsyncOperationException("Error during execution read task.", e); } } AsyncOperationCollection(final IPool connectionPool, final String collectionName); @Override IObject getAsyncOperation(final String token); @Override void createAsyncOperation(final IObject data, final String token, final String expiredTime); @Override void delete(final String token); @Override void complete(final IObject document);  }
@Test(expected = GetAsyncOperationException.class) public void ShouldThrowGetItemException_When_NestedTaskIsNull() throws Exception { when(IOC.resolve(any(), any(), any(), any(), any())).thenThrow(new ResolutionException("")); collection.getAsyncOperation("key"); }