summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Hiesel <hiesel@google.com>2016-09-21 22:30:58 +0200
committerDavid Pursehouse <dpursehouse@collab.net>2016-11-14 10:00:12 -0800
commit225da2dc6d23fcf40c59c21b0b83800813c73fef (patch)
tree5f22c1a0fb0f883d24e2fe54441e75a746ed6700
parent0d3dab22366cd90f8eb106293a46c28b57b56b0d (diff)
Add @Sandboxed annotation for classes and methods
There are some tests where it is especially hard to make sure that they are not influenced by other tests in the same class. This includes all indexer tests since some of them check the cardinality of a query result, which might change as more entities are added by other tests. This is a backport of the original change, adapted to work on stable-2.12. Change-Id: I74b40b2e7f95894dd666dcd87d97fd29b2d67c51
-rw-r--r--gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java3
-rw-r--r--gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/GerritServer.java19
-rw-r--r--gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/Sandboxed.java27
-rw-r--r--gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SandboxTest.java50
4 files changed, 96 insertions, 3 deletions
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
index 392db94010..84af20e56f 100644
--- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
@@ -256,7 +256,8 @@ public abstract class AbstractDaemonTest {
}
baseConfig.setString("gerrit", null, "tempSiteDir",
tempSiteDir.getRoot().getPath());
- if (classDesc.equals(methodDesc)) {
+ if (classDesc.equals(methodDesc) && !classDesc.sandboxed() &&
+ !methodDesc.sandboxed()) {
if (commonServer == null) {
commonServer = GerritServer.start(classDesc, baseConfig);
}
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/GerritServer.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/GerritServer.java
index 482e0408b6..5b0d311f0d 100644
--- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/GerritServer.java
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/GerritServer.java
@@ -41,6 +41,7 @@ import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.util.FS;
import java.io.File;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@@ -60,7 +61,8 @@ public class GerritServer {
return new AutoValue_GerritServer_Description(
configName,
true, // @UseLocalDisk is only valid on methods.
- testDesc.getTestClass().getAnnotation(NoHttpd.class) == null,
+ !has(NoHttpd.class, testDesc.getTestClass()),
+ has(Sandboxed.class, testDesc.getTestClass()),
null, // @GerritConfig is only valid on methods.
null); // @GerritConfigs is only valid on methods.
@@ -72,14 +74,27 @@ public class GerritServer {
configName,
testDesc.getAnnotation(UseLocalDisk.class) == null,
testDesc.getAnnotation(NoHttpd.class) == null
- && testDesc.getTestClass().getAnnotation(NoHttpd.class) == null,
+ && !has(NoHttpd.class, testDesc.getTestClass()),
+ testDesc.getAnnotation(Sandboxed.class) != null ||
+ has(Sandboxed.class, testDesc.getTestClass()),
testDesc.getAnnotation(GerritConfig.class),
testDesc.getAnnotation(GerritConfigs.class));
}
+ private static boolean has(
+ Class<? extends Annotation> annotation, Class<?> clazz) {
+ for (; clazz != null; clazz = clazz.getSuperclass()) {
+ if (clazz.getAnnotation(annotation) != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Nullable abstract String configName();
abstract boolean memory();
abstract boolean httpd();
+ abstract boolean sandboxed();
@Nullable abstract GerritConfig config();
@Nullable abstract GerritConfigs configs();
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/Sandboxed.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/Sandboxed.java
new file mode 100644
index 0000000000..11446e081b
--- /dev/null
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/Sandboxed.java
@@ -0,0 +1,27 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.acceptance;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface Sandboxed {
+}
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SandboxTest.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SandboxTest.java
new file mode 100644
index 0000000000..6ead34629e
--- /dev/null
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SandboxTest.java
@@ -0,0 +1,50 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.acceptance;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.server.account.PutUsername;
+
+import org.apache.http.HttpStatus;
+import org.junit.After;
+import org.junit.Test;
+
+@Sandboxed
+public class SandboxTest extends AbstractDaemonTest {
+ @After
+ public void addUser() throws Exception {
+ PutUsername.Input in = new PutUsername.Input();
+ in.username = "sandboxuser";
+ RestResponse r =
+ adminSession.put("/accounts/sandboxuser", in);
+ assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CREATED);
+ }
+
+ private void testUserNotPresent() throws Exception {
+ RestResponse r = adminSession.get("/accounts/sandboxuser");
+ assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
+ }
+
+ @Test
+ public void testUserNotPresent1() throws Exception {
+ testUserNotPresent();
+ }
+
+ @Test
+ public void testUserNotPresent2() throws Exception {
+ testUserNotPresent();
+ }
+}