Java Code Examples for com.google.common.testing.SerializableTester#reserialize()

The following examples show how to use com.google.common.testing.SerializableTester#reserialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IsCacheReserializable.java    From caffeine with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matchesSafely(T original, Description description) {
  desc = new DescriptionBuilder(description);

  T copy = SerializableTester.reserialize(original);

  if (original instanceof AsyncLoadingCache<?, ?>) {
    @SuppressWarnings("unchecked")
    AsyncLoadingCache<Object, Object> asyncCache = (AsyncLoadingCache<Object, Object>) original;
    @SuppressWarnings("unchecked")
    AsyncLoadingCache<Object, Object> asyncCopy = (AsyncLoadingCache<Object, Object>) copy;
    checkAsynchronousCache(asyncCache, asyncCopy, desc);
  } else if (original instanceof Cache<?, ?>) {
    @SuppressWarnings("unchecked")
    Cache<Object, Object> syncCache = (Cache<Object, Object>) original;
    @SuppressWarnings("unchecked")
    Cache<Object, Object> syncCopy = (Cache<Object, Object>) copy;
    checkSynchronousCache(syncCache, syncCopy, desc);
  } else {
    throw new UnsupportedOperationException();
  }

  return desc.matches();
}
 
Example 2
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void allFieldsAreSerialized_withMixedEmpty() {
  DummySerializableAutoValue autoValue =
      DummySerializableAutoValue.builder().setA(A).setB(B).setOptionalC(C).build();

  DummySerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 3
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void multiplePropertiesSameType_allFieldsSerialized() {
  MultiplePropertiesSameType autoValue =
      MultiplePropertiesSameType.builder().setA("A").setB("B").build();

  MultiplePropertiesSameType actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 4
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void immutableMap_allFieldsSetAndSerialized() {
  ImmutableMapSerializableAutoValue autoValue =
      ImmutableMapSerializableAutoValue.builder()
          .setA(ImmutableMap.of(Optional.of("key"), "value"))
          .setB(ImmutableMap.of("key", Optional.of("value")))
          .build();

  ImmutableMapSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 5
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void immutableMap_emptyMapSerialized() {
  ImmutableMapSerializableAutoValue autoValue =
      ImmutableMapSerializableAutoValue.builder()
          .setA(ImmutableMap.of())
          .setB(ImmutableMap.of())
          .build();

  ImmutableMapSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 6
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void immutableList_allFieldsSetAndSerialized() {
  ImmutableListSerializableAutoValue autoValue =
      ImmutableListSerializableAutoValue.builder()
          .setPayload(ImmutableList.of(Optional.of("a1"), Optional.of("a2")))
          .build();

  ImmutableListSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 7
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void immutableList_emptyListSerialized() {
  ImmutableListSerializableAutoValue autoValue =
      ImmutableListSerializableAutoValue.builder().setPayload(ImmutableList.of()).build();

  ImmutableListSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 8
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void typeParameterizedFieldsAreSerializable_withEmpty() {
  HasTypeParameters<String, Integer> autoValue =
      HasTypeParameters.<String, Integer>builder().setA(A).build();

  HasTypeParameters<String, Integer> actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 9
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void typeParameterizedFieldsAreSerializable_noEmpty() {
  HasTypeParameters<String, Integer> autoValue =
      HasTypeParameters.<String, Integer>builder().setA(A).setOptionalB(B).build();

  HasTypeParameters<String, Integer> actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 10
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void allPrefixFieldsAreSerialized_noEmpty() {
  PrefixSerializableAutoValue autoValue =
      PrefixSerializableAutoValue.builder().a("A").b(true).c("C").d(false).build();

  PrefixSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 11
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void allFieldsAreSerialized_withEmpty() {
  DummySerializableAutoValue autoValue =
      DummySerializableAutoValue.builder().setA(A).setB(B).build();

  DummySerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 12
Source File: SerializableAutoValueExtensionTest.java    From auto with Apache License 2.0 5 votes vote down vote up
@Test
public void allFieldsAreSerialized_noEmpty() {
  DummySerializableAutoValue autoValue =
      DummySerializableAutoValue.builder()
          .setA(A)
          .setB(B)
          .setOptionalC(C)
          .setOptionalD(D)
          .build();

  DummySerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example 13
Source File: AsMapTest.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine,
    population = { Population.SINGLETON, Population.PARTIAL, Population.FULL })
public void writeThroughEntry_serialize(Map<Integer, Integer> map, CacheContext context) {
  Map.Entry<Integer, Integer> entry = map.entrySet().iterator().next();
  Object copy = SerializableTester.reserialize(entry);
  assertThat(entry, is(equalTo(copy)));
}
 
Example 14
Source File: CaffeinatedGuavaTest.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public void testSerializable() {
  SerializableTester.reserialize(CaffeinatedGuava.build(Caffeine.newBuilder()));
  SerializableTester.reserialize(CaffeinatedGuava.build(
      Caffeine.newBuilder(), IdentityLoader.INSTANCE));
  SerializableTester.reserialize(CaffeinatedGuava.build(
      Caffeine.newBuilder(), TestingCacheLoaders.identityLoader()));
}
 
Example 15
Source File: CuckooFilterTest.java    From guava-probably with Apache License 2.0 5 votes vote down vote up
@Test
public void javaSerialization() {
  CuckooFilter<byte[]> cf = CuckooFilter.create(Funnels.byteArrayFunnel(), 100);
  for (int i = 0; i < 10; i++) {
    cf.add(Ints.toByteArray(i));
  }

  CuckooFilter<byte[]> copy = SerializableTester.reserialize(cf);
  for (int i = 0; i < 10; i++) {
    assertTrue(copy.contains(Ints.toByteArray(i)));
  }
  assertEquals(cf.currentFpp(), copy.currentFpp());

  SerializableTester.reserializeAndAssert(cf);
}
 
Example 16
Source File: CuckooFilterTest.java    From guava-probably with Apache License 2.0 5 votes vote down vote up
@Test
public void javaSerialization() {
  CuckooFilter<byte[]> cf = CuckooFilter.create(Funnels.byteArrayFunnel(), 100);
  for (int i = 0; i < 10; i++) {
    cf.add(Ints.toByteArray(i));
  }

  CuckooFilter<byte[]> copy = SerializableTester.reserialize(cf);
  for (int i = 0; i < 10; i++) {
    assertTrue(copy.contains(Ints.toByteArray(i)));
  }
  assertEquals(cf.currentFpp(), copy.currentFpp());

  SerializableTester.reserializeAndAssert(cf);
}
 
Example 17
Source File: ExceptionWrappingBenchmark.java    From mug with Apache License 2.0 5 votes vote down vote up
@Benchmark
void reserializeString(int n) {
  String string = new String("abc");
  for (int i = 0; i < n; i++) {
    SerializableTester.reserialize(string);
  }
}
 
Example 18
Source File: EliminationStackTest.java    From multiway-pool with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "warmedStack")
public void serialize_whenPopulated(EliminationStack<Integer> stack) {
  List<Integer> expected = new ArrayList<>(stack);
  List<Integer> actual = new ArrayList<>(SerializableTester.reserialize(stack));
  assertThat(expected, is(equalTo(actual)));
}
 
Example 19
Source File: EliminationStackTest.java    From multiway-pool with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "emptyStack")
public void serialize_whenEmpty(EliminationStack<Integer> stack) {
  List<Integer> expected = new ArrayList<>(stack);
  List<Integer> actual = new ArrayList<>(SerializableTester.reserialize(stack));
  assertThat(expected, is(equalTo(actual)));
}
 
Example 20
Source File: SingleConsumerQueueTest.java    From caffeine with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "empty,singleton,populated")
public void serializable(Queue<Integer> queue) {
  Queue<Integer> copy = SerializableTester.reserialize(queue);
  assertThat(String.format("%nExpected: %s%n     but: %s", queue, copy),
      elementsEqual(queue.iterator(), copy.iterator()));
}