Rename StringSerializer to StringCacheSerializer
For consistency with other implementations. Change-Id: I8650437da646c46ace5e5302d9ae8b485c8cddfe
This commit is contained in:
@@ -23,7 +23,7 @@ import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CodingErrorAction;
|
||||
|
||||
public enum StringSerializer implements CacheSerializer<String> {
|
||||
public enum StringCacheSerializer implements CacheSerializer<String> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -17,7 +17,7 @@ package com.google.gerrit.server.git;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.cache.CacheModule;
|
||||
import com.google.gerrit.server.cache.StringSerializer;
|
||||
import com.google.gerrit.server.cache.StringCacheSerializer;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -35,7 +35,7 @@ public class TagCache {
|
||||
protected void configure() {
|
||||
persist(CACHE_NAME, String.class, TagSetHolder.class)
|
||||
.version(1)
|
||||
.keySerializer(StringSerializer.INSTANCE)
|
||||
.keySerializer(StringCacheSerializer.INSTANCE)
|
||||
.valueSerializer(TagSetHolder.Serializer.INSTANCE);
|
||||
bind(TagCache.class);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringSerializerTest {
|
||||
public class StringCacheSerializerTest {
|
||||
@Test
|
||||
public void serialize() {
|
||||
assertThat(StringSerializer.INSTANCE.serialize("")).isEmpty();
|
||||
assertThat(StringSerializer.INSTANCE.serialize("abc")).isEqualTo(new byte[] {'a', 'b', 'c'});
|
||||
assertThat(StringSerializer.INSTANCE.serialize("a\u1234c"))
|
||||
assertThat(StringCacheSerializer.INSTANCE.serialize("")).isEmpty();
|
||||
assertThat(StringCacheSerializer.INSTANCE.serialize("abc"))
|
||||
.isEqualTo(new byte[] {'a', 'b', 'c'});
|
||||
assertThat(StringCacheSerializer.INSTANCE.serialize("a\u1234c"))
|
||||
.isEqualTo(new byte[] {'a', (byte) 0xe1, (byte) 0x88, (byte) 0xb4, 'c'});
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ public class StringSerializerTest {
|
||||
public void serializeInvalidChar() {
|
||||
// Can't use UTF-8 for the test, since it can encode all Unicode code points.
|
||||
try {
|
||||
StringSerializer.serialize(StandardCharsets.US_ASCII, "\u1234");
|
||||
StringCacheSerializer.serialize(StandardCharsets.US_ASCII, "\u1234");
|
||||
assert_().fail("expected IllegalStateException");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertThat(expected).hasCauseThat().isInstanceOf(CharacterCodingException.class);
|
||||
@@ -43,10 +44,11 @@ public class StringSerializerTest {
|
||||
|
||||
@Test
|
||||
public void deserialize() {
|
||||
assertThat(StringSerializer.INSTANCE.deserialize(new byte[0])).isEmpty();
|
||||
assertThat(StringSerializer.INSTANCE.deserialize(new byte[] {'a', 'b', 'c'})).isEqualTo("abc");
|
||||
assertThat(StringCacheSerializer.INSTANCE.deserialize(new byte[0])).isEmpty();
|
||||
assertThat(StringCacheSerializer.INSTANCE.deserialize(new byte[] {'a', 'b', 'c'}))
|
||||
.isEqualTo("abc");
|
||||
assertThat(
|
||||
StringSerializer.INSTANCE.deserialize(
|
||||
StringCacheSerializer.INSTANCE.deserialize(
|
||||
new byte[] {'a', (byte) 0xe1, (byte) 0x88, (byte) 0xb4, 'c'}))
|
||||
.isEqualTo("a\u1234c");
|
||||
}
|
||||
@@ -54,7 +56,7 @@ public class StringSerializerTest {
|
||||
@Test
|
||||
public void deserializeInvalidChar() {
|
||||
try {
|
||||
StringSerializer.INSTANCE.deserialize(new byte[] {(byte) 0xff});
|
||||
StringCacheSerializer.INSTANCE.deserialize(new byte[] {(byte) 0xff});
|
||||
assert_().fail("expected IllegalStateException");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertThat(expected).hasCauseThat().isInstanceOf(CharacterCodingException.class);
|
||||
@@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.gerrit.server.cache.StringSerializer;
|
||||
import com.google.gerrit.server.cache.StringCacheSerializer;
|
||||
import com.google.gerrit.server.cache.h2.H2CacheImpl.SqlStore;
|
||||
import com.google.gerrit.server.cache.h2.H2CacheImpl.ValueHolder;
|
||||
import com.google.inject.TypeLiteral;
|
||||
@@ -42,8 +42,8 @@ public class H2CacheTest {
|
||||
new SqlStore<>(
|
||||
"jdbc:h2:mem:Test_" + id,
|
||||
KEY_TYPE,
|
||||
StringSerializer.INSTANCE,
|
||||
StringSerializer.INSTANCE,
|
||||
StringCacheSerializer.INSTANCE,
|
||||
StringCacheSerializer.INSTANCE,
|
||||
version,
|
||||
1 << 20,
|
||||
null);
|
||||
@@ -87,9 +87,9 @@ public class H2CacheTest {
|
||||
@Test
|
||||
public void stringSerializer() {
|
||||
String input = "foo";
|
||||
byte[] serialized = StringSerializer.INSTANCE.serialize(input);
|
||||
byte[] serialized = StringCacheSerializer.INSTANCE.serialize(input);
|
||||
assertThat(serialized).isEqualTo(new byte[] {'f', 'o', 'o'});
|
||||
assertThat(StringSerializer.INSTANCE.deserialize(serialized)).isEqualTo(input);
|
||||
assertThat(StringCacheSerializer.INSTANCE.deserialize(serialized)).isEqualTo(input);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user