From a2ae544403e8e5803058827d28991216469be582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=BCth?= Date: Tue, 4 Apr 2017 14:32:51 +0200 Subject: [PATCH] Update group tests --- .../core/data/search/SearchQueueBatch.java | 7 - .../mesh/graphdb/spi/AbstractDatabase.java | 12 +- .../search/impl/DummySearchQueueBatch.java | 5 - .../search/impl/SearchQueueBatchImpl.java | 5 - .../mesh/core/group/GroupEndpointTest.java | 129 ++++++++++++------ .../mesh/search/GroupSearchEndpointTest.java | 28 ++-- .../mesh/search/NodeSearchEndpointGTest.java | 1 - .../mesh/test/context/MeshTestHelper.java | 13 +- 8 files changed, 123 insertions(+), 77 deletions(-) diff --git a/common/src/main/java/com/gentics/mesh/core/data/search/SearchQueueBatch.java b/common/src/main/java/com/gentics/mesh/core/data/search/SearchQueueBatch.java index 79208636b5..7e27c860c5 100644 --- a/common/src/main/java/com/gentics/mesh/core/data/search/SearchQueueBatch.java +++ b/common/src/main/java/com/gentics/mesh/core/data/search/SearchQueueBatch.java @@ -139,13 +139,6 @@ default SearchQueueBatch store(IndexableElement element, boolean addRelatedEntri */ List getEntries(); - /** - * Set the batch id. - * - * @param batchId - */ - void setBatchId(String batchId); - /** * Return the batch id for this batch. * diff --git a/common/src/main/java/com/gentics/mesh/graphdb/spi/AbstractDatabase.java b/common/src/main/java/com/gentics/mesh/graphdb/spi/AbstractDatabase.java index d900dacc84..d1574dfc50 100644 --- a/common/src/main/java/com/gentics/mesh/graphdb/spi/AbstractDatabase.java +++ b/common/src/main/java/com/gentics/mesh/graphdb/spi/AbstractDatabase.java @@ -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()) { @@ -69,7 +73,9 @@ public void reset() throws Exception { public T noTx(TxHandler 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; diff --git a/core/src/main/java/com/gentics/mesh/core/data/search/impl/DummySearchQueueBatch.java b/core/src/main/java/com/gentics/mesh/core/data/search/impl/DummySearchQueueBatch.java index 49cb2c645c..0e27c53c36 100644 --- a/core/src/main/java/com/gentics/mesh/core/data/search/impl/DummySearchQueueBatch.java +++ b/core/src/main/java/com/gentics/mesh/core/data/search/impl/DummySearchQueueBatch.java @@ -63,11 +63,6 @@ public List getEntries() { return Collections.emptyList(); } - @Override - public void setBatchId(String batchId) { - - } - @Override public String getBatchId() { return null; diff --git a/core/src/main/java/com/gentics/mesh/core/data/search/impl/SearchQueueBatchImpl.java b/core/src/main/java/com/gentics/mesh/core/data/search/impl/SearchQueueBatchImpl.java index 835fb11f2f..512743e030 100644 --- a/core/src/main/java/com/gentics/mesh/core/data/search/impl/SearchQueueBatchImpl.java +++ b/core/src/main/java/com/gentics/mesh/core/data/search/impl/SearchQueueBatchImpl.java @@ -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()) { diff --git a/core/src/test/java/com/gentics/mesh/core/group/GroupEndpointTest.java b/core/src/test/java/com/gentics/mesh/core/group/GroupEndpointTest.java index 2157e0f11d..a6c24795c2 100644 --- a/core/src/test/java/com/gentics/mesh/core/group/GroupEndpointTest.java +++ b/core/src/test/java/com/gentics/mesh/core/group/GroupEndpointTest.java @@ -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); @@ -124,7 +125,8 @@ public void testConflicingGroupCreation() throws Exception { try (NoTx noTx = db().noTx()) { role().grantPermissions(meshRoot().getGroupRoot(), CREATE_PERM); - MeshResponse future = client().createGroup(request).invoke(); + MeshResponse future = client().createGroup(request) + .invoke(); latchFor(future); assertSuccess(future); GroupResponse restGroup = future.result(); @@ -144,13 +146,15 @@ public void testCreateReadDelete() throws Exception { GroupCreateRequest request = new GroupCreateRequest(); request.setName(name); - MeshResponse future = client().createGroup(request).invoke(); + MeshResponse 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())); @@ -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 future = client().findGroups().invoke(); + MeshResponse 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 allGroups = new ArrayList<>(); for (int page = 1; page <= totalPages; page++) { - MeshResponse pageFuture = client().findGroups(new PagingParametersImpl(page, perPage)).invoke(); + MeshResponse pageFuture = client().findGroups(new PagingParametersImpl(page, perPage)) + .invoke(); latchFor(pageFuture); assertSuccess(pageFuture); restResponse = pageFuture.result(); @@ -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 filteredUserList = allGroups.parallelStream().filter(restGroup -> restGroup.getName().equals(extraGroupName)) + List 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 future = client().findGroups(new PagingParametersImpl(1, 0)).invoke(); + MeshResponse 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 @@ -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()); } } @@ -352,11 +387,13 @@ public void testUpdateGroupWithEmptyName() throws GenericRestException, Exceptio GroupUpdateRequest request = new GroupUpdateRequest(); request.setName(name); - MeshResponse future = client().updateGroup(group.getUuid(), request).invoke(); + MeshResponse 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()); } } @@ -372,7 +409,8 @@ public void testUpdateGroupWithConflictingName() throws GenericRestException, Ex GroupUpdateRequest request = new GroupUpdateRequest(); request.setName(alreadyUsedName); - MeshResponse future = client().updateGroup(group().getUuid(), request).invoke(); + MeshResponse future = client().updateGroup(group().getUuid(), request) + .invoke(); latchFor(future); expectException(future, CONFLICT, "group_conflicting_name", alreadyUsedName); @@ -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 future = client().createGroup(createReq).invoke(); + MeshResponse future = client().createGroup(createReq) + .invoke(); latchFor(future); } @@ -401,7 +440,8 @@ public void testReadWithRolePermsSync() throws Exception { int readCount = 100; for (int i = 0; i < readCount; i++) { - MeshResponse fut = client().findGroups(params).invoke(); + MeshResponse fut = client().findGroups(params) + .invoke(); latchFor(fut); GroupListResponse res = fut.result(); @@ -464,7 +504,8 @@ public void testUpdateMultithreaded() throws InterruptedException { CyclicBarrier barrier = prepareBarrier(nJobs); Set> 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); @@ -480,38 +521,39 @@ public void testReadByUuidMultithreaded() throws InterruptedException { Set> 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> 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> 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); @@ -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 future : set) { diff --git a/core/src/test/java/com/gentics/mesh/search/GroupSearchEndpointTest.java b/core/src/test/java/com/gentics/mesh/search/GroupSearchEndpointTest.java index eaef3802c7..68c2ab9814 100644 --- a/core/src/test/java/com/gentics/mesh/search/GroupSearchEndpointTest.java +++ b/core/src/test/java/com/gentics/mesh/search/GroupSearchEndpointTest.java @@ -1,11 +1,9 @@ package com.gentics.mesh.search; -import static com.gentics.mesh.assertj.MeshAssertions.assertThat; import static com.gentics.mesh.test.context.MeshTestHelper.call; import static com.gentics.mesh.test.context.MeshTestHelper.getSimpleTermQuery; -import static com.gentics.mesh.util.MeshAssert.assertSuccess; -import static com.gentics.mesh.util.MeshAssert.latchFor; import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import org.codehaus.jettison.json.JSONException; @@ -13,7 +11,6 @@ import com.gentics.mesh.core.rest.group.GroupListResponse; import com.gentics.mesh.core.rest.group.GroupResponse; -import com.gentics.mesh.rest.client.MeshResponse; import com.gentics.mesh.test.TestSize; import com.gentics.mesh.test.context.AbstractMeshTest; import com.gentics.mesh.test.context.MeshTestSetting; @@ -26,12 +23,13 @@ public class GroupSearchEndpointTest extends AbstractMeshTest implements BasicSe @Override public void testDocumentCreation() throws InterruptedException, JSONException { String groupName = "testgroup42a"; - createGroup(groupName); + for (int i = 0; i < 10; i++) { + createGroup(groupName + i); + } - MeshResponse searchFuture = client().searchGroups(getSimpleTermQuery("name.raw", groupName)).invoke(); - latchFor(searchFuture); - assertSuccess(searchFuture); - assertEquals(1, searchFuture.result().getData().size()); + GroupListResponse response = call(() -> client().searchGroups(getSimpleTermQuery("name.raw", groupName + 8))); + assertEquals(1, response.getData() + .size()); } @Test @@ -45,7 +43,9 @@ public void testBogusQuery() { // 2. Assert that search still works GroupListResponse result = call(() -> client().searchGroups(getSimpleTermQuery("uuid", uuid))); assertThat(result.getData()).hasSize(1); - assertEquals(uuid, result.getData().get(0).getUuid()); + assertEquals(uuid, result.getData() + .get(0) + .getUuid()); } @Test @@ -55,7 +55,9 @@ public void testSearchByUuid() throws InterruptedException, JSONException { GroupListResponse result = call(() -> client().searchGroups(getSimpleTermQuery("uuid", uuid))); assertThat(result.getData()).hasSize(1); - assertEquals(uuid, result.getData().get(0).getUuid()); + assertEquals(uuid, result.getData() + .get(0) + .getUuid()); } @Test @@ -65,7 +67,9 @@ public void testSearchByName() throws InterruptedException, JSONException { GroupListResponse result = call(() -> client().searchGroups(getSimpleTermQuery("name.raw", groupName))); assertThat(result.getData()).hasSize(1); - assertEquals(uuid, result.getData().get(0).getUuid()); + assertEquals(uuid, result.getData() + .get(0) + .getUuid()); } @Test diff --git a/core/src/test/java/com/gentics/mesh/search/NodeSearchEndpointGTest.java b/core/src/test/java/com/gentics/mesh/search/NodeSearchEndpointGTest.java index 06496e083a..6726766eab 100644 --- a/core/src/test/java/com/gentics/mesh/search/NodeSearchEndpointGTest.java +++ b/core/src/test/java/com/gentics/mesh/search/NodeSearchEndpointGTest.java @@ -8,7 +8,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.concurrent.CountDownLatch; -import java.util.stream.Collectors; import org.junit.Test; diff --git a/core/src/test/java/com/gentics/mesh/test/context/MeshTestHelper.java b/core/src/test/java/com/gentics/mesh/test/context/MeshTestHelper.java index 38d656004e..9bef9acf7a 100644 --- a/core/src/test/java/com/gentics/mesh/test/context/MeshTestHelper.java +++ b/core/src/test/java/com/gentics/mesh/test/context/MeshTestHelper.java @@ -109,7 +109,7 @@ public static T call(ClientHandler handler) { * @param handler * @param status * @return - * @throws Throwable + * @throws Throwable */ public static JsonObject call(ClientHandler handler, HttpResponseStatus status) throws Throwable { MeshResponse future; @@ -192,6 +192,17 @@ public static void validateFutures(Set> set) { } } + /** + * Wait for all responses and assert that the requests did not fail. + * + * @param set + * @param barrier + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws InvocationTargetException + * @throws NoSuchMethodException + * @throws SecurityException + */ public static void validateCreation(Set> set, CyclicBarrier barrier) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { Set uuids = new HashSet<>();