Esempio n. 1
0
  @Test
  public void testSaveJsonFormat() throws AvroBaseException, IOException {
    AvroBase<User, byte[]> userHAB =
        AvroBaseFactory.createAvroBase(new HABModule(), HAB.class, AvroFormat.JSON);
    User saved = new User();
    saved.firstName = $("Sam");
    saved.lastName = $("Pullara");
    saved.birthday = $("1212");
    saved.gender = GenderType.MALE;
    saved.email = $("*****@*****.**");
    saved.description = $("CTO of RightTime, Inc. and one of the founders of BagCheck");
    saved.title = $("Engineer");
    saved.image = $("http://farm1.static.flickr.com/1/buddyicons/[email protected]");
    saved.location = $("Los Altos, CA");
    saved.mobile = $("4155551212");
    saved.password = ByteBuffer.wrap($("").getBytes());
    byte[] row = Bytes.toBytes("spullara");
    userHAB.put(row, saved);
    Row<User, byte[]> loaded = userHAB.get(row);
    assertEquals(saved, loaded.value);

    HTablePool pool = new HTablePool();
    HTableInterface table = pool.getTable(TABLE);
    try {
      Get get = new Get(row);
      byte[] DATA = Bytes.toBytes("d");
      get.addColumn(COLUMN_FAMILY, DATA);
      Result result = table.get(get);
      assertTrue(Bytes.toString(result.getValue(COLUMN_FAMILY, DATA)).startsWith("{"));
    } finally {
      pool.putTable(table);
    }
  }
Esempio n. 2
0
 @Test
 public void testSaveFail() throws AvroBaseException {
   AvroBase<User, byte[]> userHAB =
       AvroBaseFactory.createAvroBase(new HABModule(), HAB.class, AvroFormat.BINARY);
   User saved = new User();
   saved.firstName = $("Sam");
   saved.lastName = $("Pullara");
   saved.birthday = $("1212");
   saved.gender = GenderType.MALE;
   saved.email = $("*****@*****.**");
   saved.description = $("CTO of RightTime, Inc. and one of the founders of BagCheck");
   saved.title = $("Engineer");
   saved.image = $("http://farm1.static.flickr.com/1/buddyicons/[email protected]");
   saved.location = $("Los Altos, CA");
   saved.password = ByteBuffer.wrap($("").getBytes());
   byte[] row = Bytes.toBytes("spullara");
   assertFalse(userHAB.put(row, saved, -1));
 }
Esempio n. 3
0
 @Test
 public void testCreateSequential() throws AvroBaseException {
   deleteTable(SCHEMA_TABLE);
   AvroBase<User, byte[]> userHAB =
       AvroBaseFactory.createAvroBase(new HABModule(), HAB.class, AvroFormat.BINARY);
   User saved = new User();
   saved.firstName = $("Sam");
   saved.lastName = $("Pullara");
   saved.birthday = $("1212");
   saved.gender = GenderType.MALE;
   saved.email = $("*****@*****.**");
   saved.description = $("CTO of RightTime, Inc. and one of the founders of BagCheck");
   saved.title = $("Engineer");
   saved.image = $("http://farm1.static.flickr.com/1/buddyicons/[email protected]");
   saved.location = $("Los Altos, CA");
   saved.password = ByteBuffer.wrap($("").getBytes());
   byte[] row = userHAB.create(saved);
   Row<User, byte[]> loaded = userHAB.get(row);
   assertEquals(saved, loaded.value);
   assertEquals("1", Bytes.toString(row));
 }
Esempio n. 4
0
 @Test
 public void testBenchmark() throws AvroBaseException, InterruptedException {
   deleteTable(TABLE);
   final AvroBase<User, byte[]> instance =
       AvroBaseFactory.createAvroBase(new HABModule(), HAB.class, AvroFormat.BINARY);
   final User saved = new User();
   saved.firstName = $("Sam");
   saved.lastName = $("Pullara");
   saved.birthday = $("1212");
   saved.gender = GenderType.MALE;
   saved.email = $("*****@*****.**");
   saved.description = $("CTO of RightTime, Inc. and one of the founders of BagCheck");
   saved.title = $("Engineer");
   saved.image = $("http://farm1.static.flickr.com/1/buddyicons/[email protected]");
   saved.location = $("Los Altos, CA");
   saved.password = ByteBuffer.wrap($("").getBytes());
   long start = System.currentTimeMillis();
   final Semaphore s = new Semaphore(10);
   ExecutorService es = Executors.newCachedThreadPool();
   for (int i = 0; i < INSERTS; i++) {
     s.acquire();
     es.submit(
         new Runnable() {
           public void run() {
             try {
               instance.create(saved);
             } finally {
               s.release();
             }
           }
         });
   }
   s.acquire(10);
   s.release(10);
   long end = System.currentTimeMillis();
   System.out.println(INSERTS * 1000 / (end - start));
   deleteTable(TABLE);
 }