thrift/test/lazy_deserialization/simple_test.cpp
TYPED_TEST(LazyDeserialization, DeserializeLazyStructWithoutIndex) {
  using Struct = typename TypeParam::Struct;
  using LazyStruct = typename TypeParam::LazyStruct;

  Struct foo;
  foo.field1_ref().emplace();
  foo.field2_ref().emplace();
  foo.field3_ref().emplace();
  foo.field4_ref().emplace();

  // We need first deserialization since even though `this->genLazyStruct()`
  // returns lazy struct, all lazy fields are already deserialized.
  LazyStruct lazyFoo;
  this->deserialize(this->serialize(this->genLazyStruct()), lazyFoo);
  this->deserialize(this->serialize(foo), lazyFoo);

  if (std::is_same_v<Struct, TerseFoo>) {
    // If struct enabled terse writes, we won't serialize fields that has
    // default value, thus we won't change lazyFoo after deserialization
    EXPECT_EQ(lazyFoo, this->genLazyStruct());
  } else {
    EXPECT_TRUE(lazyFoo.field1_ref()->empty());
    EXPECT_TRUE(lazyFoo.field2_ref()->empty());
    EXPECT_TRUE(lazyFoo.field3_ref()->empty());
    EXPECT_TRUE(lazyFoo.field4_ref()->empty());
  }
}
// The intention of this unit-test is testing if serialized data doesn't have
// index, we want to ensure it can be still deserialized to struct with lazy
// field with behavior that identical to non-lazy field. i.e. deserialization
// should overwrite fields and clear IOBuf. This can happen during schema
// evolution when user turned off lazy deserialization only on writer side.
The intention of this unit-test is testing if serialized data doesn't have
index, we want to ensure it can be still deserialized to struct with lazy
field with behavior that identical to non-lazy field.
The intention of this unit - test is testing if serialized data doesn ' t have index we want to ensure it can be still deserialized to struct with lazy field with behavior that identical to non - lazy field .
TYPED_TEST(LazyDeserialization, DeserializeLazyStructWithoutIndex) {
  using Struct = typename TypeParam::Struct;
  using LazyStruct = typename TypeParam::LazyStruct;
  Struct foo;
  foo.field1_ref().emplace();
  foo.field2_ref().emplace();
  foo.field3_ref().emplace();
  foo.field4_ref().emplace();
  LazyStruct lazyFoo;
  this->deserialize(this->serialize(this->genLazyStruct()), lazyFoo);
  this->deserialize(this->serialize(foo), lazyFoo);
  if (std::is_same_v<Struct, TerseFoo>) {
    EXPECT_EQ(lazyFoo, this->genLazyStruct());
  } else {
    EXPECT_TRUE(lazyFoo.field1_ref()->empty());
    EXPECT_TRUE(lazyFoo.field2_ref()->empty());
    EXPECT_TRUE(lazyFoo.field3_ref()->empty());
    EXPECT_TRUE(lazyFoo.field4_ref()->empty());
  }
}
TYPED_TEST ( LazyDeserialization , DeserializeLazyStructWithoutIndex ) { using Struct = typename TypeParam :: Struct ; using LazyStruct = typename TypeParam :: LazyStruct ; Struct foo ; foo . field1_ref ( ) . emplace ( ) ; foo . field2_ref ( ) . emplace ( ) ; foo . field3_ref ( ) . emplace ( ) ; foo . field4_ref ( ) . emplace ( ) ; LazyStruct lazyFoo ; this -> deserialize ( this -> serialize ( this -> genLazyStruct ( ) ) , lazyFoo ) ; this -> deserialize ( this -> serialize ( foo ) , lazyFoo ) ; if ( std :: is_same_v < Struct , TerseFoo > ) { EXPECT_EQ ( lazyFoo , this -> genLazyStruct ( ) ) ; } else { EXPECT_TRUE ( lazyFoo . field1_ref ( ) -> empty ( ) ) ; EXPECT_TRUE ( lazyFoo . field2_ref ( ) -> empty ( ) ) ; EXPECT_TRUE ( lazyFoo . field3_ref ( ) -> empty ( ) ) ; EXPECT_TRUE ( lazyFoo . field4_ref ( ) -> empty ( ) ) ; } }
The intention of this unit-test is testing if serialized data doesn't have
index, we want to ensure it can be still deserialized to struct with lazy
field with behavior that identical to non-lazy field.
The intention of this unit - test is testing if serialized data doesn ' t have index we want to ensure it can be still deserialized to struct with lazy field with behavior that identical to non - lazy field .
// We need first deserialization since even though `this->genLazyStruct()` // returns lazy struct, all lazy fields are already deserialized. // If struct enabled terse writes, we won't serialize fields that has // default value, thus we won't change lazyFoo after deserialization