Permalink
Browse files

Merge remote-tracking branch 'd2r/derekd-blowfishtupleserializer-test'

  • Loading branch information...
2 parents 6398179 + 7970fee commit 9fbf64adf182f2e889c44a1888e5120e821d9196 @nathanmarz committed Mar 3, 2013
@@ -26,7 +26,7 @@
* You should use in via "storm -c topology.tuple.serializer.blowfish.key=YOURKEY -c topology.tuple.serializer=backtype.storm.security.serialization.BlowfishTupleSerializer jar ...".
*/
public static String SECRET_KEY = "topology.tuple.serializer.blowfish.key";
- private static final Logger LOG = Logger.getLogger(BlowfishSerializer.class);
+ private static final Logger LOG = Logger.getLogger(BlowfishTupleSerializer.class);
private BlowfishSerializer _serializer;
public BlowfishTupleSerializer(Kryo kryo, Map storm_conf) {
@@ -35,25 +35,23 @@ public BlowfishTupleSerializer(Kryo kryo, Map storm_conf) {
encryption_key = (String)storm_conf.get(SECRET_KEY);
LOG.debug("Blowfish serializer being constructed ...");
if (encryption_key == null) {
- LOG.error("Encryption key not specified");
throw new RuntimeException("Blowfish encryption key not specified");
}
byte[] bytes = Hex.decodeHex(encryption_key.toCharArray());
_serializer = new BlowfishSerializer(new ListDelegateSerializer(), bytes);
} catch (org.apache.commons.codec.DecoderException ex) {
- LOG.error("Invalid encryption key", ex);
throw new RuntimeException("Blowfish encryption key invalid", ex);
}
}
@Override
public void write(Kryo kryo, Output output, ListDelegate object) {
- _serializer.write(kryo, output, object);
+ _serializer.write(kryo, output, object);
}
@Override
public ListDelegate read(Kryo kryo, Input input, Class<ListDelegate> type) {
- return (ListDelegate)_serializer.read(kryo, input, type);
+ return (ListDelegate)_serializer.read(kryo, input, type);
}
/**
@@ -15,8 +15,15 @@
"Throws RuntimeException when no encryption key is given.")
)
-(deftest test-encrypts-and-decrypts-message
+(deftest test-constructor-throws-on-invalid-key
+ ; The encryption key must be hexadecimal.
+ (let [conf {BlowfishTupleSerializer/SECRET_KEY "0123456789abcdefg"}]
+ (is (thrown? RuntimeException (new BlowfishTupleSerializer nil conf))
+ "Throws RuntimeException when an invalid encryption key is given.")
+ )
+)
+(deftest test-encrypts-and-decrypts-message
(let [
test-text (str
"Tetraodontidae is a family of primarily marine and estuarine fish of the order"
@@ -32,7 +39,7 @@
)
kryo (new Kryo)
arbitrary-key "7dd6fb3203878381b08f9c89d25ed105"
- storm_conf {"topology.tuple.serializer.blowfish.key" arbitrary-key}
+ storm_conf {BlowfishTupleSerializer/SECRET_KEY arbitrary-key}
writer-bts (new BlowfishTupleSerializer kryo storm_conf)
reader-bts (new BlowfishTupleSerializer kryo storm_conf)
buf-size 1024

0 comments on commit 9fbf64a

Please sign in to comment.