Move ProtoCacheSerializers to a more common location
We intend to reuse the methods of ProtoCacheSerializers for other protobuf conversions unrelated to CacheSerializers. Change-Id: I59acfd037969b1a0ae8d607cf8846876ccafbd16
This commit is contained in:
@@ -12,3 +12,13 @@ java_binary(
|
|||||||
"//lib/jgit/org.eclipse.jgit:jgit",
|
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
java_library(
|
||||||
|
name = "proto",
|
||||||
|
srcs = ["Protos.java"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//lib:gwtorm",
|
||||||
|
"//lib:protobuf",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package com.google.gerrit.server.cache.serialize;
|
package com.google.gerrit.proto;
|
||||||
|
|
||||||
import com.google.gwtorm.protobuf.ProtobufCodec;
|
import com.google.gwtorm.protobuf.ProtobufCodec;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
@@ -21,14 +21,14 @@ import com.google.protobuf.MessageLite;
|
|||||||
import com.google.protobuf.Parser;
|
import com.google.protobuf.Parser;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/** Static utilities for writing protobuf-based {@link CacheSerializer} implementations. */
|
/** Static utilities for dealing with protobuf-based objects. */
|
||||||
public class ProtoCacheSerializers {
|
public class Protos {
|
||||||
/**
|
/**
|
||||||
* Serializes a proto to a byte array.
|
* Serializes a proto to a byte array.
|
||||||
*
|
*
|
||||||
* <p>Guarantees deterministic serialization and thus is suitable for use in persistent caches.
|
* <p>Guarantees deterministic serialization. No matter whether the use case cares about
|
||||||
* Should be used in preference to {@link MessageLite#toByteArray()}, which is not guaranteed
|
* determinism or not, always use this method in preference to {@link MessageLite#toByteArray()},
|
||||||
* deterministic.
|
* which is not guaranteed deterministic.
|
||||||
*
|
*
|
||||||
* @param message the proto message to serialize.
|
* @param message the proto message to serialize.
|
||||||
* @return a byte array with the message contents.
|
* @return a byte array with the message contents.
|
||||||
@@ -49,9 +49,9 @@ public class ProtoCacheSerializers {
|
|||||||
/**
|
/**
|
||||||
* Serializes an object to a {@link ByteString} using a protobuf codec.
|
* Serializes an object to a {@link ByteString} using a protobuf codec.
|
||||||
*
|
*
|
||||||
* <p>Guarantees deterministic serialization and thus is suitable for use in persistent caches.
|
* <p>Guarantees deterministic serialization. No matter whether the use case cares about
|
||||||
* Should be used in preference to {@link ProtobufCodec#encodeToByteString(Object)}, which is not
|
* determinism or not, always use this method in preference to {@link
|
||||||
* guaranteed deterministic.
|
* ProtobufCodec#encodeToByteString(Object)}, which is not guaranteed deterministic.
|
||||||
*
|
*
|
||||||
* @param object the object to serialize.
|
* @param object the object to serialize.
|
||||||
* @param codec codec for serializing.
|
* @param codec codec for serializing.
|
||||||
@@ -84,5 +84,5 @@ public class ProtoCacheSerializers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProtoCacheSerializers() {}
|
private Protos() {}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,7 @@ java_library(
|
|||||||
"//java/com/google/gerrit/mail",
|
"//java/com/google/gerrit/mail",
|
||||||
"//java/com/google/gerrit/metrics",
|
"//java/com/google/gerrit/metrics",
|
||||||
"//java/com/google/gerrit/prettify:server",
|
"//java/com/google/gerrit/prettify:server",
|
||||||
|
"//java/com/google/gerrit/proto",
|
||||||
"//java/com/google/gerrit/reviewdb:server",
|
"//java/com/google/gerrit/reviewdb:server",
|
||||||
"//java/com/google/gerrit/server/cache/serialize",
|
"//java/com/google/gerrit/server/cache/serialize",
|
||||||
"//java/com/google/gerrit/server/ioutil",
|
"//java/com/google/gerrit/server/ioutil",
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ import com.google.auto.value.AutoValue;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableSetMultimap;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
import com.google.common.collect.SetMultimap;
|
import com.google.common.collect.SetMultimap;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.server.cache.proto.Cache.AllExternalIdsProto;
|
import com.google.gerrit.server.cache.proto.Cache.AllExternalIdsProto;
|
||||||
import com.google.gerrit.server.cache.proto.Cache.AllExternalIdsProto.ExternalIdProto;
|
import com.google.gerrit.server.cache.proto.Cache.AllExternalIdsProto.ExternalIdProto;
|
||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/** Cache value containing all external IDs. */
|
/** Cache value containing all external IDs. */
|
||||||
@@ -68,7 +68,7 @@ public abstract class AllExternalIds {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(extId -> toProto(idConverter, extId))
|
.map(extId -> toProto(idConverter, extId))
|
||||||
.forEach(allBuilder::addExternalId);
|
.forEach(allBuilder::addExternalId);
|
||||||
return ProtoCacheSerializers.toByteArray(allBuilder.build());
|
return Protos.toByteArray(allBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExternalIdProto toProto(ObjectIdConverter idConverter, ExternalId externalId) {
|
private static ExternalIdProto toProto(ObjectIdConverter idConverter, ExternalId externalId) {
|
||||||
@@ -92,7 +92,7 @@ public abstract class AllExternalIds {
|
|||||||
public AllExternalIds deserialize(byte[] in) {
|
public AllExternalIds deserialize(byte[] in) {
|
||||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||||
return create(
|
return create(
|
||||||
ProtoCacheSerializers.parseUnchecked(AllExternalIdsProto.parser(), in)
|
Protos.parseUnchecked(AllExternalIdsProto.parser(), in)
|
||||||
.getExternalIdList()
|
.getExternalIdList()
|
||||||
.stream()
|
.stream()
|
||||||
.map(proto -> toExternalId(idConverter, proto))
|
.map(proto -> toExternalId(idConverter, proto))
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ import com.google.common.cache.Cache;
|
|||||||
import com.google.gerrit.extensions.auth.oauth.OAuthToken;
|
import com.google.gerrit.extensions.auth.oauth.OAuthToken;
|
||||||
import com.google.gerrit.extensions.auth.oauth.OAuthTokenEncrypter;
|
import com.google.gerrit.extensions.auth.oauth.OAuthTokenEncrypter;
|
||||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.server.cache.CacheModule;
|
import com.google.gerrit.server.cache.CacheModule;
|
||||||
import com.google.gerrit.server.cache.proto.Cache.OAuthTokenProto;
|
import com.google.gerrit.server.cache.proto.Cache.OAuthTokenProto;
|
||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.IntKeyCacheSerializer;
|
import com.google.gerrit.server.cache.serialize.IntKeyCacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -57,7 +57,7 @@ public class OAuthTokenCache {
|
|||||||
static class Serializer implements CacheSerializer<OAuthToken> {
|
static class Serializer implements CacheSerializer<OAuthToken> {
|
||||||
@Override
|
@Override
|
||||||
public byte[] serialize(OAuthToken object) {
|
public byte[] serialize(OAuthToken object) {
|
||||||
return ProtoCacheSerializers.toByteArray(
|
return Protos.toByteArray(
|
||||||
OAuthTokenProto.newBuilder()
|
OAuthTokenProto.newBuilder()
|
||||||
.setToken(object.getToken())
|
.setToken(object.getToken())
|
||||||
.setSecret(object.getSecret())
|
.setSecret(object.getSecret())
|
||||||
@@ -69,7 +69,7 @@ public class OAuthTokenCache {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OAuthToken deserialize(byte[] in) {
|
public OAuthToken deserialize(byte[] in) {
|
||||||
OAuthTokenProto proto = ProtoCacheSerializers.parseUnchecked(OAuthTokenProto.parser(), in);
|
OAuthTokenProto proto = Protos.parseUnchecked(OAuthTokenProto.parser(), in);
|
||||||
return new OAuthToken(
|
return new OAuthToken(
|
||||||
proto.getToken(),
|
proto.getToken(),
|
||||||
proto.getSecret(),
|
proto.getSecret(),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ java_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//java/com/google/gerrit/common:annotations",
|
"//java/com/google/gerrit/common:annotations",
|
||||||
|
"//java/com/google/gerrit/proto",
|
||||||
"//lib:guava",
|
"//lib:guava",
|
||||||
"//lib:gwtorm",
|
"//lib:gwtorm",
|
||||||
"//lib:protobuf",
|
"//lib:protobuf",
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.google.common.collect.FluentIterable;
|
|||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.extensions.client.ChangeKind;
|
import com.google.gerrit.extensions.client.ChangeKind;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
@@ -33,7 +34,6 @@ import com.google.gerrit.server.cache.proto.Cache.ChangeKindKeyProto;
|
|||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.EnumCacheSerializer;
|
import com.google.gerrit.server.cache.serialize.EnumCacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.git.InMemoryInserter;
|
import com.google.gerrit.server.git.InMemoryInserter;
|
||||||
@@ -146,7 +146,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] serialize(Key object) {
|
public byte[] serialize(Key object) {
|
||||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||||
return ProtoCacheSerializers.toByteArray(
|
return Protos.toByteArray(
|
||||||
ChangeKindKeyProto.newBuilder()
|
ChangeKindKeyProto.newBuilder()
|
||||||
.setPrior(idConverter.toByteString(object.prior()))
|
.setPrior(idConverter.toByteString(object.prior()))
|
||||||
.setNext(idConverter.toByteString(object.next()))
|
.setNext(idConverter.toByteString(object.next()))
|
||||||
@@ -156,8 +156,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Key deserialize(byte[] in) {
|
public Key deserialize(byte[] in) {
|
||||||
ChangeKindKeyProto proto =
|
ChangeKindKeyProto proto = Protos.parseUnchecked(ChangeKindKeyProto.parser(), in);
|
||||||
ProtoCacheSerializers.parseUnchecked(ChangeKindKeyProto.parser(), in);
|
|
||||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||||
return create(
|
return create(
|
||||||
idConverter.fromByteString(proto.getPrior()),
|
idConverter.fromByteString(proto.getPrior()),
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ import com.google.common.cache.Weigher;
|
|||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
import com.google.gerrit.extensions.client.SubmitType;
|
import com.google.gerrit.extensions.client.SubmitType;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.server.cache.CacheModule;
|
import com.google.gerrit.server.cache.CacheModule;
|
||||||
import com.google.gerrit.server.cache.proto.Cache.MergeabilityKeyProto;
|
import com.google.gerrit.server.cache.proto.Cache.MergeabilityKeyProto;
|
||||||
import com.google.gerrit.server.cache.serialize.BooleanCacheSerializer;
|
import com.google.gerrit.server.cache.serialize.BooleanCacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import com.google.gerrit.server.git.CodeReviewCommit;
|
import com.google.gerrit.server.git.CodeReviewCommit;
|
||||||
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
|
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
|
||||||
import com.google.gerrit.server.submit.SubmitDryRun;
|
import com.google.gerrit.server.submit.SubmitDryRun;
|
||||||
@@ -143,7 +143,7 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] serialize(EntryKey object) {
|
public byte[] serialize(EntryKey object) {
|
||||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||||
return ProtoCacheSerializers.toByteArray(
|
return Protos.toByteArray(
|
||||||
MergeabilityKeyProto.newBuilder()
|
MergeabilityKeyProto.newBuilder()
|
||||||
.setCommit(idConverter.toByteString(object.getCommit()))
|
.setCommit(idConverter.toByteString(object.getCommit()))
|
||||||
.setInto(idConverter.toByteString(object.getInto()))
|
.setInto(idConverter.toByteString(object.getInto()))
|
||||||
@@ -154,8 +154,7 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntryKey deserialize(byte[] in) {
|
public EntryKey deserialize(byte[] in) {
|
||||||
MergeabilityKeyProto proto =
|
MergeabilityKeyProto proto = Protos.parseUnchecked(MergeabilityKeyProto.parser(), in);
|
||||||
ProtoCacheSerializers.parseUnchecked(MergeabilityKeyProto.parser(), in);
|
|
||||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||||
return new EntryKey(
|
return new EntryKey(
|
||||||
idConverter.fromByteString(proto.getCommit()),
|
idConverter.fromByteString(proto.getCommit()),
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ package com.google.gerrit.server.git;
|
|||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.cache.proto.Cache.TagSetHolderProto;
|
import com.google.gerrit.server.cache.proto.Cache.TagSetHolderProto;
|
||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
@@ -111,13 +111,12 @@ public class TagSetHolder {
|
|||||||
if (tags != null) {
|
if (tags != null) {
|
||||||
b.setTags(tags.toProto());
|
b.setTags(tags.toProto());
|
||||||
}
|
}
|
||||||
return ProtoCacheSerializers.toByteArray(b.build());
|
return Protos.toByteArray(b.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TagSetHolder deserialize(byte[] in) {
|
public TagSetHolder deserialize(byte[] in) {
|
||||||
TagSetHolderProto proto =
|
TagSetHolderProto proto = Protos.parseUnchecked(TagSetHolderProto.parser(), in);
|
||||||
ProtoCacheSerializers.parseUnchecked(TagSetHolderProto.parser(), in);
|
|
||||||
TagSetHolder holder = new TagSetHolder(new Project.NameKey(proto.getProjectName()));
|
TagSetHolder holder = new TagSetHolder(new Project.NameKey(proto.getProjectName()));
|
||||||
if (proto.hasTags()) {
|
if (proto.hasTags()) {
|
||||||
holder.tags = TagSet.fromProto(proto.getTags());
|
holder.tags = TagSet.fromProto(proto.getTags());
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.google.common.cache.Cache;
|
|||||||
import com.google.common.collect.Table;
|
import com.google.common.collect.Table;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.client.RefNames;
|
import com.google.gerrit.reviewdb.client.RefNames;
|
||||||
@@ -29,7 +30,6 @@ import com.google.gerrit.server.cache.CacheModule;
|
|||||||
import com.google.gerrit.server.cache.proto.Cache.ChangeNotesKeyProto;
|
import com.google.gerrit.server.cache.proto.Cache.ChangeNotesKeyProto;
|
||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import com.google.gerrit.server.notedb.AbstractChangeNotes.Args;
|
import com.google.gerrit.server.notedb.AbstractChangeNotes.Args;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk;
|
import com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -85,7 +85,7 @@ public class ChangeNotesCache {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] serialize(Key object) {
|
public byte[] serialize(Key object) {
|
||||||
return ProtoCacheSerializers.toByteArray(
|
return Protos.toByteArray(
|
||||||
ChangeNotesKeyProto.newBuilder()
|
ChangeNotesKeyProto.newBuilder()
|
||||||
.setProject(object.project().get())
|
.setProject(object.project().get())
|
||||||
.setChangeId(object.changeId().get())
|
.setChangeId(object.changeId().get())
|
||||||
@@ -95,8 +95,7 @@ public class ChangeNotesCache {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Key deserialize(byte[] in) {
|
public Key deserialize(byte[] in) {
|
||||||
ChangeNotesKeyProto proto =
|
ChangeNotesKeyProto proto = Protos.parseUnchecked(ChangeNotesKeyProto.parser(), in);
|
||||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesKeyProto.parser(), in);
|
|
||||||
return Key.create(
|
return Key.create(
|
||||||
new Project.NameKey(proto.getProject()),
|
new Project.NameKey(proto.getProject()),
|
||||||
new Change.Id(proto.getChangeId()),
|
new Change.Id(proto.getChangeId()),
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ import static com.google.common.base.Preconditions.checkState;
|
|||||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||||
import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap;
|
import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap;
|
||||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||||
|
import static com.google.gerrit.proto.Protos.toByteString;
|
||||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
|
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
|
||||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.MESSAGE_CODEC;
|
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.MESSAGE_CODEC;
|
||||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
|
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
|
||||||
import static com.google.gerrit.server.cache.serialize.ProtoCacheSerializers.toByteString;
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
@@ -40,6 +40,7 @@ import com.google.common.collect.Table;
|
|||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.common.data.SubmitRecord;
|
import com.google.gerrit.common.data.SubmitRecord;
|
||||||
import com.google.gerrit.mail.Address;
|
import com.google.gerrit.mail.Address;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
@@ -60,7 +61,6 @@ import com.google.gerrit.server.cache.proto.Cache.ChangeNotesStateProto.Reviewer
|
|||||||
import com.google.gerrit.server.cache.proto.Cache.ChangeNotesStateProto.ReviewerStatusUpdateProto;
|
import com.google.gerrit.server.cache.proto.Cache.ChangeNotesStateProto.ReviewerStatusUpdateProto;
|
||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import com.google.gerrit.server.index.change.ChangeField.StoredSubmitRecord;
|
import com.google.gerrit.server.index.change.ChangeField.StoredSubmitRecord;
|
||||||
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
|
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -487,7 +487,7 @@ public abstract class ChangeNotesState {
|
|||||||
b.setReadOnlyUntil(object.readOnlyUntil().getTime()).setHasReadOnlyUntil(true);
|
b.setReadOnlyUntil(object.readOnlyUntil().getTime()).setHasReadOnlyUntil(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProtoCacheSerializers.toByteArray(b.build());
|
return Protos.toByteArray(b.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChangeColumnsProto toChangeColumnsProto(ChangeColumns cols) {
|
private static ChangeColumnsProto toChangeColumnsProto(ChangeColumns cols) {
|
||||||
@@ -555,8 +555,7 @@ public abstract class ChangeNotesState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChangeNotesState deserialize(byte[] in) {
|
public ChangeNotesState deserialize(byte[] in) {
|
||||||
ChangeNotesStateProto proto =
|
ChangeNotesStateProto proto = Protos.parseUnchecked(ChangeNotesStateProto.parser(), in);
|
||||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesStateProto.parser(), in);
|
|
||||||
Change.Id changeId = new Change.Id(proto.getChangeId());
|
Change.Id changeId = new Change.Id(proto.getChangeId());
|
||||||
|
|
||||||
ChangeNotesState.Builder b =
|
ChangeNotesState.Builder b =
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import com.google.common.base.Converter;
|
|||||||
import com.google.common.base.Enums;
|
import com.google.common.base.Enums;
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
import com.google.gerrit.extensions.client.SubmitType;
|
import com.google.gerrit.extensions.client.SubmitType;
|
||||||
|
import com.google.gerrit.proto.Protos;
|
||||||
import com.google.gerrit.server.cache.proto.Cache.ConflictKeyProto;
|
import com.google.gerrit.server.cache.proto.Cache.ConflictKeyProto;
|
||||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||||
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
||||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
|
||||||
import org.eclipse.jgit.lib.AnyObjectId;
|
import org.eclipse.jgit.lib.AnyObjectId;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public abstract class ConflictKey {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] serialize(ConflictKey object) {
|
public byte[] serialize(ConflictKey object) {
|
||||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||||
return ProtoCacheSerializers.toByteArray(
|
return Protos.toByteArray(
|
||||||
ConflictKeyProto.newBuilder()
|
ConflictKeyProto.newBuilder()
|
||||||
.setCommit(idConverter.toByteString(object.commit()))
|
.setCommit(idConverter.toByteString(object.commit()))
|
||||||
.setOtherCommit(idConverter.toByteString(object.otherCommit()))
|
.setOtherCommit(idConverter.toByteString(object.otherCommit()))
|
||||||
@@ -81,7 +81,7 @@ public abstract class ConflictKey {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConflictKey deserialize(byte[] in) {
|
public ConflictKey deserialize(byte[] in) {
|
||||||
ConflictKeyProto proto = ProtoCacheSerializers.parseUnchecked(ConflictKeyProto.parser(), in);
|
ConflictKeyProto proto = Protos.parseUnchecked(ConflictKeyProto.parser(), in);
|
||||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||||
return create(
|
return create(
|
||||||
idConverter.fromByteString(proto.getCommit()),
|
idConverter.fromByteString(proto.getCommit()),
|
||||||
|
|||||||
@@ -4,15 +4,13 @@ junit_tests(
|
|||||||
name = "proto_tests",
|
name = "proto_tests",
|
||||||
srcs = glob(["*.java"]),
|
srcs = glob(["*.java"]),
|
||||||
deps = [
|
deps = [
|
||||||
|
"//java/com/google/gerrit/proto",
|
||||||
"//java/com/google/gerrit/testing:gerrit-test-util",
|
"//java/com/google/gerrit/testing:gerrit-test-util",
|
||||||
"//lib/truth:truth-proto-extension",
|
|
||||||
"//proto:reviewdb_java_proto",
|
|
||||||
|
|
||||||
# TODO(dborowitz): These are already runtime_deps of
|
|
||||||
# truth-proto-extension, but either omitting them or adding them as
|
|
||||||
# runtime_deps to this target fails with:
|
|
||||||
# class file for com.google.common.collect.Multimap not found
|
|
||||||
"//lib:guava",
|
"//lib:guava",
|
||||||
|
"//lib:protobuf",
|
||||||
"//lib/truth",
|
"//lib/truth",
|
||||||
|
"//lib/truth:truth-proto-extension",
|
||||||
|
"//proto:cache_java_proto",
|
||||||
|
"//proto:reviewdb_java_proto",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package com.google.gerrit.server.cache.serialize;
|
package com.google.gerrit.proto;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assert_;
|
import static com.google.common.truth.Truth.assert_;
|
||||||
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
|
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
|
||||||
@@ -23,7 +23,7 @@ import com.google.gerrit.testing.GerritBaseTests;
|
|||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ProtoCacheSerializersTest extends GerritBaseTests {
|
public class ProtosTest extends GerritBaseTests {
|
||||||
@Test
|
@Test
|
||||||
public void parseUncheckedWrongProtoType() {
|
public void parseUncheckedWrongProtoType() {
|
||||||
ChangeNotesKeyProto proto =
|
ChangeNotesKeyProto proto =
|
||||||
@@ -32,9 +32,9 @@ public class ProtoCacheSerializersTest extends GerritBaseTests {
|
|||||||
.setChangeId(1234)
|
.setChangeId(1234)
|
||||||
.setId(ByteString.copyFromUtf8("foo"))
|
.setId(ByteString.copyFromUtf8("foo"))
|
||||||
.build();
|
.build();
|
||||||
byte[] bytes = ProtoCacheSerializers.toByteArray(proto);
|
byte[] bytes = Protos.toByteArray(proto);
|
||||||
try {
|
try {
|
||||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
||||||
assert_().fail("expected IllegalArgumentException");
|
assert_().fail("expected IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Expected.
|
// Expected.
|
||||||
@@ -45,7 +45,7 @@ public class ProtoCacheSerializersTest extends GerritBaseTests {
|
|||||||
public void parseUncheckedInvalidData() {
|
public void parseUncheckedInvalidData() {
|
||||||
byte[] bytes = new byte[] {0x00};
|
byte[] bytes = new byte[] {0x00};
|
||||||
try {
|
try {
|
||||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
||||||
assert_().fail("expected IllegalArgumentException");
|
assert_().fail("expected IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Expected.
|
// Expected.
|
||||||
@@ -60,8 +60,7 @@ public class ProtoCacheSerializersTest extends GerritBaseTests {
|
|||||||
.setChangeId(1234)
|
.setChangeId(1234)
|
||||||
.setId(ByteString.copyFromUtf8("foo"))
|
.setId(ByteString.copyFromUtf8("foo"))
|
||||||
.build();
|
.build();
|
||||||
byte[] bytes = ProtoCacheSerializers.toByteArray(proto);
|
byte[] bytes = Protos.toByteArray(proto);
|
||||||
assertThat(ProtoCacheSerializers.parseUnchecked(ChangeNotesKeyProto.parser(), bytes))
|
assertThat(Protos.parseUnchecked(ChangeNotesKeyProto.parser(), bytes)).isEqualTo(proto);
|
||||||
.isEqualTo(proto);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,7 @@ junit_tests(
|
|||||||
"//java/com/google/gerrit/lifecycle",
|
"//java/com/google/gerrit/lifecycle",
|
||||||
"//java/com/google/gerrit/mail",
|
"//java/com/google/gerrit/mail",
|
||||||
"//java/com/google/gerrit/metrics",
|
"//java/com/google/gerrit/metrics",
|
||||||
|
"//java/com/google/gerrit/proto",
|
||||||
"//java/com/google/gerrit/reviewdb:server",
|
"//java/com/google/gerrit/reviewdb:server",
|
||||||
"//java/com/google/gerrit/server",
|
"//java/com/google/gerrit/server",
|
||||||
"//java/com/google/gerrit/server/cache/serialize",
|
"//java/com/google/gerrit/server/cache/serialize",
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ package com.google.gerrit.server.notedb;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
|
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
|
||||||
|
import static com.google.gerrit.proto.Protos.toByteString;
|
||||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
|
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
|
||||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.MESSAGE_CODEC;
|
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.MESSAGE_CODEC;
|
||||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
|
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
|
||||||
import static com.google.gerrit.server.cache.serialize.ProtoCacheSerializers.toByteString;
|
|
||||||
import static com.google.gerrit.server.cache.testing.SerializedClassSubject.assertThatSerializedClass;
|
import static com.google.gerrit.server.cache.testing.SerializedClassSubject.assertThatSerializedClass;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|||||||
Reference in New Issue
Block a user