Search in sources :

Example 51 with Utf8

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());
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) SingleFieldValueFilter(org.apache.gora.filter.SingleFieldValueFilter) Utf8(org.apache.avro.util.Utf8) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 52 with Utf8

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;
}
Also used : JsonDecoder(org.apache.avro.io.JsonDecoder) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) Utf8(org.apache.avro.util.Utf8) Properties(java.util.Properties) Map(java.util.Map)

Example 53 with Utf8

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);
}
Also used : Utf8(org.apache.avro.util.Utf8)

Example 54 with Utf8

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));
}
Also used : Utf8(org.apache.avro.util.Utf8) HandshakeRequest(org.apache.avro.ipc.HandshakeRequest) MD5(org.apache.avro.ipc.MD5)

Example 55 with Utf8

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);
}
Also used : Record(org.apache.avro.generic.GenericData.Record) Utf8(org.apache.avro.util.Utf8) Record(org.apache.avro.generic.GenericData.Record) GenericData(org.apache.avro.generic.GenericData)

Aggregations

Utf8 (org.apache.avro.util.Utf8)123 Test (org.junit.Test)34 WebPage (org.apache.gora.examples.generated.WebPage)32 GenericRecord (org.apache.avro.generic.GenericRecord)17 Schema (org.apache.avro.Schema)14 GenericData (org.apache.avro.generic.GenericData)13 ByteBuffer (java.nio.ByteBuffer)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 Employee (org.apache.gora.examples.generated.Employee)11 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Field (org.apache.avro.Schema.Field)6 Record (org.apache.avro.generic.GenericData.Record)5 File (java.io.File)4 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)4 Metadata (org.apache.gora.examples.generated.Metadata)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Iterator (java.util.Iterator)3 List (java.util.List)3