Search in sources :

Example 1 with Address

use of org.infinispan.protostream.domain.Address in project protostream by infinispan.

the class AnnotationsPerformanceTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    SerializationContext ctx1 = createCtxWithHandWrittenMarshaller();
    SerializationContext ctx2 = createCtxWithGeneratedMarshaller();
    User user = new User();
    user.setId(1);
    user.setName("John");
    user.setSurname("Batman");
    user.setSalutation("Sir");
    user.setGender(User.Gender.MALE);
    user.setAccountIds(new HashSet<>(Arrays.asList(1, 3)));
    List<Address> addresses = new ArrayList<>();
    addresses.add(new Address("Old Street", "XYZ42", -12));
    addresses.add(new Address("Bond Street", "QQ42", 312));
    user.setAddresses(addresses);
    Note note = new Note();
    note.setText("Lorem Ipsum");
    note.setCreationDate(new Date());
    note.setDigest(new byte[10]);
    note.setBlurb(new byte[3]);
    note.setAuthor(user);
    Note note2 = new Note();
    note2.setText("Lorem Ipsum");
    note2.setAuthor(user);
    note2.setBlurb(new byte[3]);
    Note note3 = new Note();
    note3.setText("Lorem Ipsum");
    note3.setAuthor(user);
    note3.setBlurb(new byte[3]);
    note.note = note2;
    note.notes = Collections.singletonList(note3);
    byte[] bytes = writeWithProtoStream(ctx1, note);
    writeWithProtoStream(ctx2, note);
    long d1 = readWithProtoStream(ctx1, bytes);
    log.infof("ProtoStream read duration           = %d ns", d1);
    long d2 = readWithProtoStream(ctx2, bytes);
    log.infof("ProtoStream read duration           = %d ns", d2);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) User(org.infinispan.protostream.domain.User) Address(org.infinispan.protostream.domain.Address) Note(org.infinispan.protostream.domain.Note) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 2 with Address

use of org.infinispan.protostream.domain.Address in project protostream by infinispan.

the class PerformanceTest method createTestObject.

private User createTestObject() {
    User user = new User();
    user.setId(1);
    user.setName("John");
    user.setSurname("Batman");
    user.setGender(User.Gender.MALE);
    user.setAccountIds(new HashSet<>(Arrays.asList(1, 3)));
    List<Address> addresses = new ArrayList<>();
    addresses.add(new Address("Old Street", "XYZ42", -12));
    addresses.add(new Address("Bond Street", "QQ42", 312));
    user.setAddresses(addresses);
    return user;
}
Also used : User(org.infinispan.protostream.domain.User) Address(org.infinispan.protostream.domain.Address) ArrayList(java.util.ArrayList)

Example 3 with Address

use of org.infinispan.protostream.domain.Address in project protostream by infinispan.

the class WrappingTest method createUser.

private User createUser(int id, String name, String surname) {
    User user = new User();
    user.setId(id);
    user.setName(name);
    user.setSurname(surname);
    user.setGender(User.Gender.MALE);
    user.setAccountIds(new HashSet<>(Arrays.asList(1, 3)));
    user.setAddresses(Collections.singletonList(new Address("Old Street", "XYZ42", -12)));
    return user;
}
Also used : User(org.infinispan.protostream.domain.User) Address(org.infinispan.protostream.domain.Address)

Example 4 with Address

use of org.infinispan.protostream.domain.Address in project protostream by infinispan.

the class UnknownFieldSetImplTest method createMarshalledObject.

private byte[] createMarshalledObject() throws IOException {
    ImmutableSerializationContext ctx = createContext();
    User user = new User();
    user.setId(1);
    user.setName("John");
    user.setSurname("Batman");
    user.setGender(User.Gender.MALE);
    user.setAccountIds(new HashSet<>(Arrays.asList(1, 3)));
    user.setAddresses(Collections.singletonList(new Address("Old Street", "XYZ42", -12)));
    return ProtobufUtil.toByteArray(ctx, user);
}
Also used : User(org.infinispan.protostream.domain.User) Address(org.infinispan.protostream.domain.Address) ImmutableSerializationContext(org.infinispan.protostream.ImmutableSerializationContext)

Example 5 with Address

use of org.infinispan.protostream.domain.Address in project protostream by infinispan.

the class ProtoSchemaBuilderTest method testAdapter.

@Test
public void testAdapter() throws Exception {
    SerializationContext ctx = createContext();
    String schema = new ProtoSchemaBuilder().fileName("address.proto").addClass(UUIDAdapter.class).addClass(AddressAdapter.class).addClass(AddressAdapter.AddressAdapter2.class).build(ctx);
    assertTrue(schema.contains("message Address"));
    assertTrue(schema.contains("message UUID"));
    Address address = new Address("str", "po", 77, true);
    byte[] addressBytes = ProtobufUtil.toWrappedByteArray(ctx, address);
    Address addressOut = ProtobufUtil.fromWrappedByteArray(ctx, addressBytes);
    assertNotNull(addressOut);
    assertEquals("str", addressOut.getStreet());
    assertEquals("po", addressOut.getPostCode());
    assertEquals(77, addressOut.getNumber());
    UUID uuid = new UUID(33, 55);
    byte[] uuidBytes = ProtobufUtil.toWrappedByteArray(ctx, uuid);
    UUID uuidOut = ProtobufUtil.fromWrappedByteArray(ctx, uuidBytes);
    assertNotNull(uuidOut);
    assertEquals(33, uuidOut.getMostSignificantBits());
    assertEquals(55, uuidOut.getLeastSignificantBits());
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) ProtoSchemaBuilder(org.infinispan.protostream.annotations.ProtoSchemaBuilder) Address(org.infinispan.protostream.domain.Address) UUID(java.util.UUID) UUIDAdapter(org.infinispan.protostream.annotations.impl.testdomain.UUIDAdapter) Test(org.junit.Test) AbstractProtoStreamTest(org.infinispan.protostream.test.AbstractProtoStreamTest)

Aggregations

Address (org.infinispan.protostream.domain.Address)14 User (org.infinispan.protostream.domain.User)12 Test (org.junit.Test)8 AbstractProtoStreamTest (org.infinispan.protostream.test.AbstractProtoStreamTest)7 ArrayList (java.util.ArrayList)2 SerializationContext (org.infinispan.protostream.SerializationContext)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 Date (java.util.Date)1 UUID (java.util.UUID)1 ImmutableSerializationContext (org.infinispan.protostream.ImmutableSerializationContext)1 ProtoSchemaBuilder (org.infinispan.protostream.annotations.ProtoSchemaBuilder)1 UUIDAdapter (org.infinispan.protostream.annotations.impl.testdomain.UUIDAdapter)1 Descriptor (org.infinispan.protostream.descriptors.Descriptor)1 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)1 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)1 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)1 Account (org.infinispan.protostream.domain.Account)1 Note (org.infinispan.protostream.domain.Note)1