Merge "Allow tests to create stale changes"

This commit is contained in:
David Pursehouse
2016-09-07 07:36:48 +00:00
committed by Gerrit Code Review
4 changed files with 97 additions and 0 deletions

View File

@@ -74,6 +74,8 @@ import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.index.change.ChangeIndex;
import com.google.gerrit.server.index.change.ChangeIndexCollection;
import com.google.gerrit.server.index.change.ChangeIndexer;
import com.google.gerrit.server.mail.EmailHeader;
import com.google.gerrit.server.notedb.ChangeNoteUtil;
@@ -221,6 +223,9 @@ public abstract class AbstractDaemonTest {
@Inject
private EventRecorder.Factory eventRecorderFactory;
@Inject
private ChangeIndexCollection changeIndexes;
protected TestRepository<InMemoryRepository> testRepo;
protected GerritServer server;
protected TestAccount admin;
@@ -673,6 +678,22 @@ public abstract class AbstractDaemonTest {
atrScope.set(preDisableContext);
}
protected void disableChangeIndexWrites() {
for (ChangeIndex i : changeIndexes.getWriteIndexes()) {
if (!(i instanceof ReadOnlyChangeIndex)) {
changeIndexes.addWriteIndex(new ReadOnlyChangeIndex(i));
}
}
}
protected void enableChangeIndexWrites() {
for (ChangeIndex i : changeIndexes.getWriteIndexes()) {
if (i instanceof ReadOnlyChangeIndex) {
changeIndexes.addWriteIndex(((ReadOnlyChangeIndex)i).unwrap());
}
}
}
protected static Gson newGson() {
return OutputFormat.JSON_COMPACT.newGson();
}

View File

@@ -0,0 +1,74 @@
// 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 com.google.gerrit.reviewdb.client.Change.Id;
import com.google.gerrit.server.index.QueryOptions;
import com.google.gerrit.server.index.Schema;
import com.google.gerrit.server.index.change.ChangeIndex;
import com.google.gerrit.server.query.DataSource;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gerrit.server.query.change.ChangeData;
import java.io.IOException;
public class ReadOnlyChangeIndex implements ChangeIndex {
private final ChangeIndex index;
public ReadOnlyChangeIndex(ChangeIndex index) {
this.index = index;
}
public ChangeIndex unwrap() {
return index;
}
@Override
public Schema<ChangeData> getSchema() {
return index.getSchema();
}
@Override
public void close() {
index.close();
}
@Override
public void replace(ChangeData obj) throws IOException {
// do nothing
}
@Override
public void delete(Id key) throws IOException {
// do nothing
}
@Override
public void deleteAll() throws IOException {
// do nothing
}
@Override
public DataSource<ChangeData> getSource(Predicate<ChangeData> p,
QueryOptions opts) throws QueryParseException {
return index.getSource(p, opts);
}
@Override
public void markReady(boolean ready) throws IOException {
// do nothing
}
}