use of org.apache.storm.utils.ListDelegate in project storm by apache.
the class BlowfishTupleSerializerTest method testEncryptsAndDecryptsMessage.
/**
* Reads a string encrypted by another instance with a shared key
*/
@Test
public void testEncryptsAndDecryptsMessage() {
String testText = "Tetraodontidae is a family of primarily marine and estuarine fish of the order" + " Tetraodontiformes. The family includes many familiar species, which are" + " variously called pufferfish, puffers, balloonfish, blowfish, bubblefish," + " globefish, swellfish, toadfish, toadies, honey toads, sugar toads, and sea" + " squab.[1] They are morphologically similar to the closely related" + " porcupinefish, which have large external spines (unlike the thinner, hidden" + " spines of Tetraodontidae, which are only visible when the fish has puffed up)." + " The scientific name refers to the four large teeth, fused into an upper and" + " lower plate, which are used for crushing the shells of crustaceans and" + " mollusks, their natural prey.";
Kryo kryo = new Kryo();
String arbitraryKey = "7dd6fb3203878381b08f9c89d25ed105";
Map stormConf = ImmutableMap.of(BlowfishTupleSerializer.SECRET_KEY, arbitraryKey);
BlowfishTupleSerializer writerBTS = new BlowfishTupleSerializer(kryo, stormConf);
BlowfishTupleSerializer readerBTS = new BlowfishTupleSerializer(kryo, stormConf);
int bufferSize = 1024;
Output output = new Output(bufferSize, bufferSize);
Input input = new Input(bufferSize);
String[] stringList = testText.split(" ");
ListDelegate delegate = new ListDelegate();
delegate.addAll(Arrays.asList(stringList));
writerBTS.write(kryo, output, delegate);
input.setBuffer(output.getBuffer());
ListDelegate outDelegate = readerBTS.read(kryo, input, ListDelegate.class);
Assert.assertEquals(testText, Joiner.on(" ").join(outDelegate.toArray()));
}
Aggregations