Allow tests to create stale changes
Some operations fail if a change in the index is stale. E.g. the GetRelated REST endpoint fails with 500 Internal Server Error if the change in the index doesn't contain the latest patch set. To be able to test such situations AbstractDaemonTest provides new methods to disable/enable change index writes. A test can now create a stale change by disabling change index writes, updating the change without reindex and then re-enabling change index writes. Change-Id: Ia3b1904162c0ed5de6ecb6229d3995f31606d004 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
b59fe95148
commit
1c52ddab91
@ -1,6 +1,7 @@
|
||||
SRCS = glob(['src/test/java/com/google/gerrit/acceptance/*.java'])
|
||||
|
||||
DEPS = [
|
||||
'//gerrit-antlr:query_exception',
|
||||
'//gerrit-gpg:gpg',
|
||||
'//gerrit-launcher:launcher',
|
||||
'//gerrit-openid:openid',
|
||||
|
@ -3,6 +3,7 @@ load('//tools/bzl:java.bzl', 'java_library2')
|
||||
SRCS = glob(['src/test/java/com/google/gerrit/acceptance/*.java'])
|
||||
|
||||
DEPS = [
|
||||
'//gerrit-antlr:query_exception',
|
||||
'//gerrit-gpg:gpg',
|
||||
'//gerrit-launcher:launcher',
|
||||
'//gerrit-openid:openid',
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user