use of org.apache.avro.util.Utf8 in project gora by apache.
the class DefaultFactoryTest method testCreateFilter_handlingUtf8.
/**
* Check that <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a> is fixed.
* @see <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a>
*/
@Test
public void testCreateFilter_handlingUtf8() throws Exception {
SingleFieldValueFilter<String, WebPage> filter = new SingleFieldValueFilter<>();
filter.setFieldName(WebPage.Field.URL.toString());
filter.setFilterOp(FilterOp.EQUALS);
filter.getOperands().add(new Utf8("http://www.example.com"));
filter.setFilterIfMissing(true);
DBObject dbObject = filterFactory.createFilter(filter, store);
assertEquals("{ \"url\" : \"http://www.example.com\"}", dbObject.toString());
}
use of org.apache.avro.util.Utf8 in project voldemort by voldemort.
the class ClientConfigUtil method readSingleClientConfigAvro.
/**
* Parses a string that contains single fat client config string in avro
* format
*
* @param configAvro Input string of avro format, that contains config for
* multiple stores
* @return Properties of single fat client config
*/
@SuppressWarnings("unchecked")
public static Properties readSingleClientConfigAvro(String configAvro) {
Properties props = new Properties();
try {
JsonDecoder decoder = new JsonDecoder(CLIENT_CONFIG_AVRO_SCHEMA, configAvro);
GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(CLIENT_CONFIG_AVRO_SCHEMA);
Map<Utf8, Utf8> flowMap = (Map<Utf8, Utf8>) datumReader.read(null, decoder);
for (Utf8 key : flowMap.keySet()) {
props.put(key.toString(), flowMap.get(key).toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return props;
}
use of org.apache.avro.util.Utf8 in project voldemort by voldemort.
the class AvroGenericSerializerTest method testSimpleStringSchema.
public void testSimpleStringSchema() throws Exception {
String jsonSchema = "\"string\"";
AvroGenericSerializer serializer = new AvroGenericSerializer(jsonSchema);
byte[] byte1 = serializer.toBytes(new Utf8("abc"));
byte[] byte2 = serializer.toBytes("abc");
assertArrayEquals(" should serialize to same value", byte1, byte2);
}
use of org.apache.avro.util.Utf8 in project voldemort by voldemort.
the class AvroSpecificSerializerTest method testRoundtripAvroWithHandShakeRequest.
// We use a generated class for the exercise.
public void testRoundtripAvroWithHandShakeRequest() {
String className = "java=org.apache.avro.ipc.HandshakeRequest";
HandshakeRequest req = new HandshakeRequest();
// set a few values to avoid NPEs
req.clientHash = new MD5();
req.clientProtocol = new Utf8("");
req.serverHash = new MD5();
AvroSpecificSerializer<HandshakeRequest> serializer = new AvroSpecificSerializer<HandshakeRequest>(className);
byte[] bytes = serializer.toBytes(req);
byte[] bytes2 = serializer.toBytes(req);
assertEquals(ByteUtils.compare(bytes, bytes2), 0);
assertTrue(serializer.toObject(bytes).equals(req));
assertTrue(serializer.toObject(bytes2).equals(req));
}
use of org.apache.avro.util.Utf8 in project voldemort by voldemort.
the class AvroBackwardsCompatibilityTest method writeVersion0with1Present.
private static byte[] writeVersion0with1Present(Map<Integer, String> versions, Schema s0) {
GenericData.Record record = new GenericData.Record(s0);
record.put("original", new Utf8("Abhinay"));
AvroVersionedGenericSerializer serializer = new AvroVersionedGenericSerializer(versions);
return serializer.toBytes(record);
}
Aggregations