use of org.apache.avro.util.Utf8 in project gora by apache.
the class TestHBaseStore method assertTopLevelUnions.
/**
* Checks that when writing a top level union <code>['null','type']</code>
* the value is written in raw format
* @throws Exception
*/
@Test
public void assertTopLevelUnions() throws Exception {
WebPage page = webPageStore.newPersistent();
// Write webpage data
page.setUrl(new Utf8("http://example.com"));
byte[] contentBytes = "example content in example.com".getBytes(Charset.defaultCharset());
ByteBuffer buff = ByteBuffer.wrap(contentBytes);
page.setContent(buff);
webPageStore.put("com.example/http", page);
webPageStore.flush();
// Read directly from HBase
HTable table = new HTable(conf, "WebPage");
Get get = new Get(Bytes.toBytes("com.example/http"));
org.apache.hadoop.hbase.client.Result result = table.get(get);
byte[] bytesRead = result.getValue(Bytes.toBytes("content"), null);
assertNotNull(bytesRead);
assertTrue(Arrays.equals(bytesRead, contentBytes));
table.close();
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class BSONDecorator method getUtf8String.
/**
* Access field as a Utf8 string.
*
* @param fieldName fully qualified name of the field to be accessed
* @return value of the field as a {@link Utf8} string
*/
public Utf8 getUtf8String(String fieldName) {
BasicDBObject parent = getFieldParent(fieldName);
String value = parent.getString(getLeafName(fieldName));
return (value != null) ? new Utf8(value) : null;
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class TestPersistentSerialization method testSerdeEmployeeTwoFields.
/**
* Creates an Employee object setting only two fields as dirty.
* We then do (de)serialization and check 'before' and 'after'
* states.
* @throws Exception
*/
@Test
public void testSerdeEmployeeTwoFields() throws Exception {
Employee employee = Employee.newBuilder().build();
employee.setSsn(new Utf8("11111"));
employee.setSalary(100);
TestIOUtils.testSerializeDeserialize(employee);
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class TestPersistentSerialization method testSerdeMultipleWebPages.
/**
* Creates multiple WebPage objects setting several fields to dirty.
* Asserts that the data can be serialized and
* deserialzed without loosing data. We do this by asserting
* what we get 'before' and 'after' (de)serialization processes.
* @throws Exception
*/
@Test
public void testSerdeMultipleWebPages() throws Exception {
WebPage page1 = WebPage.newBuilder().build();
WebPage page2 = WebPage.newBuilder().build();
WebPage page3 = WebPage.newBuilder().build();
page1.setUrl(new Utf8("foo"));
page2.setUrl(new Utf8("baz"));
page3.setUrl(new Utf8("bar"));
page1.setParsedContent(new ArrayList<CharSequence>());
page1.getParsedContent().add(new Utf8("coo"));
page2.setOutlinks(new HashMap<CharSequence, CharSequence>());
page2.getOutlinks().put(new Utf8("a"), new Utf8("b"));
TestIOUtils.testSerializeDeserialize(page1, page2, page3);
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class TestPersistentBase method testClear.
/**
* First we create a new WebPage object, to which we add some
* field values. This makes the fields dirty as we have not
* flushed them to the datastore. We then clear the dirty
* fields and assert that the values DO NOT exist for the
* field we previously made dirty.
* We then set new values for fields, consequently making them
* dirty, before testing the clearing of an entirely new object
* has all fields as null as they should be clean.
*/
@Test
public void testClear() {
//test clear all fields
WebPage page = WebPage.newBuilder().build();
page.setUrl(new Utf8("http://foo.com"));
page.getParsedContent().add(new Utf8("foo"));
page.getOutlinks().put(new Utf8("foo"), new Utf8("bar"));
page.setContent(ByteBuffer.wrap("foo baz bar".getBytes(Charset.defaultCharset())));
page.clear();
assertNull(page.getUrl());
assertEquals(0, page.getParsedContent().size());
assertEquals(0, page.getOutlinks().size());
assertNull(page.getContent());
//set fields again
page.setUrl(new Utf8("http://bar.com"));
page.getParsedContent().add(new Utf8("bar"));
page.getOutlinks().put(new Utf8("bar"), new Utf8("baz"));
page.setContent(ByteBuffer.wrap("foo baz bar barbaz".getBytes(Charset.defaultCharset())));
//test clear new object
page = WebPage.newBuilder().build();
page.clear();
}
Aggregations