Package org.apache.avro.util

Examples of org.apache.avro.util.Utf8


    newDecoderWithNoData().readBytes(null);
  }
 
  @Test(expected=EOFException.class)
  public void testEOFString() throws IOException {
    newDecoderWithNoData().readString(new Utf8("a"));
  }
View Full Code Here


        break;
      case 'S':
        {
          extractInt(cs);
          String s = (String) values[p++];
          vw.writeString(new Utf8(s));
          break;
        }
      case 'K':
      {
        extractInt(cs);
View Full Code Here

        if (level == skipLevel) {
          vi.skipString();
          p++;
        } else {
          String s = (String) values[p++];
          assertEquals(new Utf8(s), vi.readString(null));
        }
        break;
      case 'K':
        extractInt(cs);
        if (level == skipLevel) {
          vi.skipString();
          p++;
        } else {
          String s = (String) values[p++];
          assertEquals(new Utf8(s), vi.readString(null));
        }
        break;
      case 'b':
        extractInt(cs);
        if (level == skipLevel) {
View Full Code Here

    default: throw new RuntimeException("Unknown type: "+schema);
    }
  }

  private static Utf8 randomUtf8(Random rand, int maxLength) {
    Utf8 utf8 = new Utf8().setLength(rand.nextInt(maxLength));
    for (int i = 0; i < utf8.getLength(); i++) {
      utf8.getBytes()[i] = (byte)('a'+rand.nextInt('z'-'a'));
    }
    return utf8;
  }
View Full Code Here

    @Test
    public void testZeroInjection() throws IOException
    {
        org.apache.cassandra.avro.CfDef cd = new org.apache.cassandra.avro.CfDef();
        // populate only fields that must be non-null.
        cd.keyspace = new Utf8("Lest Ks");
        cd.name = new Utf8("Mest Cf");
       
        org.apache.cassandra.avro.CfDef cd2 = SerDeUtils.deserializeWithSchema(SerDeUtils.serializeWithSchema(cd), new org.apache.cassandra.avro.CfDef());
        assert cd.equals(cd2);
        // make sure some of the fields didn't get unexpected zeros put in during [de]serialize operations.
        assert cd.min_compaction_threshold == null;
View Full Code Here

  @Test
  public void testHello() throws IOException {
    GenericRecord params =
      new GenericData.Record(PROTOCOL.getMessages().get("hello").getRequest());
    params.put("greeting", new Utf8("bob"));
    Utf8 response = (Utf8)requestor.request("hello", params);
    assertEquals(new Utf8("goodbye"), response);
  }
View Full Code Here

  @Test
  public void testEcho() throws IOException {
    GenericRecord record =
      new GenericData.Record(PROTOCOL.getType("TestRecord"));
    record.put("name", new Utf8("foo"));
    record.put("kind", new GenericData.EnumSymbol("BAR"));
    record.put("hash", new GenericData.Fixed
               (new byte[]{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}));
    GenericRecord params =
      new GenericData.Record(PROTOCOL.getMessages().get("echo").getRequest());
View Full Code Here

      = 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

      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

      LOG.warn("system error", e);
      context.setError(e);
      bbo = new ByteBufferOutputStream();
      out = EncoderFactory.get().binaryEncoder(bbo, null);
      out.writeBoolean(true);
      writeError(Protocol.SYSTEM_ERRORS, new Utf8(e.toString()), out);
      if (null == handshake) {
        handshake = new ByteBufferOutputStream().getBufferList();
      }
    }
    out.flush();
View Full Code Here

TOP

Related Classes of org.apache.avro.util.Utf8

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.