Search in sources :

Example 6 with AddressBook

use of com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook in project elephant-bird by twitter.

the class TestTypedProtobufWritable method setUp.

@BeforeClass
public static void setUp() {
    Person p1 = Person.newBuilder().setEmail("email1@example.com").setId(74).setName("Example Person").addPhone(PhoneNumber.newBuilder().setType(PhoneType.MOBILE).setNumber("2930423").build()).addPhone(PhoneNumber.newBuilder().setType(PhoneType.HOME).setNumber("214121").build()).build();
    Person p2 = Person.newBuilder().setEmail("email2@example.com").setId(7334).setName("Another person").addPhone(PhoneNumber.newBuilder().setType(PhoneType.MOBILE).setNumber("030303").build()).build();
    referenceAb = AddressBook.newBuilder().addPerson(p1).addPerson(p2).build();
    referenceAbWritable = new TypedProtobufWritable<AddressBook>(referenceAb);
}
Also used : AddressBook(com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook) Person(com.twitter.data.proto.tutorial.AddressBookProtos.Person) BeforeClass(org.junit.BeforeClass)

Example 7 with AddressBook

use of com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook in project elephant-bird by twitter.

the class TestTypedProtobufWritable method testReadWrite.

@Test
public void testReadWrite() throws IOException {
    DataOutputStream dos = new DataOutputStream(new FileOutputStream("test.txt"));
    referenceAbWritable.write(dos);
    dos.close();
    DataInputStream dis = new DataInputStream(new FileInputStream("test.txt"));
    TypedProtobufWritable<AddressBook> after = new TypedProtobufWritable<AddressBook>();
    after.readFields(dis);
    dis.close();
    AddressBook ab2 = after.get();
    assertEquals(referenceAb, ab2);
    assertEquals(referenceAbWritable.hashCode(), after.hashCode());
}
Also used : AddressBook(com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 8 with AddressBook

use of com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook in project elephant-bird by twitter.

the class TestProtobufWritable method setUp.

@BeforeClass
public static void setUp() {
    Person p1 = Person.newBuilder().setEmail("email1@example.com").setId(74).setName("Example Person").addPhone(PhoneNumber.newBuilder().setType(PhoneType.MOBILE).setNumber("2930423").build()).addPhone(PhoneNumber.newBuilder().setType(PhoneType.HOME).setNumber("214121").build()).build();
    Person p2 = Person.newBuilder().setEmail("email2@example.com").setId(7334).setName("Another person").addPhone(PhoneNumber.newBuilder().setType(PhoneType.MOBILE).setNumber("030303").build()).build();
    referenceAb = AddressBook.newBuilder().addPerson(p1).addPerson(p2).build();
    referenceAbWritable = new ProtobufWritable<AddressBook>(referenceAb, new TypeRef<AddressBook>() {
    });
}
Also used : AddressBook(com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook) TypeRef(com.twitter.elephantbird.util.TypeRef) Person(com.twitter.data.proto.tutorial.AddressBookProtos.Person) BeforeClass(org.junit.BeforeClass)

Example 9 with AddressBook

use of com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook in project elephant-bird by twitter.

the class TestProtobufWritable method testReadWrite.

@Test
public void testReadWrite() throws IOException {
    DataOutputStream dos = new DataOutputStream(new FileOutputStream("test.txt"));
    referenceAbWritable.write(dos);
    dos.close();
    DataInputStream dis = new DataInputStream(new FileInputStream("test.txt"));
    ProtobufWritable<AddressBook> after = new ProtobufWritable<AddressBook>(new TypeRef<AddressBook>() {
    });
    after.readFields(dis);
    dis.close();
    AddressBook ab2 = after.get();
    assertEquals(referenceAb, ab2);
    assertEquals(referenceAbWritable.hashCode(), after.hashCode());
}
Also used : AddressBook(com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) ProtobufWritable(com.twitter.elephantbird.mapreduce.io.ProtobufWritable) Test(org.junit.Test)

Aggregations

AddressBook (com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook)9 Test (org.junit.Test)6 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 Person (com.twitter.data.proto.tutorial.AddressBookProtos.Person)3 Message (com.google.protobuf.Message)2 BeforeClass (org.junit.BeforeClass)2 ProtobufWritable (com.twitter.elephantbird.mapreduce.io.ProtobufWritable)1 ProtobufTuple (com.twitter.elephantbird.pig.util.ProtobufTuple)1 TypeRef (com.twitter.elephantbird.util.TypeRef)1 Path (org.apache.hadoop.fs.Path)1 BytesWritable (org.apache.hadoop.io.BytesWritable)1 DataByteArray (org.apache.pig.data.DataByteArray)1 Tuple (org.apache.pig.data.Tuple)1