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",
|
||||
],
|
||||
)
|
||||
|
||||
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
|
||||
// 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.protobuf.ByteString;
|
||||
@@ -21,14 +21,14 @@ import com.google.protobuf.MessageLite;
|
||||
import com.google.protobuf.Parser;
|
||||
import java.io.IOException;
|
||||
|
||||
/** Static utilities for writing protobuf-based {@link CacheSerializer} implementations. */
|
||||
public class ProtoCacheSerializers {
|
||||
/** Static utilities for dealing with protobuf-based objects. */
|
||||
public class Protos {
|
||||
/**
|
||||
* Serializes a proto to a byte array.
|
||||
*
|
||||
* <p>Guarantees deterministic serialization and thus is suitable for use in persistent caches.
|
||||
* Should be used in preference to {@link MessageLite#toByteArray()}, which is not guaranteed
|
||||
* deterministic.
|
||||
* <p>Guarantees deterministic serialization. No matter whether the use case cares about
|
||||
* determinism or not, always use this method in preference to {@link MessageLite#toByteArray()},
|
||||
* which is not guaranteed deterministic.
|
||||
*
|
||||
* @param message the proto message to serialize.
|
||||
* @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.
|
||||
*
|
||||
* <p>Guarantees deterministic serialization and thus is suitable for use in persistent caches.
|
||||
* Should be used in preference to {@link ProtobufCodec#encodeToByteString(Object)}, which is not
|
||||
* guaranteed deterministic.
|
||||
* <p>Guarantees deterministic serialization. No matter whether the use case cares about
|
||||
* determinism or not, always use this method in preference to {@link
|
||||
* ProtobufCodec#encodeToByteString(Object)}, which is not guaranteed deterministic.
|
||||
*
|
||||
* @param object the object to serialize.
|
||||
* @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/metrics",
|
||||
"//java/com/google/gerrit/prettify:server",
|
||||
"//java/com/google/gerrit/proto",
|
||||
"//java/com/google/gerrit/reviewdb:server",
|
||||
"//java/com/google/gerrit/server/cache/serialize",
|
||||
"//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.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import com.google.gerrit.proto.Protos;
|
||||
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.ExternalIdProto;
|
||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||
import com.google.gerrit.server.cache.serialize.ObjectIdConverter;
|
||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
||||
import java.util.Collection;
|
||||
|
||||
/** Cache value containing all external IDs. */
|
||||
@@ -68,7 +68,7 @@ public abstract class AllExternalIds {
|
||||
.stream()
|
||||
.map(extId -> toProto(idConverter, extId))
|
||||
.forEach(allBuilder::addExternalId);
|
||||
return ProtoCacheSerializers.toByteArray(allBuilder.build());
|
||||
return Protos.toByteArray(allBuilder.build());
|
||||
}
|
||||
|
||||
private static ExternalIdProto toProto(ObjectIdConverter idConverter, ExternalId externalId) {
|
||||
@@ -92,7 +92,7 @@ public abstract class AllExternalIds {
|
||||
public AllExternalIds deserialize(byte[] in) {
|
||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||
return create(
|
||||
ProtoCacheSerializers.parseUnchecked(AllExternalIdsProto.parser(), in)
|
||||
Protos.parseUnchecked(AllExternalIdsProto.parser(), in)
|
||||
.getExternalIdList()
|
||||
.stream()
|
||||
.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.OAuthTokenEncrypter;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.proto.Protos;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.cache.CacheModule;
|
||||
import com.google.gerrit.server.cache.proto.Cache.OAuthTokenProto;
|
||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||
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.Module;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -57,7 +57,7 @@ public class OAuthTokenCache {
|
||||
static class Serializer implements CacheSerializer<OAuthToken> {
|
||||
@Override
|
||||
public byte[] serialize(OAuthToken object) {
|
||||
return ProtoCacheSerializers.toByteArray(
|
||||
return Protos.toByteArray(
|
||||
OAuthTokenProto.newBuilder()
|
||||
.setToken(object.getToken())
|
||||
.setSecret(object.getSecret())
|
||||
@@ -69,7 +69,7 @@ public class OAuthTokenCache {
|
||||
|
||||
@Override
|
||||
public OAuthToken deserialize(byte[] in) {
|
||||
OAuthTokenProto proto = ProtoCacheSerializers.parseUnchecked(OAuthTokenProto.parser(), in);
|
||||
OAuthTokenProto proto = Protos.parseUnchecked(OAuthTokenProto.parser(), in);
|
||||
return new OAuthToken(
|
||||
proto.getToken(),
|
||||
proto.getSecret(),
|
||||
|
||||
@@ -4,6 +4,7 @@ java_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//java/com/google/gerrit/common:annotations",
|
||||
"//java/com/google/gerrit/proto",
|
||||
"//lib:guava",
|
||||
"//lib:gwtorm",
|
||||
"//lib:protobuf",
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
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.PatchSet;
|
||||
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.EnumCacheSerializer;
|
||||
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.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.InMemoryInserter;
|
||||
@@ -146,7 +146,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
|
||||
@Override
|
||||
public byte[] serialize(Key object) {
|
||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||
return ProtoCacheSerializers.toByteArray(
|
||||
return Protos.toByteArray(
|
||||
ChangeKindKeyProto.newBuilder()
|
||||
.setPrior(idConverter.toByteString(object.prior()))
|
||||
.setNext(idConverter.toByteString(object.next()))
|
||||
@@ -156,8 +156,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
|
||||
|
||||
@Override
|
||||
public Key deserialize(byte[] in) {
|
||||
ChangeKindKeyProto proto =
|
||||
ProtoCacheSerializers.parseUnchecked(ChangeKindKeyProto.parser(), in);
|
||||
ChangeKindKeyProto proto = Protos.parseUnchecked(ChangeKindKeyProto.parser(), in);
|
||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||
return create(
|
||||
idConverter.fromByteString(proto.getPrior()),
|
||||
|
||||
@@ -25,13 +25,13 @@ import com.google.common.cache.Weigher;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.proto.Protos;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.server.cache.CacheModule;
|
||||
import com.google.gerrit.server.cache.proto.Cache.MergeabilityKeyProto;
|
||||
import com.google.gerrit.server.cache.serialize.BooleanCacheSerializer;
|
||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||
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.CodeReviewRevWalk;
|
||||
import com.google.gerrit.server.submit.SubmitDryRun;
|
||||
@@ -143,7 +143,7 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
|
||||
@Override
|
||||
public byte[] serialize(EntryKey object) {
|
||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||
return ProtoCacheSerializers.toByteArray(
|
||||
return Protos.toByteArray(
|
||||
MergeabilityKeyProto.newBuilder()
|
||||
.setCommit(idConverter.toByteString(object.getCommit()))
|
||||
.setInto(idConverter.toByteString(object.getInto()))
|
||||
@@ -154,8 +154,7 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
|
||||
|
||||
@Override
|
||||
public EntryKey deserialize(byte[] in) {
|
||||
MergeabilityKeyProto proto =
|
||||
ProtoCacheSerializers.parseUnchecked(MergeabilityKeyProto.parser(), in);
|
||||
MergeabilityKeyProto proto = Protos.parseUnchecked(MergeabilityKeyProto.parser(), in);
|
||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||
return new EntryKey(
|
||||
idConverter.fromByteString(proto.getCommit()),
|
||||
|
||||
@@ -17,10 +17,10 @@ package com.google.gerrit.server.git;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.proto.Protos;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.cache.proto.Cache.TagSetHolderProto;
|
||||
import com.google.gerrit.server.cache.serialize.CacheSerializer;
|
||||
import com.google.gerrit.server.cache.serialize.ProtoCacheSerializers;
|
||||
import java.util.Collection;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
@@ -111,13 +111,12 @@ public class TagSetHolder {
|
||||
if (tags != null) {
|
||||
b.setTags(tags.toProto());
|
||||
}
|
||||
return ProtoCacheSerializers.toByteArray(b.build());
|
||||
return Protos.toByteArray(b.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagSetHolder deserialize(byte[] in) {
|
||||
TagSetHolderProto proto =
|
||||
ProtoCacheSerializers.parseUnchecked(TagSetHolderProto.parser(), in);
|
||||
TagSetHolderProto proto = Protos.parseUnchecked(TagSetHolderProto.parser(), in);
|
||||
TagSetHolder holder = new TagSetHolder(new Project.NameKey(proto.getProjectName()));
|
||||
if (proto.hasTags()) {
|
||||
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.flogger.FluentLogger;
|
||||
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.Project;
|
||||
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.serialize.CacheSerializer;
|
||||
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.ChangeNotesCommit.ChangeNotesRevWalk;
|
||||
import com.google.inject.Inject;
|
||||
@@ -85,7 +85,7 @@ public class ChangeNotesCache {
|
||||
|
||||
@Override
|
||||
public byte[] serialize(Key object) {
|
||||
return ProtoCacheSerializers.toByteArray(
|
||||
return Protos.toByteArray(
|
||||
ChangeNotesKeyProto.newBuilder()
|
||||
.setProject(object.project().get())
|
||||
.setChangeId(object.changeId().get())
|
||||
@@ -95,8 +95,7 @@ public class ChangeNotesCache {
|
||||
|
||||
@Override
|
||||
public Key deserialize(byte[] in) {
|
||||
ChangeNotesKeyProto proto =
|
||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesKeyProto.parser(), in);
|
||||
ChangeNotesKeyProto proto = Protos.parseUnchecked(ChangeNotesKeyProto.parser(), in);
|
||||
return Key.create(
|
||||
new Project.NameKey(proto.getProject()),
|
||||
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.ImmutableListMultimap.toImmutableListMultimap;
|
||||
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.MESSAGE_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 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.data.SubmitRecord;
|
||||
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.Branch;
|
||||
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.serialize.CacheSerializer;
|
||||
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.notedb.NoteDbChangeState.PrimaryStorage;
|
||||
import com.google.gson.Gson;
|
||||
@@ -487,7 +487,7 @@ public abstract class ChangeNotesState {
|
||||
b.setReadOnlyUntil(object.readOnlyUntil().getTime()).setHasReadOnlyUntil(true);
|
||||
}
|
||||
|
||||
return ProtoCacheSerializers.toByteArray(b.build());
|
||||
return Protos.toByteArray(b.build());
|
||||
}
|
||||
|
||||
private static ChangeColumnsProto toChangeColumnsProto(ChangeColumns cols) {
|
||||
@@ -555,8 +555,7 @@ public abstract class ChangeNotesState {
|
||||
|
||||
@Override
|
||||
public ChangeNotesState deserialize(byte[] in) {
|
||||
ChangeNotesStateProto proto =
|
||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesStateProto.parser(), in);
|
||||
ChangeNotesStateProto proto = Protos.parseUnchecked(ChangeNotesStateProto.parser(), in);
|
||||
Change.Id changeId = new Change.Id(proto.getChangeId());
|
||||
|
||||
ChangeNotesState.Builder b =
|
||||
|
||||
@@ -20,10 +20,10 @@ import com.google.common.base.Converter;
|
||||
import com.google.common.base.Enums;
|
||||
import com.google.common.collect.Ordering;
|
||||
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.serialize.CacheSerializer;
|
||||
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.ObjectId;
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract class ConflictKey {
|
||||
@Override
|
||||
public byte[] serialize(ConflictKey object) {
|
||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||
return ProtoCacheSerializers.toByteArray(
|
||||
return Protos.toByteArray(
|
||||
ConflictKeyProto.newBuilder()
|
||||
.setCommit(idConverter.toByteString(object.commit()))
|
||||
.setOtherCommit(idConverter.toByteString(object.otherCommit()))
|
||||
@@ -81,7 +81,7 @@ public abstract class ConflictKey {
|
||||
|
||||
@Override
|
||||
public ConflictKey deserialize(byte[] in) {
|
||||
ConflictKeyProto proto = ProtoCacheSerializers.parseUnchecked(ConflictKeyProto.parser(), in);
|
||||
ConflictKeyProto proto = Protos.parseUnchecked(ConflictKeyProto.parser(), in);
|
||||
ObjectIdConverter idConverter = ObjectIdConverter.create();
|
||||
return create(
|
||||
idConverter.fromByteString(proto.getCommit()),
|
||||
|
||||
@@ -4,15 +4,13 @@ junit_tests(
|
||||
name = "proto_tests",
|
||||
srcs = glob(["*.java"]),
|
||||
deps = [
|
||||
"//java/com/google/gerrit/proto",
|
||||
"//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:protobuf",
|
||||
"//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
|
||||
// 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.extensions.proto.ProtoTruth.assertThat;
|
||||
@@ -23,7 +23,7 @@ import com.google.gerrit.testing.GerritBaseTests;
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProtoCacheSerializersTest extends GerritBaseTests {
|
||||
public class ProtosTest extends GerritBaseTests {
|
||||
@Test
|
||||
public void parseUncheckedWrongProtoType() {
|
||||
ChangeNotesKeyProto proto =
|
||||
@@ -32,9 +32,9 @@ public class ProtoCacheSerializersTest extends GerritBaseTests {
|
||||
.setChangeId(1234)
|
||||
.setId(ByteString.copyFromUtf8("foo"))
|
||||
.build();
|
||||
byte[] bytes = ProtoCacheSerializers.toByteArray(proto);
|
||||
byte[] bytes = Protos.toByteArray(proto);
|
||||
try {
|
||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
||||
Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
||||
assert_().fail("expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected.
|
||||
@@ -45,7 +45,7 @@ public class ProtoCacheSerializersTest extends GerritBaseTests {
|
||||
public void parseUncheckedInvalidData() {
|
||||
byte[] bytes = new byte[] {0x00};
|
||||
try {
|
||||
ProtoCacheSerializers.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
||||
Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes);
|
||||
assert_().fail("expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected.
|
||||
@@ -60,8 +60,7 @@ public class ProtoCacheSerializersTest extends GerritBaseTests {
|
||||
.setChangeId(1234)
|
||||
.setId(ByteString.copyFromUtf8("foo"))
|
||||
.build();
|
||||
byte[] bytes = ProtoCacheSerializers.toByteArray(proto);
|
||||
assertThat(ProtoCacheSerializers.parseUnchecked(ChangeNotesKeyProto.parser(), bytes))
|
||||
.isEqualTo(proto);
|
||||
byte[] bytes = Protos.toByteArray(proto);
|
||||
assertThat(Protos.parseUnchecked(ChangeNotesKeyProto.parser(), bytes)).isEqualTo(proto);
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ junit_tests(
|
||||
"//java/com/google/gerrit/lifecycle",
|
||||
"//java/com/google/gerrit/mail",
|
||||
"//java/com/google/gerrit/metrics",
|
||||
"//java/com/google/gerrit/proto",
|
||||
"//java/com/google/gerrit/reviewdb:server",
|
||||
"//java/com/google/gerrit/server",
|
||||
"//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.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.MESSAGE_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 com.google.common.collect.ImmutableList;
|
||||
|
||||
Reference in New Issue
Block a user