Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,30 @@
*/
package org.apache.storm.kafka;

import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Values;
import com.google.common.collect.ImmutableMap;

import java.nio.ByteBuffer;
import java.util.List;

import static org.apache.storm.kafka.StringScheme.deserializeString;
import static org.apache.storm.kafka.bolt.mapper.FieldNameBasedTupleToKafkaMapper.BOLT_KEY;
import static org.apache.storm.kafka.bolt.mapper.FieldNameBasedTupleToKafkaMapper.BOLT_MESSAGE;

public class StringKeyValueScheme extends StringScheme implements KeyValueScheme {

@Override
public List<Object> deserializeKeyAndValue(ByteBuffer key, ByteBuffer value) {
if ( key == null ) {
return deserialize(value);
}
String keyString = StringScheme.deserializeString(key);
String valueString = StringScheme.deserializeString(value);
return new Values(ImmutableMap.of(keyString, valueString));
return new Values(ImmutableMap.of(deserializeString(key), deserializeString(value)));
}

@Override
public Fields getOutputFields() {
return new Fields(BOLT_KEY, BOLT_MESSAGE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
package org.apache.storm.kafka;

import org.apache.storm.tuple.Fields;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Collections;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.apache.storm.kafka.bolt.mapper.FieldNameBasedTupleToKafkaMapper.BOLT_KEY;
import static org.apache.storm.kafka.bolt.mapper.FieldNameBasedTupleToKafkaMapper.BOLT_MESSAGE;

public class StringKeyValueSchemeTest {

Expand All @@ -39,9 +40,7 @@ public void testDeserialize() throws Exception {

@Test
public void testGetOutputFields() throws Exception {
Fields outputFields = scheme.getOutputFields();
assertTrue(outputFields.contains(StringScheme.STRING_SCHEME_KEY));
assertEquals(1, outputFields.size());
assertEquals(asList(BOLT_KEY, BOLT_MESSAGE), scheme.getOutputFields().toList());
}

@Test
Expand Down