Search in sources :

Example 1 with ListDelegate

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()));
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Output(com.esotericsoftware.kryo.io.Output) ListDelegate(org.apache.storm.utils.ListDelegate) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HashMap(java.util.HashMap) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)1 Input (com.esotericsoftware.kryo.io.Input)1 Output (com.esotericsoftware.kryo.io.Output)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ListDelegate (org.apache.storm.utils.ListDelegate)1 Test (org.junit.Test)1