diff --git a/tests/common/src/main/java/com/gentics/mesh/test/ClientHelper.java b/tests/common/src/main/java/com/gentics/mesh/test/ClientHelper.java index a656c24a9e..740532eb8a 100644 --- a/tests/common/src/main/java/com/gentics/mesh/test/ClientHelper.java +++ b/tests/common/src/main/java/com/gentics/mesh/test/ClientHelper.java @@ -11,6 +11,7 @@ import static org.junit.Assert.fail; import java.util.Locale; +import java.util.Objects; import java.util.function.Function; import com.gentics.mesh.core.data.i18n.I18NUtil; @@ -246,4 +247,18 @@ public static void expectFailureMessage(Throwable e, HttpResponseStatus status, fail("Unhandled exception"); } } + + public static boolean isFailureMessage(Throwable e, HttpResponseStatus status) { + if (e instanceof GenericRestException) { + GenericRestException exception = (GenericRestException) e; + return Objects.equals(status, exception.getStatus()); + } else if (e instanceof MeshRestClientMessageException) { + MeshRestClientMessageException exception = (MeshRestClientMessageException) e; + return Objects.equals(status.code(), exception.getStatusCode()); + } else if (e != null && e.getCause() != null && e.getCause() != e) { + return isFailureMessage(e.getCause(), status); + } else { + return false; + } + } } diff --git a/tests/context-orientdb/src/main/java/com/gentics/mesh/core/project/OrientDBProjectEndpointTest.java b/tests/context-orientdb/src/main/java/com/gentics/mesh/core/project/OrientDBProjectEndpointTest.java index 3a6dad9b77..04d0b8e2ab 100644 --- a/tests/context-orientdb/src/main/java/com/gentics/mesh/core/project/OrientDBProjectEndpointTest.java +++ b/tests/context-orientdb/src/main/java/com/gentics/mesh/core/project/OrientDBProjectEndpointTest.java @@ -1,24 +1,31 @@ package com.gentics.mesh.core.project; import static com.gentics.mesh.test.ClientHelper.call; +import static com.gentics.mesh.test.ClientHelper.isFailureMessage; import static com.gentics.mesh.test.ElasticsearchTestMode.TRACKING; import static org.assertj.core.api.Assertions.assertThat; +import java.util.concurrent.TimeoutException; + import org.junit.Test; import com.gentics.mesh.core.rest.project.ProjectResponse; import com.gentics.mesh.test.MeshTestSetting; import com.gentics.mesh.test.TestSize; +import io.netty.handler.codec.http.HttpResponseStatus; + @MeshTestSetting(elasticsearch = TRACKING, testSize = TestSize.FULL, startServer = true) public class OrientDBProjectEndpointTest extends ProjectEndpointTest { /** * Test renaming, deleting and re-creating a project (together with project name cache). + * @throws InterruptedException + * @throws TimeoutException */ @Test - public void testRenameDeleteCreateProject() { + public void testRenameDeleteCreateProject() throws InterruptedException, TimeoutException { // create project named "project" ProjectResponse project = createProject("project"); @@ -30,8 +37,25 @@ public void testRenameDeleteCreateProject() { project = updateProject(project.getUuid(), "newproject"); assertThat(mesh().projectNameCache().size()).as("Project name cache size").isEqualTo(0); + long maxWaitMs = 1000; + long delayMs = 100; + boolean repeat = false; + // get tag families of newproject (this will put project into cache) - call(() -> client().findTagFamilies("newproject")); + long start = System.currentTimeMillis(); + do { + try { + call(() -> client().findTagFamilies("newproject")); + repeat = false; + } catch (Throwable t) { + if (isFailureMessage(t, HttpResponseStatus.NOT_FOUND) && (System.currentTimeMillis() - start) < maxWaitMs) { + Thread.sleep(delayMs); + repeat = true; + } else { + throw t; + } + } + } while (repeat); assertThat(mesh().projectNameCache().size()).as("Project name cache size").isEqualTo(1); // delete "newproject"