forked from twitter/elephant-bird
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up Protobuf generation through object reuse. Thanks to John Sir…
…ois for the tip.
- Loading branch information
Dmitriy Ryaboy
committed
Apr 30, 2010
1 parent
129f3e4
commit b8dae6e
Showing
7 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
package com.twitter.elephantbird.util; | ||
|
||
import com.google.protobuf.Message; | ||
import com.twitter.data.proto.tutorial.AddressBookProtos.Person; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import com.google.common.base.Function; | ||
import com.google.protobuf.Message; | ||
import com.twitter.data.proto.tutorial.AddressBookProtos.AddressBook; | ||
import com.twitter.data.proto.tutorial.AddressBookProtos.Person; | ||
import com.twitter.elephantbird.pig.piggybank.Fixtures; | ||
|
||
public class TestProtobufs { | ||
|
||
private static final AddressBook ab_ = Fixtures.buildAddressBookProto(); | ||
private static final byte[] abBytes_ = ab_.toByteArray(); | ||
|
||
@Test | ||
public void testGetInnerProtobufClass() { | ||
String canonicalClassName = "com.twitter.data.proto.tutorial.AddressBookProtos.Person"; | ||
Class<? extends Message> klass = Protobufs.getInnerProtobufClass(canonicalClassName); | ||
assertEquals(klass, Person.class); | ||
} | ||
|
||
@Test | ||
public void testDynamicParsing() { | ||
assertEquals(ab_, Protobufs.parseDynamicFrom(AddressBook.class, abBytes_)); | ||
} | ||
|
||
@Test | ||
public void testStaticParsing() { | ||
assertEquals(ab_, Protobufs.parseFrom(AddressBook.class, abBytes_)); | ||
} | ||
|
||
@Test | ||
public void testConverterParsing() { | ||
Function<byte[], AddressBook> protoConverter = Protobufs.getProtoConverter(AddressBook.class); | ||
assertEquals(ab_, protoConverter.apply(abBytes_)); | ||
} | ||
} |