Ensure that system groups can be retrieved from the index during tests

The way we set up the test environment resulted in an empty group
index at the start of our tests. This means that any groups which
were created during the setup (e.g. system groups like "Administrators")
couldn't be looked up from the index during tests. As we didn't use
the group index in tests up to now, we didn't notice it so far.

To unblock further changes which will require the group index to work
during tests, we reindex all available groups after setting up the test
environment.

It would be preferable to fix this issue properly without this
workaround. However, it doesn't seem to be easily possible. The biggest
issue is that any indexes during tests are non-permanent. If we open an
instance of the group index during setup (especially during the on-init
phase), close it, and open another instance for the real test, all
indexed data is lost. Until we find a way around this, we'll have to
live with this workaround.

Change-Id: Icf50c0be99be2a33e96688f15a01d9ea90f5563e
This commit is contained in:
Alice Kober-Sotzek
2017-08-22 18:24:15 +02:00
parent 43d5115c98
commit 6da54a4009
2 changed files with 20 additions and 0 deletions

View File

@@ -342,6 +342,20 @@ public abstract class AbstractDaemonTest {
server.getTestInjector().injectMembers(this);
Transport.register(inProcessProtocol);
toClose = Collections.synchronizedList(new ArrayList<Repository>());
// All groups which were added during the server start (e.g. in SchemaCreator) aren't contained
// in the instance of the group index which is available here and in tests. There are two
// reasons:
// 1) No group index is available in SchemaCreator when using an in-memory database. (This could
// be fixed by using the IndexManagerOnInit in InMemoryDatabase similar as BaseInit uses it.)
// 2) During the on-init part of the server start, we use another instance of the index than
// later on. As test indexes are non-permanent, closing an instance and opening another one
// removes all indexed data.
// As a workaround, we simply reindex all available groups here.
for (AccountGroup group : groupCache.all()) {
groupCache.evict(group);
}
admin = accountCreator.admin();
user = accountCreator.user();

View File

@@ -63,6 +63,12 @@ import org.junit.Test;
public class GroupsIT extends AbstractDaemonTest {
@Inject @ServerInitiated private Provider<GroupsUpdate> groupsUpdateProvider;
@Test
public void systemGroupCanBeRetrievedFromIndex() throws Exception {
List<GroupInfo> groupInfos = gApi.groups().query("name:Administrators").get();
assertThat(groupInfos).isNotEmpty();
}
@Test
public void addToNonExistingGroup_NotFound() throws Exception {
exception.expect(ResourceNotFoundException.class);