Package org.apache.avro.generic

Examples of org.apache.avro.generic.GenericRecord


  @Test
  public void testUndeclaredError() throws IOException {
    this.throwUndeclaredError = true;
    RuntimeException error = null;
    GenericRecord params =
      new GenericData.Record(PROTOCOL.getMessages().get("error").getRequest());
    try {
      requestor.request("error", params);
    } catch (RuntimeException e) {
      error = e;
View Full Code Here


    protocol.getMessages().put("hello", message);
    Transceiver t
      = new SocketTransceiver(new InetSocketAddress(server.getPort()));
    try {
      GenericRequestor r = new GenericRequestor(protocol, t);
      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();
    }
View Full Code Here

  protected static class TestResponder extends GenericResponder {
    public TestResponder() { super(PROTOCOL); }
    public Object respond(Message message, Object request)
      throws AvroRemoteException {
      GenericRecord params = (GenericRecord)request;

      if ("hello".equals(message.getName())) {
        LOG.info("hello: "+params.get("greeting"));
        return new Utf8("goodbye");
      }

      if ("echo".equals(message.getName())) {
        Object record = params.get("record");
        LOG.info("echo: "+record);
        return record;
      }

      if ("echoBytes".equals(message.getName())) {
        Object data = params.get("data");
        LOG.info("echoBytes: "+data);
        return data;
      }

      if ("error".equals(message.getName())) {
        if (throwUndeclaredError) throw new RuntimeException("foo");
        GenericRecord error =
          new GenericData.Record(PROTOCOL.getType("TestError"));
        error.put("message", new Utf8("an error"));
        throw new AvroRemoteException(error);
      }
     
      throw new AvroRuntimeException("unexpected message: "+message.getName());
    }
View Full Code Here

    public ConsumerCallbackResult onDataEvent(DbusEvent e, DbusEventDecoder eventDecoder)
    {
       try
       {
         _numDataEvents++;
         GenericRecord r = eventDecoder.getGenericRecord(e, null);
         return ConsumerCallbackResult.SUCCESS;
       }
       catch (Exception ex)
       {
         LOG.error("Error in processing event: " + ex);
View Full Code Here

            // Get the underlying structure from the database. Oracle returns the structure in the
            // second column of the array's ResultSet
            Struct struct = (Struct) arrayResultSet.getObject(2);
            Object[] attributes = struct.getAttributes();

            GenericRecord avroElement = avroArray.get(i++);

            // Iterate over the fields in the JSON array of fields.
            // We can read the structure elements only by position, not by field name, so we
            // have to use dbFieldPosition recorded in the schema definition.
            for (Field field : elementSchema.getFields())
            {
              int dbFieldPosition = Integer.valueOf(SchemaHelper.getMetaField(field, "dbFieldPosition"));
              Object dbFieldValue = attributes[dbFieldPosition];
              Object avroFieldValue = avroElement.get(field.name());
              compareField(field, dbFieldValue, avroFieldValue);
            }
          }
          break;
        case RECORD:
View Full Code Here

  {
    if (_sDebug)
    {
      LOG.debug("Compare Record:");
    }
    GenericRecord record = getGenericRecord(avroFormattedRs, decoder);

    return compareRecord(_schema, expRs, record);
  }
View Full Code Here

  throws SQLException
  {
    _buffer.clear();
    _buffer.put(avroFormattedRs.getBytes("val"));
    _event = _event.reset(_buffer, 0);
    GenericRecord record = decoder.getGenericRecord(_event);
    return record;
  }
View Full Code Here

      while (rs.next())
      {
        buffer.clear();
        buffer.put(rs.getBytes("val"));
        event = event.reset(buffer, 0);
        GenericRecord record = _decoder.getGenericRecord(event);
        _eventHandler.onRecord(event, record);
        count++;
      }
      _eventHandler.onEnd(count);
    }
View Full Code Here

      long timestamp = System.currentTimeMillis();
      long timeStart = timestamp;
      long lastTime = timestamp;
      long commitInterval = _config.getCommitInterval();
      long totLatency = 0;
      GenericRecord record = null;
      RateMonitor seedingRate = new RateMonitor("Seeding Rate");
      seedingRate.start();   
      seedingRate.suspend();
     
      long startRowId = _lastRows.get(sourceInfo.getEventView());
View Full Code Here

          hasMore = true;
          buffer.clear();
          buffer.put(rs.getBytes("val"));
          curId = rs.getLong("id");
          event = event.reset(buffer, 0);
          GenericRecord record = _decoder.getGenericRecord(event);
          if (checkFilters(event, record))
          {
            _eventHandler.onRecord(event, record);
          }
          count++;
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.