Package org.apache.avro.generic

Examples of org.apache.avro.generic.GenericRecord


   * @return
   */
  private GenericRecord generateAvroRecord(HashMap<String,ColumnState.EventField> eventFields, ReplicationBitSetterStaticConfig replicationBitConfig, Pattern replicationValuePattern)
      throws Exception
  {
    GenericRecord record = new GenericData.Record(getCurrentSchema());
    List<Schema.Field> fields = getCurrentSchema().getFields();
    String pkFieldName = SchemaHelper.getMetaField(getCurrentSchema(), "pk");
    if(pkFieldName == null)
      throw new DatabusException("No primary key specified in the schema");
    PrimaryKey pk = new PrimaryKey(pkFieldName);
View Full Code Here


      throws DatabusException, XMLStreamException
  {
    _currentStateType = STATETYPE.ENDELEMENT;

    //TODO construct a data structure that will hold key, csn and the avro
    GenericRecord record = stateMachine.columnsState.getGenericRecord();
    long scn = stateMachine.tokensState.getScn();

    if(_scn < scn)
    {
      _scn = scn;
View Full Code Here

    Random rng = new Random();
    DbusEventInfo[] result = new DbusEventInfo[eventsNum];
    GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(SOURCE1_SCHEMA);
    for (int i = 0; i < eventsNum; ++i)
    {
      GenericRecord r = new GenericData.Record(SOURCE1_SCHEMA);
      String s = RngUtils.randomString(rng.nextInt(100));
      r.put("s", s);
      ByteArrayOutputStream baos = new ByteArrayOutputStream(s.length() + 100);
      BinaryEncoder out = new BinaryEncoder(baos);
      try
      {
        writer.write(r, out);
View Full Code Here

    // now create the decoder and use it to extract and decode the event's metadata
    DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
    try
    {
      GenericRecord reuse = null;
      GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
      Assert.assertNotNull(decodedMetadata, "getMetadata() returned null GenericRecord;");

      Utf8 etag = (Utf8)decodedMetadata.get("etag");
      Assert.assertEquals(etag.toString(), "dunno what an etag is");

      Integer flags = (Integer)decodedMetadata.get("flags");
      Assert.assertEquals(flags, null, "expected flags to be null");

      Long expires = (Long)decodedMetadata.get("expires");
      Assert.assertNotNull(expires, "expected expires to have a value;");
      Assert.assertEquals(expires.longValue(), 1366150681);

      Utf8 nonexistentField = (Utf8)decodedMetadata.get("nonexistentField");
      Assert.assertNull(nonexistentField, "unexpected value for 'nonexistentField';");
    }
    catch (Exception ex)
    {
      Assert.fail("unexpected error decoding metadata: " + ex);
View Full Code Here

    // now create the decoder and attempt to use it to extract and decode the event's metadata
    DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
    try
    {
      GenericRecord reuse = null;
      GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
      Assert.fail("getMetadata() should have thrown exception");
    }
    catch (Exception ex)
    {
      // expected case:  event had metadata, but schema to decode it was missing
View Full Code Here

    // now create the decoder and attempt to use it to extract and decode the event's metadata
    DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
    try
    {
      GenericRecord reuse = null;
      GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
      Assert.assertNull(decodedMetadata, "getMetadata() should have returned null;");
    }
    catch (Exception ex)
    {
      Assert.fail("getMetadata() should not have thrown exception: " + ex);
View Full Code Here

    // now create the decoder and attempt to use it to extract and decode the event's metadata
    DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
    try
    {
      GenericRecord reuse = null;
      GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
      Assert.assertNull(decodedMetadata, "getMetadata() should have returned null;");
    }
    catch (Exception ex)
    {
      Assert.fail("getMetadata() should not have thrown exception: " + ex);
View Full Code Here

    protocol.getMessages().put("hello", message);
    Transceiver t = createTransceiver();
    try {
      GenericRequestor r = new GenericRequestor(protocol, t);
      addRpcPlugins(r);
      GenericRecord params = new GenericData.Record(message.getRequest());
      params.put("extra", Boolean.TRUE);
      params.put("greeting", new Utf8("bob"));
      Utf8 response = (Utf8)r.request("hello", params);
      assertEquals(new Utf8("goodbye"), response);
    } finally {
      t.close();
      server.close();
View Full Code Here

      }
    }

    Decoder decoder = DecoderFactory.get().binaryDecoder( inputStream, null );
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>( protocol.getType( "Message" ) );
    GenericRecord result;
    try {
      result = reader.read( null, decoder );
    }
    catch (IOException e) {
      throw log.unableToDeserializeAvroStream( e );
View Full Code Here

  private List<Utf8> asListOfString(GenericRecord result, String attribute) {
    return (List<Utf8>) result.get( attribute );
  }

  private void processId(GenericRecord operation, LuceneWorksBuilder hydrator) {
    GenericRecord id = (GenericRecord) operation.get( "id" );
    Object value = id.get( "value" );
    if ( value instanceof ByteBuffer ) {
      hydrator.addIdAsJavaSerialized( asByteArray( (ByteBuffer) value ) );
    }
    else if ( value instanceof Utf8 ) {
      hydrator.addId( value.toString() );
View Full Code Here

TOP

Related Classes of org.apache.avro.generic.GenericRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.