Skip to content

Commit

Permalink
Update group tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schüth committed Apr 4, 2017
1 parent cd212b9 commit a2ae544
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ default SearchQueueBatch store(IndexableElement element, boolean addRelatedEntri
*/
List<? extends SearchQueueEntry> getEntries();

/**
* Set the batch id.
*
* @param batchId
*/
void setBatchId(String batchId);

/**
* Return the batch id for this batch.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ public void clear() {
log.debug("Clearing graph");
}
try (Tx tx = tx()) {
tx.getGraph().e().removeAll();
tx.getGraph().v().removeAll();
tx.getGraph()
.e()
.removeAll();
tx.getGraph()
.v()
.removeAll();
tx.success();
}
if (log.isDebugEnabled()) {
Expand Down Expand Up @@ -69,7 +73,9 @@ public void reset() throws Exception {
public <T> T noTx(TxHandler<T> txHandler) {
// Avoid creating a transaction if possible
if (Database.threadLocalGraph.get() != null) {
log.error("Bogus noTx() call detected. Avoid creating nested transactions for threads which already use an active transaction.");
if (log.isDebugEnabled()) {
log.debug("Bogus noTx() call detected. Avoid creating nested transactions for threads which already use an active transaction.");
}
try {
T result = txHandler.call();
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public List<? extends SearchQueueEntry> getEntries() {
return Collections.emptyList();
}

@Override
public void setBatchId(String batchId) {

}

@Override
public String getBatchId() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ public String getBatchId() {
return batchId;
}

@Override
public void setBatchId(String batchId) {
this.batchId = batchId;
}

@Override
public void printDebug() {
for (SearchQueueEntry entry : getEntries()) {
Expand Down
129 changes: 86 additions & 43 deletions core/src/test/java/com/gentics/mesh/core/group/GroupEndpointTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void testCreate() throws Exception {
public void testCreateWithNoPerm() throws Exception {
GroupCreateRequest request = new GroupCreateRequest();
request.setName("test12345");
String groupRootUuid = db().noTx(() -> meshRoot().getGroupRoot().getUuid());
String groupRootUuid = db().noTx(() -> meshRoot().getGroupRoot()
.getUuid());

try (NoTx noTx = db().noTx()) {
role().revokePermissions(meshRoot().getGroupRoot(), CREATE_PERM);
Expand Down Expand Up @@ -124,7 +125,8 @@ public void testConflicingGroupCreation() throws Exception {

try (NoTx noTx = db().noTx()) {
role().grantPermissions(meshRoot().getGroupRoot(), CREATE_PERM);
MeshResponse<GroupResponse> future = client().createGroup(request).invoke();
MeshResponse<GroupResponse> future = client().createGroup(request)
.invoke();
latchFor(future);
assertSuccess(future);
GroupResponse restGroup = future.result();
Expand All @@ -144,13 +146,15 @@ public void testCreateReadDelete() throws Exception {
GroupCreateRequest request = new GroupCreateRequest();
request.setName(name);

MeshResponse<GroupResponse> future = client().createGroup(request).invoke();
MeshResponse<GroupResponse> future = client().createGroup(request)
.invoke();
latchFor(future);
assertSuccess(future);
GroupResponse restGroup = future.result();
assertThat(restGroup).matches(request);

Group foundGroup = boot().groupRoot().findByUuid(restGroup.getUuid());
Group foundGroup = boot().groupRoot()
.findByUuid(restGroup.getUuid());
assertNotNull("Group should have been created.", foundGroup);

call(() -> client().findGroupByUuid(restGroup.getUuid()));
Expand Down Expand Up @@ -201,36 +205,49 @@ public void testReadMultiple() throws Exception {
role().grantPermissions(group, READ_PERM);
}

totalGroups = nGroups + data().getGroups().size();
totalGroups = nGroups + data().getGroups()
.size();
// Test default paging parameters
MeshResponse<GroupListResponse> future = client().findGroups().invoke();
MeshResponse<GroupListResponse> future = client().findGroups()
.invoke();
latchFor(future);
assertSuccess(future);
GroupListResponse restResponse = future.result();
assertEquals(25, restResponse.getMetainfo().getPerPage());
assertEquals(1, restResponse.getMetainfo().getCurrentPage());
assertEquals(23, restResponse.getData().size());
assertEquals(25, restResponse.getMetainfo()
.getPerPage());
assertEquals(1, restResponse.getMetainfo()
.getCurrentPage());
assertEquals(23, restResponse.getData()
.size());

int perPage = 6;
future = client().findGroups(new PagingParametersImpl(3, perPage)).invoke();
future = client().findGroups(new PagingParametersImpl(3, perPage))
.invoke();
latchFor(future);
assertSuccess(future);
restResponse = future.result();

assertEquals(perPage, restResponse.getData().size());
assertEquals(perPage, restResponse.getData()
.size());

// created groups + test data group
int totalPages = (int) Math.ceil(totalGroups / (double) perPage);
assertEquals("The response did not contain the correct amount of items", perPage, restResponse.getData().size());
assertEquals(3, restResponse.getMetainfo().getCurrentPage());
assertEquals("The response did not contain the correct amount of items", perPage, restResponse.getData()
.size());
assertEquals(3, restResponse.getMetainfo()
.getCurrentPage());
assertEquals("We expect {" + totalGroups + "} groups and with a paging size of {" + perPage + "} exactly {" + totalPages + "} pages.",
totalPages, restResponse.getMetainfo().getPageCount());
assertEquals(perPage, restResponse.getMetainfo().getPerPage());
assertEquals(totalGroups, restResponse.getMetainfo().getTotalCount());
totalPages, restResponse.getMetainfo()
.getPageCount());
assertEquals(perPage, restResponse.getMetainfo()
.getPerPage());
assertEquals(totalGroups, restResponse.getMetainfo()
.getTotalCount());

List<GroupResponse> allGroups = new ArrayList<>();
for (int page = 1; page <= totalPages; page++) {
MeshResponse<GroupListResponse> pageFuture = client().findGroups(new PagingParametersImpl(page, perPage)).invoke();
MeshResponse<GroupListResponse> pageFuture = client().findGroups(new PagingParametersImpl(page, perPage))
.invoke();
latchFor(pageFuture);
assertSuccess(pageFuture);
restResponse = pageFuture.result();
Expand All @@ -239,34 +256,51 @@ public void testReadMultiple() throws Exception {
assertEquals("Somehow not all groups were loaded when loading all pages.", totalGroups, allGroups.size());

// Verify that extra group is not part of the response
List<GroupResponse> filteredUserList = allGroups.parallelStream().filter(restGroup -> restGroup.getName().equals(extraGroupName))
List<GroupResponse> filteredUserList = allGroups.parallelStream()
.filter(restGroup -> restGroup.getName()
.equals(extraGroupName))
.collect(Collectors.toList());
assertTrue("Extra group should not be part of the list since no permissions were added.", filteredUserList.size() == 0);

call(() -> client().findGroups(new PagingParametersImpl(-1, perPage)), BAD_REQUEST, "error_page_parameter_must_be_positive", "-1");

future = client().findGroups(new PagingParametersImpl(1, -1)).invoke();
future = client().findGroups(new PagingParametersImpl(1, -1))
.invoke();
latchFor(future);
expectException(future, BAD_REQUEST, "error_pagesize_parameter", "-1");

future = client().findGroups(new PagingParametersImpl(4242, 1)).invoke();
future = client().findGroups(new PagingParametersImpl(4242, 1))
.invoke();
latchFor(future);
assertSuccess(future);

assertEquals(0, future.result().getData().size());
assertEquals(4242, future.result().getMetainfo().getCurrentPage());
assertEquals(23, future.result().getMetainfo().getPageCount());
assertEquals(23, future.result().getMetainfo().getTotalCount());
assertEquals(1, future.result().getMetainfo().getPerPage());
assertEquals(0, future.result()
.getData()
.size());
assertEquals(4242, future.result()
.getMetainfo()
.getCurrentPage());
assertEquals(23, future.result()
.getMetainfo()
.getPageCount());
assertEquals(23, future.result()
.getMetainfo()
.getTotalCount());
assertEquals(1, future.result()
.getMetainfo()
.getPerPage());
}
}

@Test
public void testReadMetaCountOnly() {
MeshResponse<GroupListResponse> future = client().findGroups(new PagingParametersImpl(1, 0)).invoke();
MeshResponse<GroupListResponse> future = client().findGroups(new PagingParametersImpl(1, 0))
.invoke();
latchFor(future);
assertSuccess(future);
assertEquals(0, future.result().getData().size());
assertEquals(0, future.result()
.getData()
.size());
}

@Test
Expand Down Expand Up @@ -324,7 +358,8 @@ public void testUpdate() throws GenericRestException, Exception {

try (Tx tx = db().tx()) {
assertThat(restGroup).matches(request);
Group reloadedGroup = boot().groupRoot().findByUuid(uuid);
Group reloadedGroup = boot().groupRoot()
.findByUuid(uuid);
assertEquals("The group should have been updated", name, reloadedGroup.getName());
}
}
Expand Down Expand Up @@ -352,11 +387,13 @@ public void testUpdateGroupWithEmptyName() throws GenericRestException, Exceptio
GroupUpdateRequest request = new GroupUpdateRequest();
request.setName(name);

MeshResponse<GroupResponse> future = client().updateGroup(group.getUuid(), request).invoke();
MeshResponse<GroupResponse> future = client().updateGroup(group.getUuid(), request)
.invoke();
latchFor(future);
expectException(future, BAD_REQUEST, "error_name_must_be_set");

Group reloadedGroup = boot().groupRoot().findByUuid(group.getUuid());
Group reloadedGroup = boot().groupRoot()
.findByUuid(group.getUuid());
assertEquals("The group should not have been updated", group.getName(), reloadedGroup.getName());
}
}
Expand All @@ -372,7 +409,8 @@ public void testUpdateGroupWithConflictingName() throws GenericRestException, Ex
GroupUpdateRequest request = new GroupUpdateRequest();
request.setName(alreadyUsedName);

MeshResponse<GroupResponse> future = client().updateGroup(group().getUuid(), request).invoke();
MeshResponse<GroupResponse> future = client().updateGroup(group().getUuid(), request)
.invoke();
latchFor(future);
expectException(future, CONFLICT, "group_conflicting_name", alreadyUsedName);

Expand All @@ -392,7 +430,8 @@ public void testReadWithRolePermsSync() throws Exception {
GroupCreateRequest createReq = new GroupCreateRequest();
for (int i = 0; i < groupCount; i++) {
createReq.setName("testGroup" + i);
MeshResponse<GroupResponse> future = client().createGroup(createReq).invoke();
MeshResponse<GroupResponse> future = client().createGroup(createReq)
.invoke();
latchFor(future);
}

Expand All @@ -401,7 +440,8 @@ public void testReadWithRolePermsSync() throws Exception {

int readCount = 100;
for (int i = 0; i < readCount; i++) {
MeshResponse<GroupListResponse> fut = client().findGroups(params).invoke();
MeshResponse<GroupListResponse> fut = client().findGroups(params)
.invoke();
latchFor(fut);
GroupListResponse res = fut.result();

Expand Down Expand Up @@ -464,7 +504,8 @@ public void testUpdateMultithreaded() throws InterruptedException {
CyclicBarrier barrier = prepareBarrier(nJobs);
Set<MeshResponse<?>> set = new HashSet<>();
for (int i = 0; i < nJobs; i++) {
set.add(client().updateGroup(group().getUuid(), request).invoke());
set.add(client().updateGroup(group().getUuid(), request)
.invoke());
}
validateSet(set, barrier);

Expand All @@ -480,38 +521,39 @@ public void testReadByUuidMultithreaded() throws InterruptedException {
Set<MeshResponse<?>> set = new HashSet<>();
for (int i = 0; i < nJobs; i++) {
log.debug("Invoking findGroupByUuid REST call");
set.add(client().findGroupByUuid(uuid).invoke());
set.add(client().findGroupByUuid(uuid)
.invoke());
}
validateSet(set, barrier);
}

@Test
@Override
@Ignore("not yet enabled")
public void testDeleteByUUIDMultithreaded() throws InterruptedException {
int nJobs = 3;
String uuid = group().getUuid();
int nJobs = 10;
String uuid = db().noTx(() -> group().getUuid());
CyclicBarrier barrier = prepareBarrier(nJobs);
Set<MeshResponse<Void>> set = new HashSet<>();
for (int i = 0; i < nJobs; i++) {
log.debug("Invoking deleteUser REST call");
set.add(client().deleteGroup(uuid).invoke());
set.add(client().deleteGroup(uuid)
.invoke());
}
validateDeletion(set, barrier);
}

@Test
@Override
@Ignore("not yet enabled")
public void testCreateMultithreaded() throws Exception {
int nJobs = 5;
int nJobs = 50;
CyclicBarrier barrier = prepareBarrier(nJobs);
Set<MeshResponse<?>> set = new HashSet<>();
for (int i = 0; i < nJobs; i++) {
log.debug("Invoking createGroup REST call");
GroupCreateRequest request = new GroupCreateRequest();
request.setName("test12345_" + i);
set.add(client().createGroup(request).invoke());
set.add(client().createGroup(request)
.invoke());
}
validateCreation(set, barrier);

Expand All @@ -525,7 +567,8 @@ public void testReadByUuidMultithreadedNonBlocking() throws InterruptedException
int nJobs = 200;
for (int i = 0; i < nJobs; i++) {
log.debug("Invoking findGroupByUuid REST call");
set.add(client().findGroupByUuid(group().getUuid()).invoke());
set.add(client().findGroupByUuid(group().getUuid())
.invoke());
}
}
for (MeshResponse<GroupResponse> future : set) {
Expand Down
Loading

0 comments on commit a2ae544

Please sign in to comment.