Acceptance tests: Disable HTTPD per class or method annotation
If HTTPD not used in tests, it doesn't make much sense to enable it. Using @NoHttpd on class or method it is now possible to disable HTTP entirely and is another small step making slow tests fast. With maturity of plugin API, more and more tests are going to move to plugin API driven tests from REST driven tests. Benchmark shows, that doing REST vs. plugin API comparisson: @Test public void rest() throws Exception { String changeId = createChange().getChangeId(); for (int i = 0; i < 1000; i++) { getRESTChange(changeId, ALL); } } @Test public void api() throws Exception { String changeId = createChange().getChangeId(); for (int i = 0; i < 1000; i++) { getPluginAPIChange(changeId, ALL); } } make on my machine ca. 2 sec. for plugin API vs. 10 sec. for REST: The whole Servlet/HTTP stack and Gson serialization and deserialization is out if the picture for API driven tests. Change-Id: If60170f06f466765d9602450043a1629a344d7ce
This commit is contained in:
parent
468eaa288e
commit
83ea0403b1
@ -93,7 +93,9 @@ public abstract class AbstractDaemonTest {
|
|||||||
@Override
|
@Override
|
||||||
public void evaluate() throws Throwable {
|
public void evaluate() throws Throwable {
|
||||||
boolean mem = description.getAnnotation(UseLocalDisk.class) == null;
|
boolean mem = description.getAnnotation(UseLocalDisk.class) == null;
|
||||||
beforeTest(config(description), mem);
|
boolean enableHttpd = description.getAnnotation(NoHttpd.class) == null
|
||||||
|
&& description.getTestClass().getAnnotation(NoHttpd.class) == null;
|
||||||
|
beforeTest(config(description), mem, enableHttpd);
|
||||||
base.evaluate();
|
base.evaluate();
|
||||||
afterTest();
|
afterTest();
|
||||||
}
|
}
|
||||||
@ -116,8 +118,8 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beforeTest(Config cfg, boolean memory) throws Exception {
|
private void beforeTest(Config cfg, boolean memory, boolean enableHttpd) throws Exception {
|
||||||
server = startServer(cfg, memory);
|
server = startServer(cfg, memory, enableHttpd);
|
||||||
server.getTestInjector().injectMembers(this);
|
server.getTestInjector().injectMembers(this);
|
||||||
admin = accounts.admin();
|
admin = accounts.admin();
|
||||||
user = accounts.user();
|
user = accounts.user();
|
||||||
@ -133,8 +135,9 @@ public abstract class AbstractDaemonTest {
|
|||||||
git = cloneProject(sshSession.getUrl() + "/" + project.get());
|
git = cloneProject(sshSession.getUrl() + "/" + project.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GerritServer startServer(Config cfg, boolean memory) throws Exception {
|
protected GerritServer startServer(Config cfg, boolean memory,
|
||||||
return GerritServer.start(cfg, memory);
|
boolean enableHttpd) throws Exception {
|
||||||
|
return GerritServer.start(cfg, memory, enableHttpd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void afterTest() throws Exception {
|
private void afterTest() throws Exception {
|
||||||
|
@ -49,7 +49,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class GerritServer {
|
public class GerritServer {
|
||||||
|
|
||||||
/** Returns fully started Gerrit server */
|
/** Returns fully started Gerrit server */
|
||||||
static GerritServer start(Config cfg, boolean memory) throws Exception {
|
static GerritServer start(Config cfg, boolean memory, boolean enableHttpd)
|
||||||
|
throws Exception {
|
||||||
final CyclicBarrier serverStarted = new CyclicBarrier(2);
|
final CyclicBarrier serverStarted = new CyclicBarrier(2);
|
||||||
final Daemon daemon = new Daemon(new Runnable() {
|
final Daemon daemon = new Daemon(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -71,6 +72,7 @@ public class GerritServer {
|
|||||||
cfg.setBoolean("httpd", null, "requestLog", false);
|
cfg.setBoolean("httpd", null, "requestLog", false);
|
||||||
cfg.setBoolean("sshd", null, "requestLog", false);
|
cfg.setBoolean("sshd", null, "requestLog", false);
|
||||||
cfg.setBoolean("index", "lucene", "testInmemory", true);
|
cfg.setBoolean("index", "lucene", "testInmemory", true);
|
||||||
|
daemon.setEnableHttpd(enableHttpd);
|
||||||
daemon.setLuceneModule(new LuceneIndexModule(
|
daemon.setLuceneModule(new LuceneIndexModule(
|
||||||
ChangeSchemas.getLatest().getVersion(),
|
ChangeSchemas.getLatest().getVersion(),
|
||||||
Runtime.getRuntime().availableProcessors(), null));
|
Runtime.getRuntime().availableProcessors(), null));
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (C) 2014 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 NoHttpd {
|
||||||
|
}
|
@ -17,6 +17,7 @@ package com.google.gerrit.acceptance.api.change;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
@ -30,6 +31,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class ChangeIT extends AbstractDaemonTest {
|
public class ChangeIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.acceptance.api.project;
|
package com.google.gerrit.acceptance.api.project;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class ProjectIT extends AbstractDaemonTest {
|
public class ProjectIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.acceptance.api.revision;
|
package com.google.gerrit.acceptance.api.revision;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||||
@ -27,6 +28,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class RevisionIT extends AbstractDaemonTest {
|
public class RevisionIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -18,6 +18,7 @@ import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
|||||||
import static com.google.gerrit.server.project.Util.grant;
|
import static com.google.gerrit.server.project.Util.grant;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.server.config.AllProjectsName;
|
import com.google.gerrit.server.config.AllProjectsName;
|
||||||
@ -33,6 +34,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class DraftChangeBlockedIT extends AbstractDaemonTest {
|
public class DraftChangeBlockedIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -14,11 +14,14 @@
|
|||||||
|
|
||||||
package com.google.gerrit.acceptance.git;
|
package com.google.gerrit.acceptance.git;
|
||||||
|
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class SshPushForReviewIT extends AbstractPushForReview {
|
public class SshPushForReviewIT extends AbstractPushForReview {
|
||||||
@Before
|
@Before
|
||||||
public void selectSshUrl() throws GitAPIException, IOException {
|
public void selectSshUrl() throws GitAPIException, IOException {
|
||||||
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.acceptance.SshSession;
|
import com.google.gerrit.acceptance.SshSession;
|
||||||
import com.google.gerrit.common.data.AccessSection;
|
import com.google.gerrit.common.data.AccessSection;
|
||||||
@ -62,6 +63,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class SubmitOnPushIT extends AbstractDaemonTest {
|
public class SubmitOnPushIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertNull;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class ListChangesOptionsIT extends AbstractDaemonTest {
|
public class ListChangesOptionsIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
private String changeId;
|
private String changeId;
|
||||||
|
@ -19,6 +19,7 @@ import static com.google.gerrit.extensions.common.ListChangesOption.DETAILED_LAB
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.common.data.LabelType;
|
import com.google.gerrit.common.data.LabelType;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
@ -36,6 +37,7 @@ import org.eclipse.jgit.lib.Repository;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class LabelTypeIT extends AbstractDaemonTest {
|
public class LabelTypeIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -155,6 +155,10 @@ public class Daemon extends SiteProgram {
|
|||||||
this.serverStarted = serverStarted;
|
this.serverStarted = serverStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEnableHttpd(boolean enable) {
|
||||||
|
httpd = enable;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int run() throws Exception {
|
public int run() throws Exception {
|
||||||
if (doInit) {
|
if (doInit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user