use of org.apache.gora.examples.generated.Metadata in project gora by apache.
the class DataStoreTestUtil method assertEqualWebPageObjects.
/**
* Mimics {@link org.apache.gora.store.DataStoreTestUtil#assertEqualEmployeeObjects(Employee, Employee)}
* in that we pick our way through fields within before and after
* {@link org.apache.gora.examples.generated.WebPage} objects comparing field values.
* @param beforeWebPage
* @param afterWebPage
*/
private static void assertEqualWebPageObjects(WebPage beforeWebPage, WebPage afterWebPage) {
//check url field
CharSequence beforeUrl = beforeWebPage.getUrl();
CharSequence afterUrl = afterWebPage.getUrl();
assertEquals(beforeUrl, afterUrl);
//check content field
ByteBuffer beforeContent = beforeWebPage.getContent();
ByteBuffer afterContent = afterWebPage.getContent();
assertEquals(beforeContent, afterContent);
//check parsedContent field
List<CharSequence> beforeParsedContent = beforeWebPage.getParsedContent();
List<CharSequence> afterParsedContent = afterWebPage.getParsedContent();
assertEquals(beforeParsedContent, afterParsedContent);
//check outlinks field
Map<CharSequence, CharSequence> beforeOutlinks = beforeWebPage.getOutlinks();
Map<CharSequence, CharSequence> afterOutlinks = afterWebPage.getOutlinks();
assertEquals(beforeOutlinks, afterOutlinks);
//check metadata field
if (beforeWebPage.get(5) != null) {
Metadata beforeMetadata = beforeWebPage.getMetadata();
Metadata afterMetadata = afterWebPage.getMetadata();
assertEqualMetadataObjects(beforeMetadata, afterMetadata);
}
}
use of org.apache.gora.examples.generated.Metadata in project gora by apache.
the class DataStoreTestUtil method createWebPage.
private static <K> WebPage createWebPage() {
WebPage webpage = WebPage.newBuilder().build();
webpage.setUrl(new Utf8("url.."));
webpage.setContent(ByteBuffer.wrap("test content".getBytes(Charset.defaultCharset())));
webpage.setParsedContent(new ArrayList<CharSequence>());
Metadata metadata = Metadata.newBuilder().build();
webpage.setMetadata(metadata);
return webpage;
}
use of org.apache.gora.examples.generated.Metadata in project gora by apache.
the class TestHBaseByteInterface method testEncodingDecoding.
@Test
public void testEncodingDecoding() throws Exception {
for (int i = 0; i < 1000; i++) {
//employer
CharSequence name = new Utf8("john");
long dateOfBirth = System.currentTimeMillis();
int salary = 1337;
CharSequence ssn = new Utf8(String.valueOf(RANDOM.nextLong()));
Employee e = Employee.newBuilder().build();
e.setName(name);
e.setDateOfBirth(dateOfBirth);
e.setSalary(salary);
e.setSsn(ssn);
byte[] employerBytes = HBaseByteInterface.toBytes(e, Employee.SCHEMA$);
Employee e2 = (Employee) HBaseByteInterface.fromBytes(Employee.SCHEMA$, employerBytes);
assertEquals(name, e2.getName());
assertEquals(dateOfBirth, e2.getDateOfBirth().longValue());
assertEquals(salary, e2.getSalary().intValue());
assertEquals(ssn, e2.getSsn());
//metadata
CharSequence key = new Utf8("theKey");
CharSequence value = new Utf8("theValue " + RANDOM.nextLong());
HashMap<CharSequence, CharSequence> data = new HashMap<>();
data.put(key, value);
Metadata m = Metadata.newBuilder().build();
m.setData(data);
byte[] datumBytes = HBaseByteInterface.toBytes(m, Metadata.SCHEMA$);
Metadata m2 = (Metadata) HBaseByteInterface.fromBytes(Metadata.SCHEMA$, datumBytes);
assertEquals(value, m2.getData().get(key));
}
}
use of org.apache.gora.examples.generated.Metadata in project gora by apache.
the class WebPageDataCreator method createWebPageData.
public static void createWebPageData(DataStore<String, WebPage> dataStore) throws IOException {
try {
WebPage page;
log.info("creating web page data");
for (int i = 0; i < URLS.length; i++) {
page = WebPage.newBuilder().build();
page.setUrl(new Utf8(URLS[i]));
page.setParsedContent(new ArrayList<CharSequence>());
if (CONTENTS[i] != null) {
page.setContent(ByteBuffer.wrap(CONTENTS[i].getBytes(Charset.defaultCharset())));
for (String token : CONTENTS[i].split(" ")) {
page.getParsedContent().add(new Utf8(token));
}
}
for (int j = 0; j < LINKS[i].length; j++) {
page.getOutlinks().put(new Utf8(URLS[LINKS[i][j]]), new Utf8(ANCHORS[i][j]));
}
Metadata metadata = Metadata.newBuilder().build();
metadata.setVersion(1);
metadata.getData().put(new Utf8("metakey"), new Utf8("metavalue"));
page.setMetadata(metadata);
dataStore.put(URLS[i], page);
}
dataStore.flush();
log.info("finished creating web page data");
} catch (Exception e) {
log.info("error creating web page data");
}
}
use of org.apache.gora.examples.generated.Metadata in project gora by apache.
the class DataStoreTestUtil method testPutNested.
public static void testPutNested(DataStore<String, WebPage> store) throws Exception {
String revUrl = "foo.com:http/";
String url = "http://foo.com/";
store.createSchema();
WebPage page = WebPage.newBuilder().build();
Metadata metadata = Metadata.newBuilder().build();
metadata.setVersion(1);
metadata.getData().put(new Utf8("foo"), new Utf8("baz"));
page.setMetadata(metadata);
page.setUrl(new Utf8(url));
store.put(revUrl, page);
store.flush();
page = store.get(revUrl);
metadata = page.getMetadata();
assertNotNull(metadata);
assertEquals(1, metadata.getVersion().intValue());
assertEquals(new Utf8("baz"), metadata.getData().get(new Utf8("foo")));
}
Aggregations