Merge changes from topic "remove-misc-gwtorm"
* changes: Replace InMemoryAccountPatchReviewStore with a config option Return ImmutableList from ResultSet Copy ResultSet from gwtorm into index.query package Move IndexedQuery to query subpackage
This commit is contained in:
@@ -39,6 +39,7 @@ import com.google.gerrit.server.config.GerritRuntime;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
||||
import com.google.gerrit.server.schema.JdbcAccountPatchReviewStore;
|
||||
import com.google.gerrit.server.ssh.NoSshModule;
|
||||
import com.google.gerrit.server.util.SocketUtil;
|
||||
import com.google.gerrit.server.util.SystemLog;
|
||||
@@ -388,6 +389,8 @@ public class GerritServer implements AutoCloseable {
|
||||
cfg.setBoolean("sshd", null, "requestLog", false);
|
||||
cfg.setBoolean("index", "lucene", "testInmemory", true);
|
||||
cfg.setString("gitweb", null, "cgi", "");
|
||||
cfg.setString(
|
||||
"accountPatchReviewDb", null, "url", JdbcAccountPatchReviewStore.TEST_IN_MEMORY_URL);
|
||||
daemon.setEnableHttpd(desc.httpd());
|
||||
daemon.setLuceneModule(LuceneIndexModule.singleVersionAllLatest(0, isSlave(baseConfig)));
|
||||
daemon.setDatabaseForTesting(
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.google.gson.FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -38,8 +39,10 @@ import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.Schema;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.ListResultSet;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.index.query.ResultSet;
|
||||
import com.google.gerrit.proto.Protos;
|
||||
import com.google.gerrit.reviewdb.converter.ProtoConverter;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
@@ -51,7 +54,6 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import com.google.protobuf.MessageLite;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -62,7 +64,6 @@ import java.net.URLEncoder;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -385,7 +386,6 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
|
||||
private <T> ResultSet<T> readImpl(Function<JsonObject, T> mapper) throws OrmException {
|
||||
try {
|
||||
List<T> results = Collections.emptyList();
|
||||
String uri = getURI(index, SEARCH);
|
||||
Response response =
|
||||
performRequest(HttpPost.METHOD_NAME, uri, search, Collections.emptyMap());
|
||||
@@ -396,34 +396,19 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
new JsonParser().parse(content).getAsJsonObject().getAsJsonObject("hits");
|
||||
if (obj.get("hits") != null) {
|
||||
JsonArray json = obj.getAsJsonArray("hits");
|
||||
results = Lists.newArrayListWithCapacity(json.size());
|
||||
ImmutableList.Builder<T> results = ImmutableList.builderWithExpectedSize(json.size());
|
||||
for (int i = 0; i < json.size(); i++) {
|
||||
T mapperResult = mapper.apply(json.get(i).getAsJsonObject());
|
||||
if (mapperResult != null) {
|
||||
results.add(mapperResult);
|
||||
}
|
||||
}
|
||||
return new ListResultSet<>(results.build());
|
||||
}
|
||||
} else {
|
||||
logger.atSevere().log(statusLine.getReasonPhrase());
|
||||
}
|
||||
final List<T> r = Collections.unmodifiableList(results);
|
||||
return new ResultSet<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return r.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> toList() {
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Do nothing.
|
||||
}
|
||||
};
|
||||
return new ListResultSet<>(ImmutableList.of());
|
||||
} catch (IOException e) {
|
||||
throw new OrmException(e);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.index;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.IndexPredicate;
|
||||
@@ -21,7 +22,6 @@ import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -95,7 +95,7 @@ public interface Index<K, V> {
|
||||
*/
|
||||
default Optional<V> get(K key, QueryOptions opts) throws IOException {
|
||||
opts = opts.withStart(0).withLimit(2);
|
||||
List<V> results;
|
||||
ImmutableList<V> results;
|
||||
try {
|
||||
results = getSource(keyPredicate(key), opts).read().toList();
|
||||
} catch (QueryParseException e) {
|
||||
@@ -120,7 +120,7 @@ public interface Index<K, V> {
|
||||
*/
|
||||
default Optional<FieldBundle> getRaw(K key, QueryOptions opts) throws IOException {
|
||||
opts = opts.withStart(0).withLimit(2);
|
||||
List<FieldBundle> results;
|
||||
ImmutableList<FieldBundle> results;
|
||||
try {
|
||||
results = getSource(keyPredicate(key), opts).readRaw().toList();
|
||||
} catch (QueryParseException e) {
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
package com.google.gerrit.index.project;
|
||||
|
||||
import com.google.gerrit.index.Index;
|
||||
import com.google.gerrit.index.IndexedQuery;
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.IndexedQuery;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
|
||||
@@ -21,10 +21,8 @@ import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gwtorm.server.ListResultSet;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.OrmRuntimeException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.index.query;
|
||||
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
|
||||
public interface DataSource<T> {
|
||||
/** @return an estimate of the number of results from {@link #read()}. */
|
||||
|
||||
@@ -12,18 +12,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.index;
|
||||
package com.google.gerrit.index.query;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.IndexPredicate;
|
||||
import com.google.gerrit.index.query.Paginated;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.index.Index;
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
47
java/com/google/gerrit/index/query/ListResultSet.java
Normal file
47
java/com/google/gerrit/index/query/ListResultSet.java
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
//
|
||||
// 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.index.query;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ListResultSet<T> implements ResultSet<T> {
|
||||
private ImmutableList<T> items;
|
||||
|
||||
public ListResultSet(List<T> r) {
|
||||
items = ImmutableList.copyOf(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return toList().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<T> toList() {
|
||||
if (items == null) {
|
||||
throw new IllegalStateException("Results already obtained");
|
||||
}
|
||||
ImmutableList<T> r = items;
|
||||
items = null;
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
items = null;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.index.query;
|
||||
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
|
||||
public interface Paginated<T> {
|
||||
QueryOptions getOptions();
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.google.gerrit.index.Index;
|
||||
import com.google.gerrit.index.IndexCollection;
|
||||
import com.google.gerrit.index.IndexConfig;
|
||||
import com.google.gerrit.index.IndexRewriter;
|
||||
import com.google.gerrit.index.IndexedQuery;
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.SchemaDefinitions;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
@@ -40,7 +39,6 @@ import com.google.gerrit.metrics.Timer1;
|
||||
import com.google.gerrit.server.logging.CallerFinder;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.OrmRuntimeException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -268,7 +266,7 @@ public abstract class QueryProcessor<T> {
|
||||
|
||||
out = new ArrayList<>(cnt);
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
List<T> matchesList = matches.get(i).toList();
|
||||
ImmutableList<T> matchesList = matches.get(i).toList();
|
||||
logger.atFine().log(
|
||||
"Matches[%d]:\n%s",
|
||||
i, lazy(() -> matchesList.stream().map(this::formatForLogging).collect(toSet())));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.index.query;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,15 +23,15 @@ import java.util.List;
|
||||
@AutoValue
|
||||
public abstract class QueryResult<T> {
|
||||
public static <T> QueryResult<T> create(
|
||||
@Nullable String query, Predicate<T> predicate, int limit, List<T> entites) {
|
||||
@Nullable String query, Predicate<T> predicate, int limit, List<T> entities) {
|
||||
boolean more;
|
||||
if (entites.size() > limit) {
|
||||
if (entities.size() > limit) {
|
||||
more = true;
|
||||
entites = entites.subList(0, limit);
|
||||
entities = entities.subList(0, limit);
|
||||
} else {
|
||||
more = false;
|
||||
}
|
||||
return new AutoValue_QueryResult<>(query, predicate, entites, more);
|
||||
return new AutoValue_QueryResult<>(query, predicate, ImmutableList.copyOf(entities), more);
|
||||
}
|
||||
|
||||
/** @return the original query string, or null if the query was created programmatically. */
|
||||
@@ -41,7 +42,7 @@ public abstract class QueryResult<T> {
|
||||
public abstract Predicate<T> predicate();
|
||||
|
||||
/** @return the query results. */
|
||||
public abstract List<T> entities();
|
||||
public abstract ImmutableList<T> entities();
|
||||
|
||||
/**
|
||||
* @return whether the query could be retried with a higher start/limit to produce more results.
|
||||
|
||||
52
java/com/google/gerrit/index/query/ResultSet.java
Normal file
52
java/com/google/gerrit/index/query/ResultSet.java
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
//
|
||||
// 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.index.query;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Result from any data store query function.
|
||||
*
|
||||
* @param <T> type of entity being returned by the query.
|
||||
*/
|
||||
public interface ResultSet<T> extends Iterable<T> {
|
||||
/**
|
||||
* Obtain an iterator to loop through the results.
|
||||
*
|
||||
* <p>The iterator can be obtained only once. When the iterator completes ( <code>hasNext()</code>
|
||||
* returns false) {@link #close()} will be automatically called.
|
||||
*/
|
||||
@Override
|
||||
Iterator<T> iterator();
|
||||
|
||||
/**
|
||||
* Materialize all results as a single list.
|
||||
*
|
||||
* <p>Prior to returning {@link #close()} is invoked. This method must not be combined with {@link
|
||||
* #iterator()} on the same instance.
|
||||
*
|
||||
* @return immutable list of the complete results.
|
||||
*/
|
||||
ImmutableList<T> toList();
|
||||
|
||||
/**
|
||||
* Close the result, discarding any further results.
|
||||
*
|
||||
* <p>This method may be invoked more than once. Its main use is to stop obtaining results before
|
||||
* the iterator has finished.
|
||||
*/
|
||||
void close();
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
@@ -37,18 +38,15 @@ import com.google.gerrit.index.Schema;
|
||||
import com.google.gerrit.index.Schema.Values;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.ListResultSet;
|
||||
import com.google.gerrit.index.query.ResultSet;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.index.IndexUtils;
|
||||
import com.google.gerrit.server.logging.LoggingContextAwareExecutorService;
|
||||
import com.google.gerrit.server.logging.LoggingContextAwareScheduledExecutorService;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -494,32 +492,16 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
|
||||
searcher = acquire();
|
||||
int realLimit = opts.start() + opts.limit();
|
||||
TopFieldDocs docs = searcher.search(query, realLimit, sort);
|
||||
List<T> result = new ArrayList<>(docs.scoreDocs.length);
|
||||
ImmutableList.Builder<T> b = ImmutableList.builderWithExpectedSize(docs.scoreDocs.length);
|
||||
for (int i = opts.start(); i < docs.scoreDocs.length; i++) {
|
||||
ScoreDoc sd = docs.scoreDocs[i];
|
||||
Document doc = searcher.doc(sd.doc, opts.fields());
|
||||
T mapperResult = mapper.apply(doc);
|
||||
if (mapperResult != null) {
|
||||
result.add(mapperResult);
|
||||
b.add(mapperResult);
|
||||
}
|
||||
}
|
||||
final List<T> r = Collections.unmodifiableList(result);
|
||||
return new ResultSet<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return r.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> toList() {
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Do nothing.
|
||||
}
|
||||
};
|
||||
return new ListResultSet<>(b.build());
|
||||
} catch (IOException e) {
|
||||
throw new OrmException(e);
|
||||
} finally {
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
@@ -40,6 +41,7 @@ import com.google.gerrit.index.Schema;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.index.query.ResultSet;
|
||||
import com.google.gerrit.proto.Protos;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -62,7 +64,6 @@ import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeDataSource;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.OrmRuntimeException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.protobuf.MessageLite;
|
||||
@@ -333,7 +334,8 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
} catch (IOException e) {
|
||||
throw new OrmException(e);
|
||||
}
|
||||
List<FieldBundle> fieldBundles = documents.stream().map(rawDocumentMapper).collect(toList());
|
||||
ImmutableList<FieldBundle> fieldBundles =
|
||||
documents.stream().map(rawDocumentMapper).collect(toImmutableList());
|
||||
return new ResultSet<FieldBundle>() {
|
||||
@Override
|
||||
public Iterator<FieldBundle> iterator() {
|
||||
@@ -341,7 +343,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FieldBundle> toList() {
|
||||
public ImmutableList<FieldBundle> toList() {
|
||||
return fieldBundles;
|
||||
}
|
||||
|
||||
@@ -401,15 +403,16 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChangeData> toList() {
|
||||
public ImmutableList<ChangeData> toList() {
|
||||
try {
|
||||
List<Document> docs = future.get();
|
||||
List<ChangeData> result = new ArrayList<>(docs.size());
|
||||
ImmutableList.Builder<ChangeData> result =
|
||||
ImmutableList.builderWithExpectedSize(docs.size());
|
||||
String idFieldName = LEGACY_ID.getName();
|
||||
for (Document doc : docs) {
|
||||
result.add(toChangeData(fields(doc, fields), fields, idFieldName));
|
||||
}
|
||||
return result;
|
||||
return result.build();
|
||||
} catch (InterruptedException e) {
|
||||
close();
|
||||
throw new OrmRuntimeException(e);
|
||||
|
||||
@@ -90,7 +90,6 @@ import com.google.gerrit.server.plugins.PluginGuiceEnvironment;
|
||||
import com.google.gerrit.server.plugins.PluginModule;
|
||||
import com.google.gerrit.server.project.DefaultProjectNameLockManager;
|
||||
import com.google.gerrit.server.restapi.RestApiModule;
|
||||
import com.google.gerrit.server.schema.InMemoryAccountPatchReviewStore;
|
||||
import com.google.gerrit.server.schema.JdbcAccountPatchReviewStore;
|
||||
import com.google.gerrit.server.schema.NoteDbSchemaVersionCheck;
|
||||
import com.google.gerrit.server.securestore.DefaultSecureStore;
|
||||
@@ -404,10 +403,7 @@ public class Daemon extends SiteProgram {
|
||||
modules.add(new WorkQueue.Module());
|
||||
modules.add(new StreamEventsApiListener.Module());
|
||||
modules.add(new EventBroker.Module());
|
||||
modules.add(
|
||||
inMemoryTest
|
||||
? new InMemoryAccountPatchReviewStore.Module()
|
||||
: new JdbcAccountPatchReviewStore.Module(config));
|
||||
modules.add(new JdbcAccountPatchReviewStore.Module(config));
|
||||
modules.add(new SysExecutorModule());
|
||||
modules.add(new DiffExecutorModule());
|
||||
modules.add(new MimeUtil2Module());
|
||||
|
||||
@@ -17,9 +17,9 @@ package com.google.gerrit.server.index.account;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.gerrit.index.Index;
|
||||
import com.google.gerrit.index.IndexedQuery;
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.IndexedQuery;
|
||||
import com.google.gerrit.index.query.Matchable;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
|
||||
@@ -19,25 +19,25 @@ import static com.google.gerrit.server.index.change.ChangeField.CHANGE;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.index.IndexConfig;
|
||||
import com.google.gerrit.index.IndexedQuery;
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.IndexPredicate;
|
||||
import com.google.gerrit.index.query.IndexedQuery;
|
||||
import com.google.gerrit.index.query.Matchable;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.index.query.ResultSet;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeDataSource;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -98,8 +98,8 @@ public class IndexedChangeQuery extends IndexedQuery<Change.Id, ChangeData>
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChangeData> toList() {
|
||||
List<ChangeData> r = rs.toList();
|
||||
public ImmutableList<ChangeData> toList() {
|
||||
ImmutableList<ChangeData> r = rs.toList();
|
||||
for (ChangeData cd : r) {
|
||||
fromSource.put(cd, currSource);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ package com.google.gerrit.server.index.group;
|
||||
|
||||
import com.google.gerrit.index.Index;
|
||||
import com.google.gerrit.index.IndexConfig;
|
||||
import com.google.gerrit.index.IndexedQuery;
|
||||
import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.query.DataSource;
|
||||
import com.google.gerrit.index.query.IndexedQuery;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
package com.google.gerrit.server.query.change;
|
||||
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.ListResultSet;
|
||||
import com.google.gerrit.index.query.OrPredicate;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.ResultSet;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwtorm.server.ListResultSet;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.google.gerrit.index.QueryOptions;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.index.query.ResultSet;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
import com.google.gerrit.metrics.Description.Units;
|
||||
import com.google.gerrit.metrics.MetricMaker;
|
||||
@@ -57,7 +58,6 @@ import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.gerrit.server.query.account.AccountPredicates;
|
||||
import com.google.gerrit.server.query.account.AccountQueryBuilder;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
// Copyright (C) 2017 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.server.schema;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.server.change.AccountPatchReviewStore;
|
||||
import com.google.gwtorm.jdbc.SimpleDataSource;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class InMemoryAccountPatchReviewStore extends JdbcAccountPatchReviewStore {
|
||||
@VisibleForTesting
|
||||
public static class Module extends LifecycleModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
InMemoryAccountPatchReviewStore inMemoryStore = new InMemoryAccountPatchReviewStore();
|
||||
DynamicItem.bind(binder(), AccountPatchReviewStore.class).toInstance(inMemoryStore);
|
||||
listener().toInstance(inMemoryStore);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an in-memory H2 database to store the reviewed flags. This should be used for tests
|
||||
* only.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
private InMemoryAccountPatchReviewStore() {
|
||||
super(newDataSource());
|
||||
}
|
||||
|
||||
private static synchronized DataSource newDataSource() {
|
||||
final Properties p = new Properties();
|
||||
p.setProperty("driver", "org.h2.Driver");
|
||||
// DB_CLOSE_DELAY=-1: By default the content of an in-memory H2 database is lost at the moment
|
||||
// the last connection is closed. This option keeps the content as long as the vm lives.
|
||||
p.setProperty("url", "jdbc:h2:mem:account_patch_reviews;DB_CLOSE_DELAY=-1");
|
||||
try {
|
||||
return new SimpleDataSource(p);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Unable to create test datasource", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.schema;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.primitives.Ints;
|
||||
@@ -48,6 +49,12 @@ public abstract class JdbcAccountPatchReviewStore
|
||||
implements AccountPatchReviewStore, LifecycleListener {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
// DB_CLOSE_DELAY=-1: By default the content of an in-memory H2 database is lost at the moment the
|
||||
// last connection is closed. This option keeps the content as long as the VM lives.
|
||||
@VisibleForTesting
|
||||
public static final String TEST_IN_MEMORY_URL =
|
||||
"jdbc:h2:mem:account_patch_reviews;DB_CLOSE_DELAY=-1";
|
||||
|
||||
private static final String ACCOUNT_PATCH_REVIEW_DB = "accountPatchReviewDb";
|
||||
private static final String H2_DB = "h2";
|
||||
private static final String MARIADB = "mariadb";
|
||||
@@ -109,10 +116,6 @@ public abstract class JdbcAccountPatchReviewStore
|
||||
this.ds = createDataSource(cfg, sitePaths, threadSettingsConfig);
|
||||
}
|
||||
|
||||
protected JdbcAccountPatchReviewStore(DataSource ds) {
|
||||
this.ds = ds;
|
||||
}
|
||||
|
||||
private static String getUrl(@GerritServerConfig Config cfg, SitePaths sitePaths) {
|
||||
String url = cfg.getString(ACCOUNT_PATCH_REVIEW_DB, null, URL);
|
||||
if (url == null) {
|
||||
|
||||
@@ -77,7 +77,7 @@ import com.google.gerrit.server.permissions.DefaultPermissionBackendModule;
|
||||
import com.google.gerrit.server.plugins.ServerInformationImpl;
|
||||
import com.google.gerrit.server.project.DefaultProjectNameLockManager;
|
||||
import com.google.gerrit.server.restapi.RestApiModule;
|
||||
import com.google.gerrit.server.schema.InMemoryAccountPatchReviewStore;
|
||||
import com.google.gerrit.server.schema.JdbcAccountPatchReviewStore;
|
||||
import com.google.gerrit.server.schema.SchemaCreator;
|
||||
import com.google.gerrit.server.schema.SchemaCreatorImpl;
|
||||
import com.google.gerrit.server.securestore.DefaultSecureStore;
|
||||
@@ -112,6 +112,8 @@ public class InMemoryModule extends FactoryModule {
|
||||
}
|
||||
|
||||
public static void setDefaults(Config cfg) {
|
||||
cfg.setString(
|
||||
"accountPatchReviewDb", null, "url", JdbcAccountPatchReviewStore.TEST_IN_MEMORY_URL);
|
||||
cfg.setEnum("auth", null, "type", AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT);
|
||||
cfg.setString("gerrit", null, "allProjects", "Test-Projects");
|
||||
cfg.setString("gerrit", null, "basePath", "git");
|
||||
@@ -215,7 +217,6 @@ public class InMemoryModule extends FactoryModule {
|
||||
install(new FakeEmailSender.Module());
|
||||
install(new SignedTokenEmailTokenVerifier.Module());
|
||||
install(new GpgModule(cfg));
|
||||
install(new InMemoryAccountPatchReviewStore.Module());
|
||||
install(new LocalMergeSuperSetComputation.Module());
|
||||
|
||||
bind(AllAccountsIndexer.class).toProvider(Providers.of(null));
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.google.gerrit.index.Schema;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.index.query.ResultSet;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeDataSource;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
|
||||
Reference in New Issue
Block a user